$table_or_view,
undef
);
+ handle_triggers(
+ $schema,
+ $table_or_view,
+ undef
+ );
}
handle_tables(
return $columns;
}
+sub fetch_triggers {
+ my ($schema,$table) = (shift,shift);
+ my $sth = $dbh->prepare("
+ SELECT DISTINCT
+ trigger_schema,
+ trigger_name,
+ event_object_schema,
+ event_object_table
+ FROM information_schema.triggers
+ WHERE event_object_catalog = ?
+ AND event_object_schema = ?
+ AND event_object_table = ?
+ AND trigger_schema = event_object_schema -- I don't think pgTAP can handle it otherwise
+ ");
+ $sth->execute(($db_name,$schema,$table));
+ my $triggers = $sth->fetchall_hashref('trigger_name');
+ $sth->finish;
+ return $triggers;
+}
+
sub handle_schemas {
my $callback = shift;
}
sub handle_columns {
- my ($schema,$table) = (shift,shift);
+ my ($schema,$table,$callback) = (shift,shift,shift);
my $columns = fetch_columns($schema,$table);
if (!%{ $columns }) {
return;
foreach my $column ( sort keys %{ $columns } ) {
+ $callback->($schema,$table,$column,undef) if $callback;
+
my $col_type_original = $columns->{$column}->{data_type};
my $col_type = $col_type_original;
my $col_nullable = $columns->{$column}->{is_nullable};
}
}
+sub handle_triggers {
+ my ($schema,$table,$callback) = (shift,shift,shift);
+ my $triggers = fetch_triggers($schema,$table);
+ if (!%{ $triggers }) {
+ return;
+ }
+
+ print "\n-- -- -- triggers on " . $dbh->quote("$schema.$table") . "\n";
+ print "SELECT triggers_are(\n";
+ print "\t" . $dbh->quote($schema) . ",\n";
+ print "\t" . $dbh->quote($table) . ",\n";
+ print "\tARRAY[\n\t\t";
+ print join(
+ ",\n\t\t",
+ map { $dbh->quote($_) } sort keys %{ $triggers }
+ );
+ print "\n\t],\t" . $dbh->quote("Found expected triggers for $schema.$table");
+ print "\n);\n";
+
+ foreach my $trigger ( sort keys %{ $triggers } ) {
+ $callback->($schema,$table,$trigger,undef) if $callback;
+ }
+
+}
+