Simple change to make Postgres simple array types produce correctly
Colin Newell [Mon, 18 Apr 2011 14:11:59 +0000 (15:11 +0100)]
AUTHORS
Changes
lib/SQL/Translator/Producer/PostgreSQL.pm
t/47postgres-producer.t

diff --git a/AUTHORS b/AUTHORS
index 33ab716..60b383c 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -9,6 +9,7 @@ The following people have contributed to the SQLFairy project:
 -   Chris Hilton <chilton@alterpoint.com>
 -   Chris Mungall <cjm@fruitfly.org>
 -   Chris To <christot@users.sourceforge.net>
+-   Colin Newell <colin.newell@gmail.com>
 -   Daniel Ruoso <daniel@ruoso.com>
 -   Darren Chamberlain <dlc@users.sourceforge.net>
 -   Dave Cash <dave@gnofn.org>
diff --git a/Changes b/Changes
index efa208c..2e06287 100644 (file)
--- 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
index 02c9f11..4b883c7 100644 (file)
@@ -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
index 547ddf2..10b2bc5 100644 (file)
@@ -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',