[Bast-commits] r8223 - in branches/DBIx-Class-Schema-Loader/current: . lib/DBIx/Class/Schema/Loader/DBI t

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Sat Jan 2 16:12:38 GMT 2010


Author: caelum
Date: 2010-01-02 16:12:37 +0000 (Sat, 02 Jan 2010)
New Revision: 8223

Modified:
   branches/DBIx-Class-Schema-Loader/current/Changes
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm
   branches/DBIx-Class-Schema-Loader/current/t/12pg_common.t
Log:
fix up VARBIT for postgres too, that's all the varying types except NUMERIC

Modified: branches/DBIx-Class-Schema-Loader/current/Changes
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/Changes	2010-01-02 15:35:39 UTC (rev 8222)
+++ branches/DBIx-Class-Schema-Loader/current/Changes	2010-01-02 16:12:37 UTC (rev 8223)
@@ -1,7 +1,7 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
-        - exclude 'size' column_info for postgres when unnecessary, correct
-          datetime_precision in 'size' for time|timestamp|interval types
+        - exclude 'size' column_info for postgres when unnecessary, and
+          use the correct precision for varying types (except NUMERIC)
         - 'naming' attribute and backward compatibility with 0.04006
           (in progress)
 	- added relationship_attrs option for setting attributes in

Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm	2010-01-02 15:35:39 UTC (rev 8222)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm	2010-01-02 16:12:37 UTC (rev 8223)
@@ -123,7 +123,7 @@
 }
 
 # Make sure data_type's that don't need it don't have a 'size' column_info, and
-# set the correct precision for datetime types.
+# set the correct precision for datetime and varbit types.
 sub _columns_info_for {
     my $self = shift;
     my ($table) = @_;
@@ -138,9 +138,8 @@
 /^(?:bigint|int8|bigserial|serial8|bit|boolean|bool|box|bytea|cidr|circle|date|double precision|float8|inet|integer|int|int4|line|lseg|macaddr|money|path|point|polygon|real|float4|smallint|int2|serial|serial4|text)\z/i) {
             delete $result->{$col}{size};
         }
-
-        # for datetime types, check if it has a precision or not
-        if ($data_type =~ /^(?:interval|time|timestamp)\b/) {
+# for datetime types, check if it has a precision or not
+        elsif ($data_type =~ /^(?:interval|time|timestamp)\b/) {
             my ($precision) = $self->schema->storage->dbh
                 ->selectrow_array(<<EOF, {}, $table, $col);
 SELECT datetime_precision
@@ -155,6 +154,16 @@
                 $result->{$col}{size} = $precision;
             }
         }
+        elsif ($data_type =~ /^(?:bit varying|varbit)\z/i) {
+            my ($precision) = $self->schema->storage->dbh
+                ->selectrow_array(<<EOF, {}, $table, $col);
+SELECT character_maximum_length
+FROM information_schema.columns
+WHERE table_name = ? and column_name = ?
+EOF
+
+            $result->{$col}{size} = $precision;
+        }
     }
 
     return $result;

Modified: branches/DBIx-Class-Schema-Loader/current/t/12pg_common.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/12pg_common.t	2010-01-02 15:35:39 UTC (rev 8222)
+++ branches/DBIx-Class-Schema-Loader/current/t/12pg_common.t	2010-01-02 16:12:37 UTC (rev 8223)
@@ -38,7 +38,6 @@
                     a_bigserial BIGSERIAL,
                     a_serial8 SERIAL8,
                     a_bit BIT,
-                    a_bit_varying_with_precision BIT VARYING(8),
                     a_boolean BOOLEAN,
                     a_bool BOOL,
                     a_box BOX,
@@ -79,12 +78,20 @@
                     a_timestamp_without_time_zone TIMESTAMP WITHOUT TIME ZONE,
                     a_timestamp_without_time_zone_with_precision TIMESTAMP(2) WITHOUT TIME ZONE,
                     a_timestamp_with_time_zone TIMESTAMP WITH TIME ZONE,
-                    a_timestamp_with_time_zone_with_precision TIMESTAMP(2) WITH TIME ZONE
+                    a_timestamp_with_time_zone_with_precision TIMESTAMP(2) WITH TIME ZONE,
+                    a_bit_varying_with_precision BIT VARYING(2),
+                    a_varbit_with_precision VARBIT(2),
+                    a_character_varying_with_precision CHARACTER VARYING(2),
+                    a_varchar_with_precision VARCHAR(2),
+                    a_character_with_precision CHARACTER(2),
+                    a_char_with_precision CHAR(2)
                 )
             },
+# XXX figure out what to do with DECIMAL(precision, scale) aka
+# NUMERIC(precision, scale)
         ],
         drop  => [ qw/ pg_loader_test1 pg_loader_test2 / ],
-        count => 49,
+        count => 54,
         run   => sub {
             my ($schema, $monikers, $classes) = @_;
 
@@ -103,7 +110,7 @@
                 'column comment and attrs';
 
             my $rsrc = $schema->resultset('PgLoaderTest2')->result_source;
-            my @type_columns = grep !/^id\z/, $rsrc->columns;
+            my @type_columns = grep $_ ne 'id', $rsrc->columns;
             my @without_precision = grep !/_with_precision\z/, @type_columns;
             my @with_precision    = grep  /_with_precision\z/, @type_columns;
             my %with_precision;
@@ -124,9 +131,10 @@
             for my $col (@with_precision) {
                 my ($data_type) = $col =~ /^an?_(.*)_with_precision\z/;
                 ($data_type = uc $data_type) =~ s/_/ /g;
+                my $size = $rsrc->column_info($col)->{size};
 
-                ok($rsrc->column_info($col)->{size},
-                    "$data_type with precision has a 'size' column_info");
+                is $size, 2,
+                  "$data_type with precision has a correct 'size' column_info";
             }
         },
     },




More information about the Bast-commits mailing list