Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 92471
Status: rejected
Priority: 0/
Queue: DBIx-Class

Owner: Nobody in particular
Requestors: TREVELYAN [...]

Bug Information
Severity: (no value)
Broken in: 0.08250
Fixed in: (no value)

Subject: add_unique_constraint generates indexes without a prefix leads to name conflict (with fix suggestion)
Download (untitled) / with headers
text/plain 1.1k
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
Download (untitled) / with headers
text/plain 766b
On Sat Jan 25 22:53:10 2014, TREVELYAN wrote: Show quoted text
> Hi, > > add_unique_constraint() will generate SQL like this: > > CREATE UNIQUE INDEX $NAME ON $TABLE ($FIELD); >
This is correct. And your proposed fix will break this contract - that is the name you supplied to add_unique_constraint is supposed to be used as-is when passed to SQL::Translator. Furthermore - very few RDBMS have schema-wide indexing, most support identically named indexes as long as they are attached to different tables. The correct solution in your case is to supply an explicit name in the add_unique_contraint call(). I am rejecting this ticket as there is no warranted change that can be made in DBIC itself. Feel free to continue the discussion / reopen it if I missed something. Cheers

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to