From: Peter Rabbitson Date: Thu, 3 Sep 2009 07:06:25 +0000 (+0000) Subject: Fix pg matchtype parsing X-Git-Tag: v0.11008~90 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=840447a59faddb3c53b86dcee3a155aaa9fd631a;p=dbsrgits%2FSQL-Translator.git Fix pg matchtype parsing --- diff --git a/lib/SQL/Translator/Parser/PostgreSQL.pm b/lib/SQL/Translator/Parser/PostgreSQL.pm index 5a66cec..af1e393 100644 --- a/lib/SQL/Translator/Parser/PostgreSQL.pm +++ b/lib/SQL/Translator/Parser/PostgreSQL.pm @@ -660,7 +660,7 @@ table_constraint : comment(s?) constraint_name(?) table_constraint_type deferrab deferred => $item{'deferred'}, reference_table => $desc->{'reference_table'}, reference_fields => $desc->{'reference_fields'}, - match_type => $desc->{'match_type'}[0], + match_type => $desc->{'match_type'}, on_delete => $desc->{'on_delete'} || $desc->{'on_delete_do'}, on_update => $desc->{'on_update'} || $desc->{'on_update_do'}, comments => [ @comments ], @@ -718,9 +718,7 @@ deferrable : not(?) /deferrable/i deferred : /initially/i /(deferred|immediate)/i { $item[2] } -match_type : /match full/i { 'match_full' } - | - /match partial/i { 'match_partial' } +match_type : /match/i /partial|full|simple/i { $item[2] } key_action : key_delete | diff --git a/lib/SQL/Translator/Schema/Constraint.pm b/lib/SQL/Translator/Schema/Constraint.pm index 84f1d8c..aa1f0ea 100644 --- a/lib/SQL/Translator/Schema/Constraint.pm +++ b/lib/SQL/Translator/Schema/Constraint.pm @@ -285,7 +285,7 @@ sub match_type { =head2 match_type Get or set the constraint's match_type. Only valid values are "full" -or "partial." +"partial" and "simple" my $match_type = $constraint->match_type('FULL'); @@ -296,7 +296,7 @@ or "partial." if ( $arg ) { $arg = lc $arg; return $self->error("Invalid match type: $arg") - unless $arg eq 'full' || $arg eq 'partial'; + unless $arg eq 'full' || $arg eq 'partial' || $arg eq 'simple'; $self->{'match_type'} = $arg; } diff --git a/t/14postgres-parser.t b/t/14postgres-parser.t index 3bfe6a5..0facca8 100644 --- a/t/14postgres-parser.t +++ b/t/14postgres-parser.t @@ -8,7 +8,7 @@ use SQL::Translator::Schema::Constants; use Test::SQL::Translator qw(maybe_plan); BEGIN { - maybe_plan(120, 'SQL::Translator::Parser::PostgreSQL'); + maybe_plan(122, 'SQL::Translator::Parser::PostgreSQL'); SQL::Translator::Parser::PostgreSQL->import('parse'); } @@ -63,7 +63,9 @@ my $sql = q[ alter table only t_test1 add constraint c_u1 unique (f_varchar); alter table t_test1 add constraint "c_fk2" foreign key (f_fk2) - references t_test2 (f_id) on update no action on delete cascade; + references t_test2 (f_id) match simple + on update no action on delete cascade deferrable; + alter table t_test1 drop column f_dropped restrict; @@ -231,6 +233,8 @@ is( $c4->reference_table, 't_test2', 'Constraint is to table "t_test2"' ); is( join(',', $c4->reference_fields), 'f_id', 'Constraint is to field "f_id"' ); is( $c4->on_delete, 'cascade', 'On delete: cascade' ); is( $c4->on_update, 'no_action', 'On delete: no action' ); +is( $c4->match_type, 'simple', 'Match type: simple' ); +is( $c4->deferrable, 1, 'Deferrable detected' ); my $t2 = shift @tables; is( $t2->name, 't_test2', 'Table t_test2 exists' );