Skip to content

Commit

Permalink
Fix PostgreSQL grammar parsing of UUID, time, timetz column types
Browse files Browse the repository at this point in the history
  • Loading branch information
SPodjasek authored and ribasushi committed Jun 25, 2015
1 parent e773f3f commit 84ef6e4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions lib/SQL/Translator/Parser/PostgreSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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] };
}
Expand Down
34 changes: 32 additions & 2 deletions t/14postgres-parser.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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"' );
Expand Down Expand Up @@ -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' );
Expand Down

0 comments on commit 84ef6e4

Please sign in to comment.