From bcb8dfd42f14a8fd0a6507d26abec2c8d898a4e8 Mon Sep 17 00:00:00 2001 From: Marc Cousin Date: Sun, 4 Feb 2018 18:16:32 +0100 Subject: [PATCH 1/2] create table_constraint_checksum function for pg_tapgen --- sql/pgtap.sql.in | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sql/pgtap.sql.in b/sql/pgtap.sql.in index 784a44c5b..d1ba83bce 100644 --- a/sql/pgtap.sql.in +++ b/sql/pgtap.sql.in @@ -2376,6 +2376,17 @@ RETURNS TEXT AS $$ SELECT col_has_check( $1, $2, 'Column ' || quote_ident($1) || '(' || quote_ident($2) || ') should have a check constraint' ); $$ LANGUAGE sql; +-- table_constraint_checksum ( schema, table, conname, contype, checksum, description) +CREATE OR REPLACE FUNCTION table_constraint_checksum (NAME, NAME, NAME, char, text, text) +RETURNS TEXT AS $$ + SELECT is(md5 ( pg_get_constraintdef(oid)), $5, $6) + FROM pg_constraint + WHERE connamespace=(SELECT oid FROM pg_namespace WHERE nspname=$1) + AND conrelid=$2::regclass + AND conname=$3 + AND contype=$4; +$$ LANGUAGE sql; + -- fk_ok( fk_schema, fk_table, fk_column[], pk_schema, pk_table, pk_column[], description ) CREATE OR REPLACE FUNCTION fk_ok ( NAME, NAME, NAME[], NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ From ca2318b099204f9704f2e286d074b27553dad51a Mon Sep 17 00:00:00 2001 From: Marc Cousin Date: Tue, 6 Feb 2018 16:25:10 +0100 Subject: [PATCH 2/2] Add doc for table_constraint_checksum --- doc/pgtap.mmd | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/doc/pgtap.mmd b/doc/pgtap.mmd index e348b63f0..33cc83961 100644 --- a/doc/pgtap.mmd +++ b/doc/pgtap.mmd @@ -4671,6 +4671,32 @@ that do have check constraints, if any: Just like `col_is_pk()`, except that it test that the column or array of columns have a check constraint on them. +### `table_constraint_checksum` ### + + SELECT table_constraint_checksum ( :schema, :table, :conname, :contype, :checksum, :description); + +**Parameters** + +`:schema` +: Schema of the table owning the constraint. + +`:table` +: Name of the table owning the constraint. + +`:conname` +: Name of the constraint itself. + +`:contype` +: Type of the constraint: c = check constraint, f = foreign key constraint, +p = primary key constraint, u = unique constraint, t = constraint trigger, +x = exclusion constraint. + +`:checksum` +: Checksum of the constraint. Generated with md5(pg_get_constraintdef(oid)) from pg_constraint. + +`:description` +: A short description of the test. + ### `index_is_unique()` ### SELECT index_is_unique( :schema, :table, :index, :description );