Skip to content

PostgreSQL predicates are created exactly as declared - #145

Open
MelbourneDeveloper wants to merge 1 commit into
mainfrom
fix/predicate-ddl-from-declared-text
Open

MelbourneDeveloper wants to merge 1 commit into
mainfrom
fix/predicate-ddl-from-declared-text

Conversation

@MelbourneDeveloper

Copy link
Copy Markdown
Collaborator

A CHECK, partial-index predicate or RLS policy added to an existing table was created from the canonical comparison text instead of the declared text. That text drops ::text casts and spelled some operators as parser token names, so:

  • a::text < b::text was created as a < b (a different comparison) and the run reported success, for both CHECKs and RLS policies.
  • Policies using LIKE, ->>, ->, @> or & failed with a syntax error such as near "PGLikeMatch". These worked in v0.11.0-beta.1.

Now a declared predicate takes the canonical form only when the live object already has that exact canonical form, which is what makes the diff see no change. Every other predicate keeps its declared text, so DDL is always generated from what the YAML says. The renderer also spells LIKE, JSON, containment and bitwise operators as SQL, because the canonical text is parsed by PostgreSQL again when the live side is compared.

Migrate_PredicatesAddedToExistingTableKeepGroupingAndRegroupingIsApplied now also adds a text-cast CHECK and text-cast, LIKE and JSON policies to an existing table and asserts the catalog definitions.

I also ran 52 predicate shapes as a CHECK and as a policy, on a new and on an existing table, through v0.11.0-beta.1 and this branch, comparing the catalog definition with what PostgreSQL stores for the same expression directly. This branch produced no wrong definition and no case that the old release handled and this one does not.

Still failing, loudly and as in v0.11.0-beta.1: a CHECK comparing a text cast to a text column (a::text = d, (a + b)::text = d) and length(d::varchar) > a.

This branch has not been deployed

No deployments
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