From: Colin Newell Date: Mon, 18 Apr 2011 14:11:59 +0000 (+0100) Subject: Simple change to make Postgres simple array types produce correctly X-Git-Tag: v0.11008~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aacb31871ec4c0eaf0c4c89287c4ac395063625f;p=dbsrgits%2FSQL-Translator.git Simple change to make Postgres simple array types produce correctly --- diff --git a/AUTHORS b/AUTHORS index 33ab716..60b383c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,6 +9,7 @@ The following people have contributed to the SQLFairy project: - Chris Hilton - Chris Mungall - Chris To +- Colin Newell - Daniel Ruoso - Darren Chamberlain - Dave Cash diff --git a/Changes b/Changes index efa208c..2e06287 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,8 @@ * Quote everything in SQL Server * Turn off constraints before dropping tables in SQL Server * Make true unique constraints if needed in SQL Server +* Fixed Producer::PostgresSQL to output array type after type size, + i.e. varchar(64)[] rather than varchar[](64) # ---------------------------------------------------------- # 0.11007 2010-11-30 diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm index 02c9f11..4b883c7 100644 --- a/lib/SQL/Translator/Producer/PostgreSQL.pm +++ b/lib/SQL/Translator/Producer/PostgreSQL.pm @@ -674,6 +674,7 @@ sub convert_datatype my @size = $field->size; my $data_type = lc $field->data_type; + my $array = $data_type =~ s/\[\]$//; if ( $data_type eq 'enum' ) { # my $len = 0; @@ -740,6 +741,10 @@ sub convert_datatype } elsif ( defined $size[0] && $size[0] > 0 ) { $data_type .= '(' . join( ',', @size ) . ')'; } + if($array) + { + $data_type .= '[]'; + } # # Geography diff --git a/t/47postgres-producer.t b/t/47postgres-producer.t index 547ddf2..10b2bc5 100644 --- a/t/47postgres-producer.t +++ b/t/47postgres-producer.t @@ -14,7 +14,7 @@ use FindBin qw/$Bin/; #============================================================================= BEGIN { - maybe_plan(38, + maybe_plan(39, 'SQL::Translator::Producer::PostgreSQL', 'Test::Differences', ) @@ -40,6 +40,20 @@ my $field1_sql = SQL::Translator::Producer::PostgreSQL::create_field($field1); is($field1_sql, 'myfield character varying(10)', 'Create field works'); +my $field_array = SQL::Translator::Schema::Field->new( name => 'myfield', + table => $table, + data_type => 'character varying[]', + size => 10, + default_value => undef, + is_auto_increment => 0, + is_nullable => 1, + is_foreign_key => 0, + is_unique => 0 ); + +my $field_array_sql = SQL::Translator::Producer::PostgreSQL::create_field($field_array); + +is($field_array_sql, 'myfield character varying(10)[]', 'Create field works'); + my $field2 = SQL::Translator::Schema::Field->new( name => 'myfield', table => $table, data_type => 'VARCHAR',