Mercurial > pub > Impl
diff Lib/IMPL/SQL/Schema/Traits.pm @ 44:32d2350fccf9
ORM
*Minor fixes
*Working tarnsform to sql
*Fixes to the sql traits
author | Sergey |
---|---|
date | Mon, 11 Jan 2010 01:42:00 +0300 |
parents | 56cef8e3cda6 |
children | 16ada169ca75 |
line wrap: on
line diff
--- a/Lib/IMPL/SQL/Schema/Traits.pm Thu Jan 07 15:41:49 2010 +0300 +++ b/Lib/IMPL/SQL/Schema/Traits.pm Mon Jan 11 01:42:00 2010 +0300 @@ -13,8 +13,8 @@ } ; BEGIN { - public _direct property SrcSchema => prop_none; - public _direct property DstSchema => prop_none; + public _direct property SrcSchema => prop_all; + public _direct property DstSchema => prop_all; public _direct property PendingActions => prop_get; public _direct property TableInfo => prop_get; public _direct property Handler => prop_get; @@ -51,7 +51,7 @@ return 1; } - if ( not grep {$srcTable->Column($_->Name)} $dstTable->Columns ) { + if ( not grep {$srcTable->Column($_->Name)} @{$dstTable->Columns} ) { $this->{$TableInfo}->{$srcTable->Name}->{'NewName'} = $dstTable->Name if $srcTable->Name ne $dstTable->Name; @@ -76,14 +76,14 @@ } my $i = 0; - my %dstColumns = map { $_->Name, $i++} $dstTable->Columns ; + my %dstColumns = map { $_->Name, $i++} @{$dstTable->Columns} ; # сначала удаляем столбцы # потом добавляем недостающие и изменяем столбцы в нужном порядке my @columnsToUpdate; - foreach my $srcColumn ($srcTable->Columns) { + foreach my $srcColumn (@{$srcTable->Columns}) { if (defined (my $dstColumnIndex = delete $dstColumns{$srcColumn->Name})) { push @columnsToUpdate, { Action => 'update', ColumnSrc => $srcColumn, ColumnDst => $dstTable->ColumnAt($dstColumnIndex), NewPosition => $dstColumnIndex}; } else { @@ -126,8 +126,8 @@ ref $src eq ref $dst or return 0; - my @dstColumns = $dst->Columns; - scalar(@{$src->Columns}) == scalar(@{$dst->Columns}) and not grep { my $column = shift @dstColumns; not $column->isSame($_) } $src->Columns or return 0; + my @dstColumns = @{$dst->Columns}; + scalar(@{$src->Columns}) == scalar(@{$dst->Columns}) and not grep { my $column = shift @dstColumns; not $column->isSame($_) } @{$src->Columns} or return 0; not UNIVERSAL::isa($src,'IMPL::SQL::Schema::Constraint::ForeignKey') or ConstraintEquals($src->ReferencedPrimaryKey,$dst->ReferencedPrimaryKey) or return 0; @@ -167,7 +167,7 @@ $this->{$Handler}->DropTable($this->MapTableName($tbl->Name)); $this->{$TableInfo}{$this->MapTableName($tbl->Name)}{'State'} = STATE_REMOVED; $this->{$TableInfo}{$this->MapTableName($tbl->Name)}{'Constraints'} = {map {$_,STATE_REMOVED} keys %{$tbl->Constraints}}; - $this->{$TableInfo}{$this->MapTableName($tbl->Name)}{'Columns'} = {map { $_->Name, STATE_REMOVED} $tbl->Columns}; + $this->{$TableInfo}{$this->MapTableName($tbl->Name)}{'Columns'} = {map { $_->Name, STATE_REMOVED} @{$tbl->Columns}}; return 1; } @@ -180,7 +180,7 @@ $this->{$TableInfo}->{$tbl->Name}->{'State'} = STATE_CREATED; - $this->{$TableInfo}->{$tbl->Name}->{'Columns'} = {map { $_->Name, STATE_CREATED } $tbl->Columns}; + $this->{$TableInfo}->{$tbl->Name}->{'Columns'} = {map { $_->Name, STATE_CREATED } @{$tbl->Columns}}; $this->{$TableInfo}->{$tbl->Name}->{'Constraints'} = {map {$_->Name, STATE_CREATED} grep { not UNIVERSAL::isa($_,'IMPL::SQL::Schema::Constraint::ForeignKey') } values %{$tbl->Constraints}}; $this->AddConstraint($_) foreach grep { UNIVERSAL::isa($_,'IMPL::SQL::Schema::Constraint::ForeignKey') } values %{$tbl->Constraints}; @@ -242,7 +242,12 @@ my $pending; - $pending = grep { my $column = $_; not grep { IfUndef($this->{$TableInfo}{$constraint->Table->Name}{'Columns'}{$column->Name}, STATE_NORMAL) == $_ } (STATE_UPDATED, STATE_CREATED) } $constraint->Columns; + $pending = grep { + my $column = $_; + not grep { + IfUndef($this->{$TableInfo}{$constraint->Table->Name}{'Columns'}{$column->Name}, STATE_NORMAL) == $_ + } (STATE_UPDATED, STATE_CREATED) + } @{$constraint->Columns}; if ($pending) { push @{$this->{$PendingActions}},{Action => \&AddConstraint, Args => [$constraint]};