-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
checks for comments, exclusion constraints, array set_eq, and rls #306
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2418,6 +2418,18 @@ RETURNS TEXT AS $$ | |
SELECT col_has_check( $1, $2, 'Column ' || quote_ident($1) || '(' || quote_ident($2) || ') should have a check constraint' ); | ||
$$ LANGUAGE sql; | ||
|
||
-- col_has_exclusion(schema, table, columns, description) | ||
CREATE OR REPLACE FUNCTION col_has_exclusion(TEXT, TEXT, TEXT[], TEXT) | ||
RETURNS TEXT AS $$ | ||
SELECT ok(array_agg(attr.attname)::TEXT[] @> $3 AND $3 @> array_agg(attr.attname)::TEXT[]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the |
||
FROM pg_constraint AS con | ||
JOIN LATERAL unnest(con.conkey) AS attnums (num) ON TRUE | ||
JOIN pg_attribute AS attr ON attr.attrelid = con.conrelid | ||
AND attr.attnum = attnums.num | ||
WHERE conrelid = format('%1$I.%2$I', $1, $2)::regclass | ||
AND contype = 'x'; | ||
$$ 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 $$ | ||
|
@@ -6840,6 +6852,15 @@ RETURNS TEXT AS $$ | |
); | ||
$$ LANGUAGE sql; | ||
|
||
CREATE OR REPLACE FUNCTION _relcomp( anyarray, anyarray, TEXT, TEXT ) | ||
RETURNS TEXT AS $$ | ||
SELECT _docomp( | ||
_temptable( $1, '__taphave__' ), | ||
_temptable( $2, '__tapwant__' ), | ||
$3, $4 | ||
); | ||
$$ LANGUAGE sql; | ||
|
||
-- set_eq( sql, sql, description ) | ||
CREATE OR REPLACE FUNCTION set_eq( TEXT, TEXT, TEXT ) | ||
RETURNS TEXT AS $$ | ||
|
@@ -6864,6 +6885,18 @@ RETURNS TEXT AS $$ | |
SELECT _relcomp( $1, $2, NULL::text, '' ); | ||
$$ LANGUAGE sql; | ||
|
||
-- set_eq( array, array, description ) | ||
CREATE OR REPLACE FUNCTION set_eq(anyarray, anyarray, TEXT) | ||
RETURNS TEXT AS $$ | ||
SELECT _relcomp( $1, $2, $3, '' ); | ||
$$ LANGUAGE sql; | ||
|
||
-- set_eq( array, array ) | ||
CREATE OR REPLACE FUNCTION set_eq(anyarray, anyarray) | ||
RETURNS TEXT AS $$ | ||
SELECT _relcomp( $1, $2, NULL::text, '' ) | ||
$$ LANGUAGE sql; | ||
|
||
-- bag_eq( sql, sql, description ) | ||
CREATE OR REPLACE FUNCTION bag_eq( TEXT, TEXT, TEXT ) | ||
RETURNS TEXT AS $$ | ||
|
@@ -11366,3 +11399,65 @@ RETURNS TEXT AS $$ | |
'Function ' || quote_ident($1) || '() should not be a procedure' | ||
); | ||
$$ LANGUAGE sql; | ||
|
||
-- table_comment_has(schema, table, comment, description) | ||
CREATE OR REPLACE FUNCTION table_comment_has(TEXT, TEXT, TEXT, TEXT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WE use |
||
RETURNS TEXT AS $$ | ||
SELECT ok(COUNT(*) >= 1, $4) | ||
FROM pg_description | ||
JOIN LATERAL regexp_split_to_table(description, '\n') AS lines (line) ON TRUE | ||
WHERE objoid = format('%1$I.%2$I', $1, $2)::regclass | ||
AND objsubid = 0 | ||
AND trim(line) ILIKE $3 | ||
$$ LANGUAGE sql; | ||
|
||
-- table_comment_has(schema, table, comment) | ||
CREATE OR REPLACE FUNCTION table_comment_has(TEXT, TEXT, TEXT) | ||
RETURNS TEXT AS $$ | ||
SELECT table_comment_has($1, $2, $3, 'table comment contains expected line'); | ||
$$ LANGUAGE sql; | ||
|
||
-- column_comment_has(schema, table, column, comment, description) | ||
CREATE OR REPLACE FUNCTION column_comment_has(TEXT, TEXT, TEXT, TEXT, TEXT) | ||
RETURNS TEXT AS $$ | ||
SELECT ok(COUNT(*) >= 1, $5) | ||
FROM pg_description | ||
JOIN pg_attribute AS attr | ||
ON attr.attrelid = pg_description.objoid | ||
AND attr.attnum = pg_description.objsubid | ||
JOIN LATERAL regexp_split_to_table(description, '\n') AS lines (line) ON TRUE | ||
WHERE objoid = format('%1$I.%2$I', $1, $2)::regclass | ||
AND attr.attname = $3::name | ||
AND trim(line) ILIKE $4 | ||
$$ LANGUAGE sql; | ||
|
||
-- column_comment_has(schema, table, column, comment) | ||
CREATE OR REPLACE FUNCTION column_comment_has(TEXT, TEXT, TEXT, TEXT) | ||
RETURNS TEXT AS $$ | ||
SELECT column_comment_has($1, $2, $3, $4, 'column comment contains expected line'); | ||
$$ LANGUAGE sql; | ||
|
||
-- function_comment_has(schema, function, comment, description) | ||
CREATE OR REPLACE FUNCTION function_comment_has(TEXT, TEXT, TEXT, TEXT) | ||
RETURNS TEXT AS $$ | ||
SELECT ok(COUNT(*) >= 1, $4) | ||
FROM pg_description | ||
JOIN LATERAL regexp_split_to_table(description, '\n') AS lines (line) ON TRUE | ||
WHERE objoid = format('%1$I.%2$I', $1, $2)::regproc | ||
AND objsubid = 0 | ||
AND trim(line) ILIKE $3 | ||
$$ LANGUAGE sql; | ||
|
||
-- function_comment_has(schema, function, comment) | ||
CREATE OR REPLACE FUNCTION function_comment_has(TEXT, TEXT, TEXT) | ||
RETURNS TEXT AS $$ | ||
SELECT function_comment_has($1, $2, $3, 'function comment contains expected line'); | ||
$$ LANGUAGE sql; | ||
|
||
-- rls_is_enabled(schema, table, desired_value) | ||
CREATE OR REPLACE FUNCTION rls_is_enabled(TEXT, TEXT, BOOLEAN) | ||
RETURNS TEXT AS $$ | ||
SELECT ok(relrowsecurity IS NOT DISTINCT FROM $3) | ||
FROM pg_class | ||
WHERE oid = format('%1$I.%2$I', $1, $2)::regclass | ||
$$ LANGUAGE sql; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description should go after the parameters to be consistent with the existing docs. Same goes for some of the other documentation added here.