Subject: | add_unique_constraint generates indexes without a prefix leads to name conflict (with fix suggestion) |
Hi,
add_unique_constraint() will generate SQL like this:
CREATE UNIQUE INDEX $NAME ON $TABLE ($FIELD);
However if you have multiple tables with same field (and constraint name) this will lead to a index naming conflict in the DB schema.
I noted that belongs_to() does not have this problem as it adds a table_name 'prefix':
...
279 my $index = $table->add_index(
280 name => join('_', $table_name, 'idx', @keys),
...
Line numbers are from version 1.10 of SQL::Translator::Parser::DBIx::Class.
Please can do the same for add_unique_constraint(). I tried this on my system and it worked fine:
...
149 foreach my $uniq (sort keys %unique_constraints) {
150 if (!$source->_compare_relationship_keys($unique_constraints{$uniq}, \@primary)) {
151 $table->add_constraint(
152 type => 'unique',
153 name => join('_', $table_name, "uniq", $uniq),
154 fields => $unique_constraints{$uniq}
155 );
156 }
157 }
...
Thanks & regards,
Thorben