pgschema
pgschema copied to clipboard
pgSchema generates invalid WITH CHECK ; when removing an explicit RLS WITH CHECK clause
When changing a PostgreSQL RLS policy from an explicit WITH CHECK expression to an implicit one, pgSchema generates invalid SQL with check ;.
pgSchema version 1.12.3
Existing database schema
create policy agents_app_tenant on backend.agents for all to backend_app using (
organization_id = (select nullif(current_setting('app.current_organization_id', true)'')::uuid))
with check (
organization_id = (select nullif(current_setting('app.current_organization_id', true)'')::uuid)
);
Desired schema
create policy agents_app_tenant on backend.agents for all to backend_app using (
organization_id = (select backend.current_organization_id()));
Generated migration
alter policy agents_app_tenant on agents using (
organization_id = (select current_organization_id()))
with check ;
This is invalid PostgreSQL syntax because WITH CHECK requires a parenthesized expression.
Expected behaviour
Because PostgreSQL does not appear to support clearing an existing policy’s explicit WITH CHECK expression through ALTER POLICY, pgSchema could drop and recreate the policy.