use base 'DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault';
use mro 'c3';
-our $VERSION = '0.07020';
+our $VERSION = '0.07035';
=head1 NAME
return ($self->next::method(@_), 'pg_catalog');
}
+my %pg_rules = (
+ a => 'NO ACTION',
+ r => 'RESTRICT',
+ c => 'CASCADE,',
+ n => 'SET NULL',
+ d => 'SET DEFAULT',
+);
+
+sub _table_fk_info {
+ my ($self, $table) = @_;
+
+ my $sth = $self->dbh->prepare_cached(<<"EOF");
+select q.constr_name, q.to_schema, q.to_table, from_cols.attname from_col, to_cols.attname to_col,
+ q.on_delete, q.on_update, q.is_deferrable
+from (select constr.conname constr_name, to_ns.nspname to_schema, to_class.relname to_table,
+ unnest(constr.conkey) from_colnum, unnest(constr.confkey) to_colnum,
+ constr.confdeltype on_delete, constr.confupdtype on_update,
+ constr.condeferrable is_deferrable,
+ constr.conrelid conrelid, constr.confrelid confrelid
+ from pg_constraint constr
+ join pg_namespace from_ns on constr.connamespace = from_ns.oid
+ join pg_class from_class on constr.conrelid = from_class.oid and from_class.relnamespace = from_ns.oid
+ join pg_class to_class on constr.confrelid = to_class.oid
+ join pg_namespace to_ns on to_class.relnamespace = to_ns.oid
+ where from_ns.nspname = ?
+ and from_class.relname = ?
+ and from_class.relkind = 'r'
+ and constr.contype = 'f'
+) q
+join pg_attribute from_cols on from_cols.attrelid = q.conrelid and from_cols.attnum = q.from_colnum
+join pg_attribute to_cols on to_cols.attrelid = q.confrelid and to_cols.attnum = q.to_colnum;
+EOF
+
+ $sth->execute($table->schema, $table->name);
+
+ my %rels;
+
+ while (my ($fk, $remote_schema, $remote_table, $col, $remote_col,
+ $delete_rule, $update_rule, $is_deferrable) = $sth->fetchrow_array) {
+ push @{ $rels{$fk}{local_columns} }, $self->_lc($col);
+ push @{ $rels{$fk}{remote_columns} }, $self->_lc($remote_col);
+
+ $rels{$fk}{remote_table} = DBIx::Class::Schema::Loader::Table->new(
+ loader => $self,
+ name => $remote_table,
+ schema => $remote_schema,
+ ) unless exists $rels{$fk}{remote_table};
+
+ $rels{$fk}{attrs} ||= {
+ on_delete => $pg_rules{$delete_rule},
+ on_update => $pg_rules{$update_rule},
+ is_deferrable => $is_deferrable,
+ };
+ }
+
+ return [ values %rels ];
+}
+
+
sub _table_uniq_info {
my ($self, $table) = @_;
return $table_comment if $table_comment;
($table_comment) = $self->dbh->selectrow_array(<<'EOF', {}, $table->name, $table->schema);
-SELECT obj_description(oid)
-FROM pg_class
+SELECT obj_description(oid)
+FROM pg_class
WHERE relname=? AND relnamespace=(SELECT oid FROM pg_namespace WHERE nspname=?)
EOF
my ($table_oid) = $self->dbh->selectrow_array(<<'EOF', {}, $table->name, $table->schema);
SELECT oid
-FROM pg_class
+FROM pg_class
WHERE relname=? AND relnamespace=(SELECT oid FROM pg_namespace WHERE nspname=?)
EOF
$info->{extra}{custom_type_name} = $info->{data_type};
$info->{data_type} = 'enum';
-
+
delete $info->{size};
}
}