feat(scripts): extend revert/verify vocabulary + node-level AST API - #328
Merged
Conversation
New mechanical inverses and existence checks: materialized views / CREATE TABLE AS, foreign servers / foreign tables / user mappings, collations, aggregates, binary operators, casts, publications, subscriptions, extended statistics, event triggers, rules, ATTACH PARTITION (-> DETACH), ALTER DEFAULT PRIVILEGES GRANT (-> REVOKE) and SECURITY LABEL (-> IS NULL). ALTER TYPE ADD VALUE gains a pg_enum verify check (no revert: Postgres has no DROP VALUE). Prefix operators and DEFAULT PRIVILEGES REVOKE warn instead of guessing.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…ong-tail creates, node-level API - RenameStmt / AlterObjectSchemaStmt inverses (the statement carries both sides) - GRANT ALL verify expansion to the object type's concrete privilege list - FDW, conversion, access method, transform, opclass/opfamily, text search objects and tablespaces: DROP inverses + catalog existence checks - has_sequence_privilege for sequence grants - deparser: dot-join qualified names in ALTER TYPE/DOMAIN RENAME; emit SEQUENCE keyword in GRANT/REVOKE ON SEQUENCE - node-level API: invertStatement(facts) -> Node[] | null and existenceCheck(facts) -> Node[] | null under revertFor/verifyFor
…e and SEQUENCE grants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends
@pgsql/scriptsin three directions, keeping the never-guess contract (un-derivable →-- revert not derivable: <reason>+ warning; inverses are AST-built and deparsed, never string-templated; reverse topo order):1. Easy-win vocabulary — matviews/CTAS, FDW family (server/foreign table/user mapping), collation/aggregate/binary operator/cast, publication/subscription/statistics/event trigger/rule,
ATTACH PARTITION→DETACH PARTITION,ALTER DEFAULT PRIVILEGES GRANT→REVOKE,SECURITY LABEL→IS NULL, plus apg_enumverify forADD VALUE(no revert — Postgres has noDROP VALUE).2. Stateless groups — inverses that need no prior state because the statement carries both sides:
RenameStmt/AlterObjectSchemaStmt: swap old/new name (or schema) — tables, columns, indexes, sequences, views, types, functions, schemas.SET SCHEMAon an unqualified name warns (original schema unknown).GRANT ALL: revert staysREVOKE ALL; verify expands to the object type's concrete privilege list (ALL_PRIVILEGESper objtype; sequences now usehas_sequence_privilege).DROP+ catalog existence checks (pg_foreign_data_wrapper,pg_conversion,pg_am,pg_transform,pg_opclass/pg_opfamily,pg_ts_*,pg_tablespace).3. Node-level API — the per-statement layer under
revertFor/verifyFor, for consumers that compose inverses at the AST level (semantic diff driver, bundle reconcile, migration gen) without round-tripping through deparsed text:Both return
nullinstead of guessing — including partially underivable multi-commandALTER TABLEs (no silent partial inverses).revertFor/verifyForremain the text-level conveniences on top.Two deparser fixes surfaced by round-tripping the generated inverses:
ALTER TYPE/DOMAIN ... RENAMEnow dot-joins qualified names (was comma-joining theList), andGRANT/REVOKE ... ON SEQUENCEnow emits theSEQUENCEkeyword.87 exact-output tests;
SUPPORTED_STATEMENTS/README updated. Part of the Phase 4 follow-up (constructive-planning#1329).Link to Devin session: https://app.devin.ai/sessions/7f032c8e1bf245eeac2def99fdcc1623
Requested by: @pyramation