From: Luke Saunders Date: Tue, 23 Oct 2007 14:08:46 +0000 (+0000) Subject: changed constraint and index generation to be consistent with DB defaults X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d25d7fc27925eb19fe407dcfb41f45d26a8c5236;p=dbsrgits%2FDBIx-Class-Historic.git changed constraint and index generation to be consistent with DB defaults --- diff --git a/Makefile.PL b/Makefile.PL index 51a0096..67326b5 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -22,7 +22,7 @@ requires 'Scope::Guard' => 0.03; # Perl 5.8.0 doesn't have utf8::is_utf8() requires 'Encode' => 0 if ($] <= 5.008000); -build_requires 'DBD::SQLite' => 1.14; +build_requires 'DBD::SQLite' => 1.13; build_requires 'Test::Builder' => 0.33; install_script 'script/dbicadmin'; diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 4f48015..0138050 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -96,6 +96,13 @@ sub parse { $table->primary_key($source->primary_columns); my @primary = $source->primary_columns; + foreach my $field (@primary) { + my $index = $table->add_index( + name => $field, + fields => [$field], + type => 'NORMAL', + ); + } my %unique_constraints = $source->unique_constraints; foreach my $uniq (keys %unique_constraints) { if (!$source->compare_relationship_keys($unique_constraints{$uniq}, \@primary)) { @@ -104,6 +111,13 @@ sub parse { name => "$uniq", fields => $unique_constraints{$uniq} ); + + my $index = $table->add_index( + name => $unique_constraints{$uniq}->[0], + fields => $unique_constraints{$uniq}, + type => 'NORMAL', + ); + } } @@ -159,7 +173,7 @@ sub parse { if (scalar(@keys)) { $table->add_constraint( type => 'foreign_key', - name => "fk_$keys[0]", + name => $table->name . "_fk_$keys[0]", fields => \@keys, reference_fields => \@refkeys, reference_table => $rel_table, @@ -168,7 +182,7 @@ sub parse { ); my $index = $table->add_index( - name => $table->name . "_fk_$keys[0]", + name => $keys[0], fields => \@keys, type => 'NORMAL', );