use SQL::Translator::Schema::Constants;
use Storable 'dclone';
-plan tests => 6;
+plan tests => 7;
use_ok('SQL::Translator::Diff') or die "Cannot continue\n";
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':
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
+}