Skip to content

Predicates added to an existing PostgreSQL table keep their parentheses and casts - #144

Merged
MelbourneDeveloper merged 3 commits into
mainfrom
fix/predicate-grouping-preserved
Nov 28, 2026
Merged

MelbourneDeveloper merged 3 commits into
mainfrom
fix/predicate-grouping-preserved

Conversation

@MelbourneDeveloper

Copy link
Copy Markdown
Collaborator

Adding a CHECK, partial-index predicate or RLS policy to a table that already exists rewrote the predicate before creating it. (a > 0 OR b > 0) AND c > 0 was created as a > 0 OR (b > 0 AND c > 0), (a + b) * c > 10 as a + (b * c) > 10, and (a::numeric / b) > 0.5 lost its cast, and the run still reported success. Regrouping a predicate in the YAML was also reported as up to date. v0.11.0-beta.1 rejected these predicates as drifted instead of installing the wrong one.

The canonical renderer now writes parentheses back wherever operator precedence would regroup the expression, and keeps every cast except the text/varchar/custom-type casts PostgreSQL adds itself. Migrate_PredicatesAddedToExistingTableKeepGroupingAndRegroupingIsApplied adds the three predicates to an existing table on real PostgreSQL, checks the catalog definitions, reruns clean, then regroups them and checks the change is applied.

Also here:

  • A YAML that declares only roles was rejected with "supports exactly one target schema; found:". It now migrates against public (Migrate_RolesOnlySchemaMigratesAndRerunsClean).
  • Removes an unused debug variable from the index inspector.

Not changed: custom-type casts (enums, domains) are still stripped from the canonical form, as before.

@MelbourneDeveloper
MelbourneDeveloper merged commit 12a147c into main Nov 28, 2026
11 checks passed
@MelbourneDeveloper
MelbourneDeveloper deleted the fix/predicate-grouping-preserved branch November 28, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant