From: mix3@サタデーナイトフィーバー Date: Thu, 2 Apr 2015 04:14:46 +0000 (+0900) Subject: Quoted table_name wasn't being used during MySQL DROP TABLE construction X-Git-Tag: v0.11022~44 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=237e4855d512ffd8877490dc986fe1385087ad27;p=dbsrgits%2FSQL-Translator.git Quoted table_name wasn't being used during MySQL DROP TABLE construction --- diff --git a/Changes b/Changes index 728a6a1..3c5a770 100644 --- a/Changes +++ b/Changes @@ -1,8 +1,9 @@ Changes for SQL::Translator * Add support for monotonically increasing SQLite autoincs (GH#47) + * Fix forgotten quoting in the MySQL DROP TABLE diff producer (GH#50) * Declare dependencies in deterministic order (RT#102859) - * Multiple speedups of naive internal debugging mechanism + * Multiple speedups of naive internal debugging mechanism (GH#54) * Remove dependency on List::MoreUtils ( http://is.gd/lmu_cac_debacle ) 0.11021 2015-01-29 diff --git a/lib/SQL/Translator/Producer/MySQL.pm b/lib/SQL/Translator/Producer/MySQL.pm index 904b294..86d23c3 100644 --- a/lib/SQL/Translator/Producer/MySQL.pm +++ b/lib/SQL/Translator/Producer/MySQL.pm @@ -938,12 +938,13 @@ sub batch_alter_table { sub drop_table { my ($table, $options) = @_; - # Drop (foreign key) constraints so table drops cleanly - my @sql = batch_alter_table($table, { alter_drop_constraint => [ grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints ] }, $options); - - my $table_name = _generator($options)->quote($table); - return (@sql, "DROP TABLE $table"); - + return ( + # Drop (foreign key) constraints so table drops cleanly + batch_alter_table( + $table, { alter_drop_constraint => [ grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints ] }, $options + ), + 'DROP TABLE ' . _generator($options)->quote($table), + ); } sub rename_table { diff --git a/t/30sqlt-new-diff-mysql.t b/t/30sqlt-new-diff-mysql.t index 2df13b5..706c275 100644 --- a/t/30sqlt-new-diff-mysql.t +++ b/t/30sqlt-new-diff-mysql.t @@ -279,6 +279,7 @@ COMMIT; $s2->name('Schema 4'); my $t1 = $s1->add_table(dclone($target_schema->get_table('employee'))); + $s1->add_table(dclone($source_schema->get_table('deleted'))); my $t2 = dclone($target_schema->get_table('employee')); $t2->name('fnord'); $t2->extra(renamed_from => 'employee'); @@ -310,6 +311,10 @@ ALTER TABLE employee RENAME TO fnord, DROP FOREIGN KEY bar_fk, ADD CONSTRAINT foo_fk FOREIGN KEY (employee_id) REFERENCES foo (id); +ALTER TABLE deleted DROP FOREIGN KEY fk_fake; + +DROP TABLE deleted; + COMMIT; @@ -328,6 +333,10 @@ ALTER TABLE `employee` RENAME TO `fnord`, DROP FOREIGN KEY `bar_fk`, ADD CONSTRAINT `foo_fk` FOREIGN KEY (`employee_id`) REFERENCES `foo` (`id`); +ALTER TABLE `deleted` DROP FOREIGN KEY `fk_fake`; + +DROP TABLE `deleted`; + COMMIT;