Subject: | UUID, time, timetz columns |
Add handling of UUID columns, also add tests for time(|tz) columns
Subject: | sqlt-fix-90089d6.patch |
commit efc914b59f8fc4c5215fe67f0abb5b30ef3c3409
Author: Sebastian Podjasek <sebastian@podjasek.pl>
Date: Sat Nov 8 01:10:08 2014 +0100
Add UUID, time, timetz column handling
diff --git a/lib/SQL/Translator/Parser/PostgreSQL.pm b/lib/SQL/Translator/Parser/PostgreSQL.pm
index fdcc2d8..1d07983 100644
--- a/lib/SQL/Translator/Parser/PostgreSQL.pm
+++ b/lib/SQL/Translator/Parser/PostgreSQL.pm
@@ -614,6 +614,11 @@ pg_data_type :
$return = { type => 'timestamp' . ($2||'') };
}
|
+ /(timetz|time)(?:\(\d\))?( with(?:out)? time zone)?/i
+ {
+ $return = { type => 'time' . ($2||'') };
+ }
+ |
/text/i
{
$return = {
@@ -622,7 +627,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|timetz|time|varchar|json|hstore|uuid)/i
{
$return = { type => $item[1] };
}
diff --git a/t/14postgres-parser.t b/t/14postgres-parser.t
index 4f50511..da12ee4 100644
--- a/t/14postgres-parser.t
+++ b/t/14postgres-parser.t
@@ -32,6 +32,9 @@ my $sql = q{
f_timestamp2 timestamp without time zone,
f_json json,
f_hstore hstore
+ f_uuid uuid,
+ f_time time(0) with time_zone,
+ f_time2 time without time zone
);
create table t_test2 (
@@ -244,6 +247,33 @@ is( $f14->default_value, undef, 'Default value is "undef"' );
is( $f14->is_primary_key, 0, 'Field is not PK' );
is( $f14->is_foreign_key, 0, 'Field is not FK' );
+my $f15 = shift @t1_fields;
+is( $f15->name, 'f_uuid', '13th field is "f_uuid"' );
+is( $f15->data_type, 'uuid', 'Field is a UUID' );
+is( $f15->is_nullable, 1, 'Field can be null' );
+is( $f15->size, 0, 'Size is "0"' );
+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_time', '14th field is "f_time"' );
+is( $f16->data_type, 'time with time zone', 'Field is a time with time zone' );
+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_time2', '15th field is "f_time2"' );
+is( $f17->data_type, 'time without time zone', 'Field is a time without 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 $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' );