Skip to content

pg-delta: order RLS policies after referenced new tables #184

@avallete

Description

@avallete

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

  1. Add a regression test that creates two new tables and a policy on one table whose USING/WITH CHECK references the other.
  2. Prefer extending dependency extraction so policies depend on newly created tables referenced in those expressions.
  3. 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.

Metadata

Metadata

Labels

🐛 BugDefects, regressions, or unintended behavior that need fixing

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions