X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F30sqlt-new-diff-mysql.t;h=fced6afda88af2bd74fd48ab0a72411eaea8a018;hb=4104f82be9bfe6cc21f16b8f72d9c38eb6f52d69;hp=867931a087a812e3297d709c4b5d2fced6ab4f76;hpb=804f9d60475a4535bd8b7dd59ba922a7529bb1a1;p=dbsrgits%2FSQL-Translator.git diff --git a/t/30sqlt-new-diff-mysql.t b/t/30sqlt-new-diff-mysql.t index 867931a..fced6af 100644 --- a/t/30sqlt-new-diff-mysql.t +++ b/t/30sqlt-new-diff-mysql.t @@ -13,7 +13,7 @@ use Test::SQL::Translator qw(maybe_plan); use SQL::Translator::Schema::Constants; use Storable 'dclone'; -plan tests => 6; +plan tests => 7; use_ok('SQL::Translator::Diff') or die "Cannot continue\n"; @@ -214,7 +214,7 @@ COMMIT; data_type => 'int' ); - $out = SQL::Translator::Diff::schema_diff($s1, 'MySQL', $s2, 'MySQL' ); + my $out = SQL::Translator::Diff::schema_diff($s1, 'MySQL', $s2, 'MySQL' ); eq_or_diff($out, <<'## END OF DIFF', "Batch alter of constraints work for InnoDB"); -- Convert schema 'Schema 1' to 'Schema 2': @@ -229,3 +229,49 @@ ALTER TABLE employee ADD COLUMN new integer, COMMIT; ## END OF DIFF } + +{ + # Test other things about renaming tables to - namely that renames + # constraints are still formated right. + + my $s1 = SQL::Translator::Schema->new; + my $s2 = SQL::Translator::Schema->new; + + $s1->name('Schema 3'); + $s2->name('Schema 4'); + + my $t1 = $s1->add_table(dclone($target_schema->get_table('employee'))); + my $t2 = dclone($target_schema->get_table('employee')); + $t2->name('fnord'); + $t2->extra(renamed_from => 'employee'); + $s2->add_table($t2); + + + $t1->add_constraint( + name => 'bar_fk', + type => 'FOREIGN KEY', + fields => ['employee_id'], + reference_fields => ['id'], + reference_table => 'bar', + ); + $t2->add_constraint( + name => 'foo_fk', + type => 'FOREIGN KEY', + fields => ['employee_id'], + reference_fields => ['id'], + reference_table => 'foo', + ); + + my $out = SQL::Translator::Diff::schema_diff($s1, 'MySQL', $s2, 'MySQL' ); + eq_or_diff($out, <<'## END OF DIFF', "Alter/drop constraints works with rename table"); +-- Convert schema 'Schema 3' to 'Schema 4': + +BEGIN; + +ALTER TABLE employee RENAME TO fnord, + DROP FOREIGN KEY bar_fk, + ADD CONSTRAINT foo_fk FOREIGN KEY (employee_id) REFERENCES foo (id); + +COMMIT; +## END OF DIFF +}