Permalink
Browse files

Make sure tables are visible when testing FKs.

  • Loading branch information...
theory committed Jan 25, 2013
1 parent f6fb778 commit 979651f7a833dd7e83eb3f32e16ef8f788548469
Showing with 15 additions and 2 deletions.
  1. +3 −2 Changes
  2. +11 −0 sql/pgtap--0.92.0--0.93.0.sql
  3. +1 −0 sql/pgtap.sql.in
View
@@ -7,8 +7,9 @@ Revision history for pgTAP
* Fixed misselling of "constraint" in constraint test diagnostic output.
* Fixed `fk_ok()` so that the table must be visible in the search path when
the schema name is not specified.
-* Fixed constraint- and trigger-checking functions so that they only look at
- tables visible in the search path unles the schema is specified.
+* Fixed constraint, trigger, and foreign key-checking functions so that they
+ only look at tables visible in the search path unles the schema is
+ specified.
* Fixed `col_type_is()` so that it won't report the column as not existing
when the column's data type is not in the search path.
@@ -141,3 +141,14 @@ RETURNS TEXT AS $$
AND attnum > 0
AND NOT a.attisdropped
$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION _fkexists ( NAME, NAME[] )
+RETURNS BOOLEAN AS $$
+ SELECT EXISTS(
+ SELECT TRUE
+ FROM pg_all_foreign_keys
+ WHERE quote_ident(fk_table_name) = quote_ident($1)
+ AND pg_catalog.pg_table_is_visible(fk_table_oid)
+ AND fk_columns = $2
+ );
+$$ LANGUAGE SQL;
View
@@ -1929,6 +1929,7 @@ RETURNS BOOLEAN AS $$
SELECT TRUE
FROM pg_all_foreign_keys
WHERE quote_ident(fk_table_name) = quote_ident($1)
+ AND pg_catalog.pg_table_is_visible(fk_table_oid)
AND fk_columns = $2
);
$$ LANGUAGE SQL;

0 comments on commit 979651f

Please sign in to comment.