* Check in MySQL parser to avoid trying to parse a table defined twice in the same
file as indices (and probably other things) get messed up
* Workaround for some MySQL quirks on primary key definitions
+* Fix dropping primary keys in MySQL diffs (RT#62250, patch from Nick Bertrand)
* MySQL producer does not attempt to write out non-existent unique constraint names
* MySQL parser correctly differentiates between signed and unsigned integer column
display sizes
my $qc = $options->{quote_field_names} || '';
my $table_name = quote_table_name($c->table->name, $qt);
- my $out = sprintf('ALTER TABLE %s DROP %s %s',
- $table_name,
- $c->type eq FOREIGN_KEY ? $c->type : "INDEX",
- $qc . $c->name . $qc );
-
- return $out;
+ my @out = ('ALTER','TABLE',$table_name,'DROP');
+ if($c->type eq PRIMARY_KEY) {
+ push @out, $c->type;
+ }
+ else {
+ push @out, ($c->type eq FOREIGN_KEY ? $c->type : "INDEX"),
+ $qc . $c->name . $qc;
+ }
+ return join(' ',@out);
}
sub alter_create_constraint
#=============================================================================
BEGIN {
- maybe_plan(72,
+ maybe_plan(73,
'YAML',
'SQL::Translator::Producer::MySQL',
'Test::Differences',
}
}
}
+
+{ # test for rt62250
+ my $table = SQL::Translator::Schema::Table->new(name => 'table');
+ $table->add_field(
+ SQL::Translator::Schema::Field->new( name => 'mypk',
+ table => $table,
+ data_type => 'INT',
+ size => 10,
+ default_value => undef,
+ is_auto_increment => 1,
+ is_nullable => 0,
+ is_foreign_key => 0,
+ is_unique => 1 ));
+
+ my $constraint = $table->add_constraint(fields => ['mypk'], type => 'PRIMARY_KEY');
+ my $options = {quote_table_names => '`'};
+ is(SQL::Translator::Producer::MySQL::alter_drop_constraint($constraint,$options),
+ 'ALTER TABLE `table` DROP PRIMARY KEY','valid drop primary key');
+}