X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FDBIx%2FClass.pm;h=4f48015d38a82625b94c34341468307db4fa2e20;hb=5e253a3e0e5e369eb2285be32e0f7217638d8ad9;hp=a0f37b6153381698230c9bb443018d2e1cfed9d8;hpb=c385ecea5ec4297f269bcc2b8db8e08f5772196d;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index a0f37b6..4f48015 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -67,8 +67,6 @@ sub parse { foreach my $moniker (@monikers) { - #eval "use $tableclass"; - #print("Can't load $tableclass"), next if($@); my $source = $dbixschema->source($moniker); next if $seen_tables{$source->name}++; @@ -80,7 +78,7 @@ sub parse { my $colcount = 0; foreach my $col ($source->columns) { - # assuming column_info in dbix is the same as DBI (?) + # assuming column_info in dbic is the same as DBI (?) # data_type is a number, column_type is text? my %colinfo = ( name => $col, @@ -109,11 +107,6 @@ sub parse { } } - foreach my $idx ( $source->indices ) { - my $ret = $table->add_index(%$idx) - or die $table->error; - } - my @rels = $source->relationships(); my %created_FK_rels; @@ -163,19 +156,37 @@ sub parse { ) { $created_FK_rels{$rel_table}->{$key_test} = 1; - $table->add_constraint( - type => 'foreign_key', - name => "fk_$keys[0]", - fields => \@keys, - reference_fields => \@refkeys, - reference_table => $rel_table, - on_delete => $on_delete, - on_update => $on_update - ); + if (scalar(@keys)) { + $table->add_constraint( + type => 'foreign_key', + name => "fk_$keys[0]", + fields => \@keys, + reference_fields => \@refkeys, + reference_table => $rel_table, + on_delete => $on_delete, + on_update => $on_update + ); + + my $index = $table->add_index( + name => $table->name . "_fk_$keys[0]", + fields => \@keys, + type => 'NORMAL', + ); + } + } } } + + if ($source->result_class->can('sqlt_deploy_hook')) { + $source->result_class->sqlt_deploy_hook($table); + } + } + + if ($dbixschema->can('sqlt_deploy_hook')) { + $dbixschema->sqlt_deploy_hook($schema); } + return 1; }