pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

pgSchema generates invalid WITH CHECK ; when removing an explicit RLS WITH CHECK clause

Open leonzaher opened this issue 3 months ago • 0 comments

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.

leonzaher avatar Aug 18 '26 11:08 leonzaher