Skip to content
Browse files

Foreign key table must be visible if no schema specified.

  • Loading branch information...
1 parent 446980b commit 0b040efb8e4f6dde79f87208ab4d0b50e29d8b2f @theory committed Jan 21, 2013
Showing with 30 additions and 2 deletions.
  1. +27 −0 sql/pgtap--0.92.0--0.93.0.sql
  2. +3 −2 sql/pgtap.sql.in
View
27 sql/pgtap--0.92.0--0.93.0.sql
@@ -79,3 +79,30 @@ BEGIN
);
END;
$$ LANGUAGE plpgsql;
+
+-- fk_ok( fk_table, fk_column[], pk_table, pk_column[], description )
+CREATE OR REPLACE FUNCTION fk_ok ( NAME, NAME[], NAME, NAME[], TEXT )
+RETURNS TEXT AS $$
+DECLARE
+ tab name;
+ cols name[];
+BEGIN
+ SELECT pk_table_name, pk_columns
+ FROM pg_all_foreign_keys
+ WHERE fk_table_name = $1
+ AND fk_columns = $2
+ AND pg_catalog.pg_table_is_visible(fk_table_oid)
+ INTO tab, cols;
+
+ RETURN is(
+ -- have
+ $1 || '(' || _ident_array_to_string( $2, ', ' )
+ || ') REFERENCES ' || COALESCE( tab || '(' || _ident_array_to_string( cols, ', ' ) || ')', 'NOTHING'),
+ -- want
+ $1 || '(' || _ident_array_to_string( $2, ', ' )
+ || ') REFERENCES ' ||
+ $3 || '(' || _ident_array_to_string( $4, ', ' ) || ')',
+ $5
+ );
+END;
+$$ LANGUAGE plpgsql;
View
5 sql/pgtap.sql.in
@@ -2251,8 +2251,9 @@ DECLARE
BEGIN
SELECT pk_table_name, pk_columns
FROM pg_all_foreign_keys
- WHERE fk_table_name = $1
- AND fk_columns = $2
+ WHERE fk_table_name = $1
+ AND fk_columns = $2
+ AND pg_catalog.pg_table_is_visible(fk_table_oid)
INTO tab, cols;
RETURN is(

0 comments on commit 0b040ef

Please sign in to comment.
Something went wrong with that request. Please try again.