From: Alexander Hartmaier Date: Fri, 15 Jan 2010 18:21:20 +0000 (+0000) Subject: added branch no_duplicate_indexes_for_pk_cols with test and fix X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=620df7e8b1f5c9f335989baff37ddfe763032765;p=dbsrgits%2FDBIx-Class-Historic.git added branch no_duplicate_indexes_for_pk_cols with test and fix --- diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index d67ce9e..2aa5098 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -210,10 +210,15 @@ sub parse { { # Constraints are added only if applicable next unless $fk_constraint; - + # Make sure we dont create the same foreign key constraint twice my $key_test = join("\x00", sort @keys); next if $created_FK_rels{$rel_table}->{$key_test}; + + # Make sure we dont create additional indexes for the + # primary columns + my $pk_test = join("\x00", sort @primary); + next if $key_test eq $pk_test; if (scalar(@keys)) { diff --git a/t/99dbic_sqlt_parser.t b/t/99dbic_sqlt_parser.t index 4d1ddac..ccfc60a 100644 --- a/t/99dbic_sqlt_parser.t +++ b/t/99dbic_sqlt_parser.t @@ -38,14 +38,22 @@ my @sources = grep { my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } }); - foreach my $source (@sources) { - my $table = get_table($sqlt_schema, $schema, $source); + foreach my $source_name (@sources) { + my $table = get_table($sqlt_schema, $schema, $source_name); my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints); my @indices = $table->get_indices; + my $index_count = scalar(@indices); - $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def - is($index_count, $fk_count, "correct number of indices for $source with no args"); + $index_count++ if ($source_name eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def + is($index_count, $fk_count, "correct number of indices for $source_name with no args"); + + for my $index (@indices) { + my $source = $schema->source($source_name); + my @pks = $source->primary_columns; + my @idx_cols = $index->fields; + ok ( !eq_set(\@pks, \@idx_cols), "no additional index for the primary columns exists in $source_name"); + } } }