X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FPg.pm;h=196cbdfb047654943ebe7c1daac4387d216e2fd3;hb=4e793de74348432fc7d185641bac24a47005e01e;hp=1910923e393f871681ea7d464e5093d775b1d59b;hpb=f80b0ea749d599898951efc034141d26237a926e;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index 1910923..196cbdf 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -7,9 +7,9 @@ use base qw/ DBIx::Class::Schema::Loader::DBI /; use Carp::Clan qw/^DBIx::Class/; -use Class::C3; +use mro 'c3'; -our $VERSION = '0.07000'; +our $VERSION = '0.07004'; =head1 NAME @@ -41,6 +41,10 @@ sub _setup { if (not defined $self->preserve_case) { $self->preserve_case(0); } + elsif ($self->preserve_case) { + $self->schema->storage->sql_maker->quote_char('"'); + $self->schema->storage->sql_maker->name_sep('.'); + } } sub _table_uniq_info { @@ -141,6 +145,7 @@ sub _columns_info_for { my $data_type = $info->{data_type}; # 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) { delete $info->{size}; @@ -150,6 +155,9 @@ sub _columns_info_for { if (lc($data_type) eq 'timestamp without time zone') { $info->{data_type} = 'timestamp'; } + elsif (lc($data_type) eq 'time without time zone') { + $info->{data_type} = 'time'; + } my ($precision) = $self->schema->storage->dbh ->selectrow_array(<{data_type} = 'varchar'; - $info->{data_type} = 'text' if not $info->{size}; + if (not $info->{size}) { + $info->{data_type} = 'text'; + $info->{original}{data_type} = 'varchar'; + } } elsif (lc($data_type) eq 'character') { $info->{data_type} = 'char'; } + else { + my ($typetype) = $self->schema->storage->dbh + ->selectrow_array(<schema->storage->dbh + ->selectall_arrayref(<{data_type}); +SELECT e.enumlabel +FROM pg_catalog.pg_enum e +JOIN pg_catalog.pg_type t ON t.oid = e.enumtypid +WHERE t.typname = ? +EOF + + $info->{extra}{list} = [ map { $_->[0] } @$typevalues ]; + + # Store its original name in extra for SQLT to pick up. + $info->{extra}{custom_type_name} = $info->{data_type}; + + $info->{data_type} = 'enum'; + + delete $info->{size}; + } + } # process SERIAL columns - if (ref($info->{default_value}) eq 'SCALAR' && ${ $info->{default_value} } =~ /\bnextval\(['"](\w+)/i) { + if (ref($info->{default_value}) eq 'SCALAR' && ${ $info->{default_value} } =~ /\bnextval\(['"]([.\w]+)/i) { $info->{is_auto_increment} = 1; $info->{sequence} = $1; delete $info->{default_value}; } # alias now() to current_timestamp for deploying to other DBs - if (eval { lc ${ $info->{default_value} }||'' eq 'now()' }) { + if ((eval { lc ${ $info->{default_value} } }||'') eq 'now()') { # do not use a ref to a constant, that breaks Data::Dump output ${$info->{default_value}} = 'current_timestamp'; + + my $now = 'now()'; + $info->{original}{default_value} = \$now; } }