From: Sebastian Podjasek Date: Wed, 8 Apr 2015 23:36:40 +0000 (+0200) Subject: Fix PostgreSQL grammar parsing of UUID, time, timetz column types X-Git-Tag: v0.11022~38 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=84ef6e4e04d8beed11b86c54a3a7759cb772bcae;p=dbsrgits%2FSQL-Translator.git Fix PostgreSQL grammar parsing of UUID, time, timetz column types --- diff --git a/Changes b/Changes index 50dd5f3..2ba7d65 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Changes for SQL::Translator * Add support for monotonically increasing SQLite autoincs (GH#47) * Add support for CHECK constraint in SQLite producer (GH#57) * Fix forgotten quoting in the MySQL DROP TABLE diff producer (GH#50) + * Fix Pg grammar parsing of UUID, time, timetz columns (RT#100196, GH#52) * Improve add_trigger consistency between producers (GH#48) * Declare dependencies in deterministic order (RT#102859) * Multiple speedups of naive internal debugging mechanism (GH#54) diff --git a/lib/SQL/Translator/Parser/PostgreSQL.pm b/lib/SQL/Translator/Parser/PostgreSQL.pm index ce3cfbb..dc05928 100644 --- a/lib/SQL/Translator/Parser/PostgreSQL.pm +++ b/lib/SQL/Translator/Parser/PostgreSQL.pm @@ -613,11 +613,16 @@ pg_data_type : $return = { type => 'bytea' }; } | - /(timestamptz|timestamp)(?:\(\d\))?( with(?:out)? time zone)?/i + / ( timestamp (?:tz)? ) (?: \( \d \) )? ( \s with (?:out)? \s time \s zone )? /ix { $return = { type => 'timestamp' . ($2||'') }; } | + / ( time (?:tz)? ) (?: \( \d \) )? ( \s with (?:out)? \s time \s zone )? /ix + { + $return = { type => 'time' . ($2||'') }; + } + | /text/i { $return = { @@ -626,7 +631,7 @@ pg_data_type : }; } | - /(bit|box|cidr|circle|date|inet|line|lseg|macaddr|money|numeric|decimal|path|point|polygon|timetz|time|varchar|json|hstore)/i + /(bit|box|cidr|circle|date|inet|line|lseg|macaddr|money|numeric|decimal|path|point|polygon|varchar|json|hstore|uuid)/i { $return = { type => $item[1] }; } diff --git a/t/14postgres-parser.t b/t/14postgres-parser.t index d5a02dd..5548258 100644 --- a/t/14postgres-parser.t +++ b/t/14postgres-parser.t @@ -32,7 +32,10 @@ my $sql = q{ f_timestamp2 timestamp without time zone, f_json json, f_hstore hstore, - f_numarray numeric(7,2) [ ] + f_numarray numeric(7,2) [ ], + f_uuid uuid, + f_time time(0) with time zone, + f_time2 time without time zone ); create table t_test2 ( @@ -120,7 +123,7 @@ is( $t1->name, 't_test1', 'Table t_test1 exists' ); is( $t1->comments, 'comment on t_test1', 'Table comment exists' ); my @t1_fields = $t1->get_fields; -is( scalar @t1_fields, 16, '16 fields in t_test1' ); +is( scalar @t1_fields, 19, '19 fields in t_test1' ); my $f1 = shift @t1_fields; is( $f1->name, 'f_serial', 'First field is "f_serial"' ); @@ -254,6 +257,33 @@ is( $f15->default_value, undef, 'Default value is "undef"' ); is( $f15->is_primary_key, 0, 'Field is not PK' ); is( $f15->is_foreign_key, 0, 'Field is not FK' ); +my $f16 = shift @t1_fields; +is( $f16->name, 'f_uuid', '16th field is "f_uuid"' ); +is( $f16->data_type, 'uuid', 'Field is a UUID' ); +is( $f16->is_nullable, 1, 'Field can be null' ); +is( $f16->size, 0, 'Size is "0"' ); +is( $f16->default_value, undef, 'Default value is "undef"' ); +is( $f16->is_primary_key, 0, 'Field is not PK' ); +is( $f16->is_foreign_key, 0, 'Field is not FK' ); + +my $f17 = shift @t1_fields; +is( $f17->name, 'f_time', '17th field is "f_time"' ); +is( $f17->data_type, 'time with time zone', 'Field is a time with time zone' ); +is( $f17->is_nullable, 1, 'Field can be null' ); +is( $f17->size, 0, 'Size is "0"' ); +is( $f17->default_value, undef, 'Default value is "undef"' ); +is( $f17->is_primary_key, 0, 'Field is not PK' ); +is( $f17->is_foreign_key, 0, 'Field is not FK' ); + +my $f18 = shift @t1_fields; +is( $f18->name, 'f_time2', '18th field is "f_time2"' ); +is( $f18->data_type, 'time without time zone', 'Field is a time without time zone' ); +is( $f18->is_nullable, 1, 'Field can be null' ); +is( $f18->size, 0, 'Size is "0"' ); +is( $f18->default_value, undef, 'Default value is "undef"' ); +is( $f18->is_primary_key, 0, 'Field is not PK' ); +is( $f18->is_foreign_key, 0, 'Field is not FK' ); + # my $fk_ref2 = $f11->foreign_key_reference; # isa_ok( $fk_ref2, 'SQL::Translator::Schema::Constraint', 'FK' ); # is( $fk_ref2->reference_table, 't_test2', 'FK is to "t_test2" table' );