Problem
When planning or applying declarative changes, an RLS policy on one new table can reference another new table inside USING or WITH CHECK. If pg-delta emits CREATE POLICY before the referenced table exists, plan/apply fails on an empty database.
Current gaps
- Integration coverage appears to focus on self-table policies and simpler create-table-plus-policy cases, not policies whose expressions reference another newly created table.
- Dependency / sort logic does not obviously treat "policy expression references table X" as an ordering edge, so cross-table references may not influence plan order.
Suggested direction
- Add a regression test that creates two new tables and a policy on one table whose
USING/WITH CHECK references the other.
- Prefer extending dependency extraction so policies depend on newly created tables referenced in those expressions.
- If expression-based edges are not practical in the short term, add a narrow deferral step for policy creation after referenced new relations exist.
Success criteria
- The failing case is covered by integration tests.
- Plan/apply produces a valid order for cross-table policy references on a fresh database.
Problem
When planning or applying declarative changes, an RLS policy on one new table can reference another new table inside
USINGorWITH CHECK. If pg-delta emitsCREATE POLICYbefore the referenced table exists, plan/apply fails on an empty database.Current gaps
Suggested direction
USING/WITH CHECKreferences the other.Success criteria