changeset 169:fd92830036c3

corrected IMPL::SQL::Schema::Diff
author sourcer
date Tue, 17 May 2011 00:04:28 +0400
parents 6148f89bb7bf
children b88b7fe60aa3
files Lib/IMPL/SQL/Schema/Traits.pm Lib/IMPL/SQL/Schema/Traits/Diff.pm Lib/IMPL/lang.pm _test/Test/SQL/Diff.pm
diffstat 4 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/SQL/Schema/Traits.pm	Mon May 16 04:30:38 2011 +0400
+++ b/Lib/IMPL/SQL/Schema/Traits.pm	Tue May 17 00:04:28 2011 +0400
@@ -371,6 +371,9 @@
 	
 	die new IMPL::InvalidArgumentException( tableName => "A table name is required" ) unless $table;
 	die new IMPL::InvalidArgumentException( constraintName => "A constraint name is required" ) unless $constraint;
+	
+	$this->tableName($table);
+	$this->constraintName($constraint);
 }
 
 sub apply {
--- a/Lib/IMPL/SQL/Schema/Traits/Diff.pm	Mon May 16 04:30:38 2011 +0400
+++ b/Lib/IMPL/SQL/Schema/Traits/Diff.pm	Tue May 17 00:04:28 2011 +0400
@@ -65,7 +65,7 @@
 					new IMPL::SQL::Schema::Traits::AlterTableAddConstraint( $dst->name, _Constraint2Traits($cnDst) );
 			}
 		} else {
-			push @dropConstraints,new IMPL::SQL::Schema::Traits::AlterTableDropConstrait( $src->name, $cnSrcName );
+			push @dropConstraints,new IMPL::SQL::Schema::Traits::AlterTableDropConstraint( $src->name, $cnSrcName );
 		}
 	}
 	
@@ -119,8 +119,8 @@
 			$op->isNullable( $info->{column}->isNullable ) unless equals($info->{column}->isNullable,$info->{prevColumn}->isNullable);
 			$op->defaultValue( $info->{column}->defaultValue ) unless equals($info->{column}->defaultValue, $info->{prevColumn}->defaultValue);
 			
-			my %diff = hashDiff($info->{prevColumn},$info->{column});
-			$op->options(\%diff) if %diff;
+			my $diff = hashDiff($info->{prevColumn}->tag,$info->{column}->tag);
+			$op->options($diff) if %$diff;
 			
 			push @updateColumns, $op;
 		}
--- a/Lib/IMPL/lang.pm	Mon May 16 04:30:38 2011 +0400
+++ b/Lib/IMPL/lang.pm	Tue May 17 00:04:28 2011 +0400
@@ -141,7 +141,8 @@
 sub hashDiff {
 	my ($src,$dst) = @_;
 	
-	$dst = { %$dst };
+	$dst = $dst ? { %$dst } : {} ;
+	$src ||= {};
 	
 	my %result;
 	
--- a/_test/Test/SQL/Diff.pm	Mon May 16 04:30:38 2011 +0400
+++ b/_test/Test/SQL/Diff.pm	Tue May 17 00:04:28 2011 +0400
@@ -14,13 +14,16 @@
 test diff => sub {
 	my $schemaSrc = new IMPL::SQL::Schema(name => 'simple', version => 1 );
 	
-	$schemaSrc->AddTable({
+	my $tbl = $schemaSrc->AddTable({
 		name => 'User',
 		columns => [
-			{ name => 'name', type => Varchar(255) }
+			{ name => 'name', type => Varchar(255) },
+			{ name => 'description', type => Varchar(255) }
 		]
 	});
 	
+	$tbl->AddConstraint( unique => { name => 'unique_name', columns => ['name'] });
+	
 	my $schemaDst = new IMPL::SQL::Schema(name => 'simple', version => 2 );
 	
 	my $users = $schemaDst->AddTable({
@@ -33,7 +36,7 @@
 	});
 	
 	$users->SetPrimaryKey('id');
-	$users->AddConstraint( unique => { name => 'unique_user_login', columns => ['login'] } );
+	$users->AddConstraint( unique => { name => 'unique_login', columns => ['login'] } );
 	
 	warn Dumper(IMPL::SQL::Schema::Traits::Diff->Diff($schemaSrc,$schemaDst));