release 0.07025
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBI / Pg.pm
index c16231a..9952425 100644 (file)
@@ -2,13 +2,10 @@ package DBIx::Class::Schema::Loader::DBI::Pg;
 
 use strict;
 use warnings;
-use base qw/
-    DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault
-    DBIx::Class::Schema::Loader::DBI
-/;
+use base 'DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault';
 use mro 'c3';
 
-our $VERSION = '0.07010';
+our $VERSION = '0.07025';
 
 =head1 NAME
 
@@ -78,7 +75,7 @@ sub _table_uniq_info {
           c.relname     = ?}
     );
 
-    $uniq_sth->execute($table->schema, $table);
+    $uniq_sth->execute($table->schema, $table->name);
     while(my $row = $uniq_sth->fetchrow_arrayref) {
         my ($tableid, $indexname, $col_nums) = @$row;
         $col_nums =~ s/^\s+//;
@@ -88,7 +85,7 @@ sub _table_uniq_info {
         foreach (@col_nums) {
             $attr_sth->execute($tableid, $_);
             my $name_aref = $attr_sth->fetchrow_arrayref;
-            push(@col_names, $name_aref->[0]) if $name_aref;
+            push(@col_names, $self->_lc($name_aref->[0])) if $name_aref;
         }
 
         if(!@col_names) {
@@ -151,7 +148,7 @@ sub _columns_info_for {
         # these types are fixed size
         # XXX should this be a negative match?
         if ($data_type =~
-/^(?:bigint|int8|bigserial|serial8|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) {
+/^(?:bigint|int8|bigserial|serial8|bool(?:ean)?|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 $info->{size};
         }
 # for datetime types, check if it has a precision or not
@@ -164,7 +161,7 @@ sub _columns_info_for {
             }
 
             my ($precision) = $self->schema->storage->dbh
-                ->selectrow_array(<<EOF, {}, $table, $col);
+                ->selectrow_array(<<EOF, {}, $table->name, $col);
 SELECT datetime_precision
 FROM information_schema.columns
 WHERE table_name = ? and column_name = ?
@@ -199,7 +196,7 @@ EOF
         elsif ($data_type =~ /^(?:bit(?: varying)?|varbit)\z/i) {
             $info->{data_type} = 'varbit' if $data_type =~ /var/i;
 
-            my ($precision) = $self->dbh->selectrow_array(<<EOF, {}, $table, $col);
+            my ($precision) = $self->dbh->selectrow_array(<<EOF, {}, $table->name, $col);
 SELECT character_maximum_length
 FROM information_schema.columns
 WHERE table_name = ? and column_name = ?
@@ -272,6 +269,18 @@ EOF
             my $now = 'now()';
             $info->{original}{default_value} = \$now;
         }
+
+# detect 0/1 for booleans and rewrite
+        if ($data_type =~ /^bool/i && exists $info->{default_value}) {
+            if ($info->{default_value} eq '0') {
+                my $false = 'false';
+                $info->{default_value} = \$false;
+            }
+            elsif ($info->{default_value} eq '1') {
+                my $true = 'true';
+                $info->{default_value} = \$true;
+            }
+        }
     }
 
     return $result;