1 package DBIx::Class::Schema::Loader::DBI::Pg;
5 use base 'DBIx::Class::Schema::Loader::DBI';
10 DBIx::Class::Schema::Loader::DBI::Pg - DBIx::Class::Schema::Loader::DBI Postgres Implementation.
15 use base qw/DBIx::Class::Schema::Loader/;
17 __PACKAGE__->loader_options(
25 See L<DBIx::Class::Schema::Loader::Base>.
32 $self->next::method(@_);
33 $self->{db_schema} ||= 'public';
36 sub _table_uniq_info {
37 my ($self, $table) = @_;
40 my $dbh = $self->schema->storage->dbh;
42 # Most of the SQL here is mostly based on
43 # Rose::DB::Object::Metadata::Auto::Pg, after some prodding from
44 # John Siracusa to use his superior SQL code :)
46 my $attr_sth = $self->{_cache}->{pg_attr_sth} ||= $dbh->prepare(
47 q{SELECT attname FROM pg_catalog.pg_attribute
48 WHERE attrelid = ? AND attnum = ?}
51 my $uniq_sth = $self->{_cache}->{pg_uniq_sth} ||= $dbh->prepare(
52 q{SELECT x.indrelid, i.relname, x.indkey
55 JOIN pg_catalog.pg_class c ON c.oid = x.indrelid
56 JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
57 JOIN pg_catalog.pg_constraint con ON con.conname = i.relname
58 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
60 x.indisunique = 't' AND
68 $uniq_sth->execute($self->db_schema, $table);
69 while(my $row = $uniq_sth->fetchrow_arrayref) {
70 my ($tableid, $indexname, $col_nums) = @$row;
71 $col_nums =~ s/^\s+//;
72 my @col_nums = split(/\s+/, $col_nums);
76 $attr_sth->execute($tableid, $_);
77 my $name_aref = $attr_sth->fetchrow_arrayref;
78 push(@col_names, $name_aref->[0]) if $name_aref;
82 warn "Failed to parse unique constraint $indexname on $table";
85 push(@uniqs, [ $indexname => \@col_names ]);
94 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
95 L<DBIx::Class::Schema::Loader::DBI>