[Bast-commits] r8328 - in DBIx-Class/0.08/branches: . no_duplicate_indexes_for_pk_cols/lib/SQL/Translator/Parser/DBIx no_duplicate_indexes_for_pk_cols/t

abraxxa at dev.catalyst.perl.org abraxxa at dev.catalyst.perl.org
Fri Jan 15 18:21:20 GMT 2010


Author: abraxxa
Date: 2010-01-15 18:21:20 +0000 (Fri, 15 Jan 2010)
New Revision: 8328

Added:
   DBIx-Class/0.08/branches/no_duplicate_indexes_for_pk_cols/
Modified:
   DBIx-Class/0.08/branches/no_duplicate_indexes_for_pk_cols/lib/SQL/Translator/Parser/DBIx/Class.pm
   DBIx-Class/0.08/branches/no_duplicate_indexes_for_pk_cols/t/99dbic_sqlt_parser.t
Log:
added branch no_duplicate_indexes_for_pk_cols with test and fix


Copied: DBIx-Class/0.08/branches/no_duplicate_indexes_for_pk_cols (from rev 8327, DBIx-Class/0.08/trunk)

Modified: DBIx-Class/0.08/branches/no_duplicate_indexes_for_pk_cols/lib/SQL/Translator/Parser/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/SQL/Translator/Parser/DBIx/Class.pm	2010-01-15 18:10:42 UTC (rev 8327)
+++ DBIx-Class/0.08/branches/no_duplicate_indexes_for_pk_cols/lib/SQL/Translator/Parser/DBIx/Class.pm	2010-01-15 18:21:20 UTC (rev 8328)
@@ -210,10 +210,15 @@
             {
                 # 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)) {
 

Modified: DBIx-Class/0.08/branches/no_duplicate_indexes_for_pk_cols/t/99dbic_sqlt_parser.t
===================================================================
--- DBIx-Class/0.08/trunk/t/99dbic_sqlt_parser.t	2010-01-15 18:10:42 UTC (rev 8327)
+++ DBIx-Class/0.08/branches/no_duplicate_indexes_for_pk_cols/t/99dbic_sqlt_parser.t	2010-01-15 18:21:20 UTC (rev 8328)
@@ -38,14 +38,22 @@
 { 
   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");
+    }
   }
 }
 




More information about the Bast-commits mailing list