From: Rafael Kitover Date: Wed, 29 Aug 2012 16:18:03 +0000 (-0400) Subject: minor optimization for Pg FK attrs, better test X-Git-Tag: 0.07028~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b976244637f29ed09595b371def46ceccbff5cc3;p=dbsrgits%2FDBIx-Class-Schema-Loader.git minor optimization for Pg FK attrs, better test Set the FK attributes in Pg _table_fk_info only once instead of once for each column. Also test DEFERRABLE being on instead of off, since it defaults to off. --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index f9176d1..a751b94 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -83,9 +83,11 @@ EOF schema => $remote_schema, ) unless exists $rels{$fk}{remote_table}; - $rels{$fk}{attrs}{on_delete} = uc $delete_rule; - $rels{$fk}{attrs}{on_update} = uc $update_rule; - $rels{$fk}{attrs}{is_deferrable} = uc $is_deferrable eq 'YES' ? 1 : 0; + $rels{$fk}{attrs} ||= { + on_delete => uc $delete_rule, + on_update => uc $update_rule, + is_deferrable => uc $is_deferrable eq 'YES' ? 1 : 0, + }; } return [ values %rels ]; diff --git a/t/10_03pg_common.t b/t/10_03pg_common.t index 342e771..ed1ed93 100644 --- a/t/10_03pg_common.t +++ b/t/10_03pg_common.t @@ -239,7 +239,7 @@ my $tester = dbixcsl_common_tests->new( id bigserial primary key, eleven_id int, foreign key (eleven_id) references pg_loader_test9(id) - on delete restrict on update set null + on delete restrict on update set null deferrable ) }, @@ -288,7 +288,7 @@ my $tester = dbixcsl_common_tests->new( is $rel_info->{attrs}{on_update}, 'SET NULL', 'ON UPDATE clause introspected correctly'; - is $rel_info->{attrs}{is_deferrable}, 0, + is $rel_info->{attrs}{is_deferrable}, 1, 'DEFERRABLE clause introspected correctly'; foreach my $db_schema (['dbicsl-test', 'dbicsl.test'], '%') {