pgtap icon indicating copy to clipboard operation
pgtap copied to clipboard

Feature Request: has_rls_enabled, hasnt_rls_enabled

Open madflow opened this issue 5 years ago • 0 comments

Feature Request: has_rls_enabled, hasnt_rls_enabled

Tests whether or not a table has row level security (RLS) enabled.

has_rls_enabled()

SELECT has_rls_enabled( :schema, :table, :description );
SELECT has_rls_enabled( :table, :description );
SELECT has_rls_enabled( :table );

hasnt_rls_enabled()

SELECT hasnt_rls_enabled( :schema, :table, :description );
SELECT hasnt_rls_enabled( :table, :description );
SELECT hasnt_rls_enabled( :table );

Parameters

  • :schema Schema in which to find the table.
  • :table Name of a table containing the check constraint.
  • :description A short description of the test.

Quick and dirty SQL:

SELECT
c.relrowsecurity as "has_rls_enabled"
FROM pg_catalog.pg_class c
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r')
AND n.nspname = 'schemaname'
AND c.relname = 'tablename'
AND pg_catalog.pg_table_is_visible(c.oid);

madflow avatar Mar 13 '20 14:03 madflow