X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FPg.pm;h=4bb5d235f3381fe44fc56ce0e2dc4c7ca3648ff6;hb=e4be49c99edfa51b5dee57848ab589fa9bff38a2;hp=f5eefbb55e7b8761f340b618df42720b82438f2f;hpb=6b1d4f76b756e4b4119153a1f1e8a7bd59ad4e87;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 f5eefbb..4bb5d23 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -6,28 +6,19 @@ use base qw/ DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault DBIx::Class::Schema::Loader::DBI /; -use Carp::Clan qw/^DBIx::Class/; -use Class::C3; +use mro 'c3'; +use DBIx::Class::Schema::Loader::Table (); -our $VERSION = '0.07001'; +our $VERSION = '0.07010'; =head1 NAME DBIx::Class::Schema::Loader::DBI::Pg - DBIx::Class::Schema::Loader::DBI PostgreSQL Implementation. -=head1 SYNOPSIS - - package My::Schema; - use base qw/DBIx::Class::Schema::Loader/; - - __PACKAGE__->loader_options( debug => 1 ); - - 1; - =head1 DESCRIPTION -See L. +See L and L. =cut @@ -36,7 +27,7 @@ sub _setup { $self->next::method(@_); - $self->{db_schema} ||= 'public'; + $self->{db_schema} ||= ['public']; if (not defined $self->preserve_case) { $self->preserve_case(0); @@ -47,6 +38,38 @@ sub _setup { } } +sub _tables_list { + my ($self, $opts) = @_; + + my $dbh = $self->schema->storage->dbh; + + my @tables; + + foreach my $schema (@{ $self->db_schema }) { + my @raw_tables = $dbh->tables(undef, $schema, '%', '%'); + + foreach my $table_name (@raw_tables) { + my $schema_quoted = $table_name =~ /^"/; + + if ($schema_quoted) { + $table_name =~ s/^"([^"]+)"\.//; + } + else { + $table_name =~ s/^([^.]+)\.//; + } + my $table = DBIx::Class::Schema::Loader::Table->new(schema => $1); + + $table_name =~ s/^"([^"]+)"\z/$1/; + + $table->name($table_name); + + push @tables, $table; + } + } + + return $self->_filter_tables(\@tables, $opts); +} + sub _table_uniq_info { my ($self, $table) = @_; @@ -83,7 +106,7 @@ sub _table_uniq_info { c.relname = ?} ); - $uniq_sth->execute($self->db_schema, $table); + $uniq_sth->execute($table->schema, $table); while(my $row = $uniq_sth->fetchrow_arrayref) { my ($tableid, $indexname, $col_nums) = @$row; $col_nums =~ s/^\s+//; @@ -114,7 +137,7 @@ sub _table_comment { FROM pg_class WHERE relname=? AND relnamespace=( SELECT oid FROM pg_namespace WHERE nspname=?) - }, undef, $table, $self->db_schema + }, undef, $table, $table->schema ); return $table_comment } @@ -127,7 +150,7 @@ sub _column_comment { FROM pg_class WHERE relname=? AND relnamespace=( SELECT oid FROM pg_namespace WHERE nspname=?) - }, undef, $table, $self->db_schema + }, undef, $table, $table->schema ); return $self->schema->storage->dbh->selectrow_array('SELECT col_description(?,?)', undef, $table_oid, $column_number ); @@ -224,9 +247,38 @@ EOF 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\('([^:]+)'/i) { $info->{is_auto_increment} = 1; $info->{sequence} = $1; delete $info->{default_value};