};
+ # Names are only specific to a given schema
+ local %used_names = ();
+
#
# Work out which tables need to be InnoDB to support foreign key
# constraints. We do this first as we need InnoDB at both ends.
$mysql_table_type_to_options->($table);
- foreach ( $table->get_constraints ) {
- next unless $_->type eq FOREIGN_KEY;
+ foreach my $c( $table->get_constraints ) {
+ next unless $c->type eq FOREIGN_KEY;
+
+ # Normalize constraint names here.
+ my $c_name = $c->name;
+ # Give the constraint a name if it doesn't have one, so it doens't feel
+ # left out
+ $c_name = $table->name . '_fk' unless length $c_name;
+
+ $c->name( next_unused_name($c_name) );
+
for my $meth (qw/table reference_table/) {
- my $table = $schema->get_table($_->$meth) || next;
+ my $table = $schema->get_table($c->$meth) || next;
next if $mysql_table_type_to_options->($table);
$table->options( { 'ENGINE' => 'InnoDB' } );
}
my $qf = $options->{quote_field_names} || '';
my $qt = $options->{quote_table_names} || '';
my $leave_name = $options->{leave_name} || undef;
- my $counter = ($options->{fk_name_counter} ||= {});
my @fields = $c->fields or next;
my $table = $c->table;
my $c_name = $c->name;
- # Give the constraint a name if it doesn't have one, so it doens't feel
- # left out
- unless ( $c_name ){
- $c_name = $table->name . '_fk';
- }
-
- $counter->{$table} ||= {};
my $def = join(' ',
map { $_ || () }
'CONSTRAINT',
- $qt . join('_', next_unused_name($c_name)
- ) . $qt,
+ $qt . $c_name . $qt,
'FOREIGN KEY'
);
ALTER TABLE employee DROP FOREIGN KEY FK5302D47D93FE702E,
DROP COLUMN job_title,
- ADD CONSTRAINT FK5302D47D93FE702E_diff_1 FOREIGN KEY (employee_id) REFERENCES person (person_id);
+ ADD CONSTRAINT FK5302D47D93FE702E_diff FOREIGN KEY (employee_id) REFERENCES person (person_id);
ALTER TABLE person DROP UNIQUE UC_age_name,
DROP INDEX u_name,
ADD COLUMN is_rock_star tinyint(4) DEFAULT '1',