pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Perpetual policy diffs: table references not normalized

Open asonawalla opened this issue 10 months ago • 0 comments

Summary

Following the fix in PR #222 for function qualifier normalization (issue #220), we're still seeing perpetual diffs when policy expressions reference tables with same-schema qualifiers.

Context

PR #222 correctly normalizes function calls like public.auth_uid() → auth_uid(). However, the same issue exists for table references within policy expressions.

Reproduction

Schema file contains:

CREATE POLICY "Select own orders" ON orders
FOR SELECT TO authenticated
USING (user_id IN (
    SELECT u.id
    FROM users u  -- no public. prefix
    WHERE u.tenant_id = (SELECT public.current_tenant_id())
));

pgschema generates DDL with:

FROM public.users u  -- adds public. prefix

But PostgreSQL's pg_get_expr() returns:

FROM users u  -- no public. prefix

This creates a perpetual diff where pgschema always wants to ALTER the policy.

Expected Behavior

Table references within policy expressions should be normalized the same way function calls are in PR #222—strip same-schema qualifiers during comparison.

Related

  • Issue #220 (function qualifiers in policies)
  • PR #222 (fix for #220)
  • Issue #218 (schema qualifiers in column defaults)

asonawalla avatar Jan 04 '26 17:01 asonawalla