[Bast-commits] r8231 - 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
Sun Jan 3 21:23:37 GMT 2010


Author: caelum
Date: 2010-01-03 21:23:37 +0000 (Sun, 03 Jan 2010)
New Revision: 8231

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 NUMERIC/DECIMAL size for postgres

Modified: branches/DBIx-Class-Schema-Loader/current/Changes
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/Changes	2010-01-03 21:04:46 UTC (rev 8230)
+++ branches/DBIx-Class-Schema-Loader/current/Changes	2010-01-03 21:23:37 UTC (rev 8231)
@@ -1,5 +1,7 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
+        - fix NUMERIC/DECIMAL size column_info for postgres
+
 0.04999_13  2010-01-03 12:32:25
         - exclude 'size' column_info for postgres when unnecessary, and
           use the correct precision for varying types (except NUMERIC)

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-03 21:04:46 UTC (rev 8230)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm	2010-01-03 21:23:37 UTC (rev 8231)
@@ -164,6 +164,14 @@
 
             $result->{$col}{size} = $precision;
         }
+        elsif ($data_type =~ /^(?:numeric|decimal)\z/i) {
+            my $size = $result->{$col}{size};
+            $size =~ s/\s*//g;
+
+            my ($scale, $precision) = split /,/, $size;
+
+            $result->{$col}{size} = [ $precision, $scale ];
+        }
     }
 
     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-03 21:04:46 UTC (rev 8230)
+++ branches/DBIx-Class-Schema-Loader/current/t/12pg_common.t	2010-01-03 21:23:37 UTC (rev 8231)
@@ -29,7 +29,7 @@
                 COMMENT ON COLUMN pg_loader_test1.value IS 'The Column'
             },
             # Test to make sure data_types that don't need a size => don't
-            # have one.
+            # have one and check varying types have the correct size.
             q{
                 CREATE TABLE pg_loader_test2 (
                     id SERIAL NOT NULL PRIMARY KEY,
@@ -84,14 +84,16 @@
                     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)
+                    a_char_with_precision CHAR(2),
+                    the_numeric NUMERIC(6, 3),
+                    the_decimal DECIMAL(6, 3)
                 )
             },
 # XXX figure out what to do with DECIMAL(precision, scale) aka
 # NUMERIC(precision, scale)
         ],
         drop  => [ qw/ pg_loader_test1 pg_loader_test2 / ],
-        count => 54,
+        count => 56,
         run   => sub {
             my ($schema, $monikers, $classes) = @_;
 
@@ -110,7 +112,7 @@
                 'column comment and attrs';
 
             my $rsrc = $schema->resultset('PgLoaderTest2')->result_source;
-            my @type_columns = grep $_ ne 'id', $rsrc->columns;
+            my @type_columns = grep /^a/, $rsrc->columns;
             my @without_precision = grep !/_with_precision\z/, @type_columns;
             my @with_precision    = grep  /_with_precision\z/, @type_columns;
             my %with_precision;
@@ -136,6 +138,12 @@
                 is $size, 2,
                   "$data_type with precision has a correct 'size' column_info";
             }
+
+            is_deeply $rsrc->column_info('the_numeric')->{size}, [6,3],
+                'size for NUMERIC(precision, scale) is correct';
+
+            is_deeply $rsrc->column_info('the_decimal')->{size}, [6,3],
+                'size for DECIMAL(precision, scale) is correct';
         },
     },
 );




More information about the Bast-commits mailing list