feat(scripts): @pgsql/scripts — revert and verify generation from statement facts - #327
Merged
Conversation
…ation from statement facts
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:
|
Migration script generation gets its own package next to the parser and deparser: @pgsql/scripts derives revert and verify scripts from @pgsql/transform statement facts. Adds SUPPORTED_STATEMENTS / SUPPORTED_NODE_TAGS documenting the supported vocabulary; anything else warns instead of guessing.
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
Phase 4 follow-up (refs constructive-io/constructive-planning#1329): a new package,
@pgsql/scripts, derives revert and verify scripts from@pgsql/transformstatement facts — the missing third leg next to the parser and deparser. Consumed by constructive-io/constructive#1562 sopgpm export --granularitystops emitting empty revert/verify files.revertFor— mechanical inverses in reverse topological order ofbuildStatementGraph(facts), so dependents drop before dependencies and noCASCADEis ever emitted. Inverses are built as AST nodes and deparsed (never string-templated): CREATE schema/table/view/index/sequence/type/domain/function/trigger/policy/extension/role → DROP (functions keep their input signature for overload safety);ADD COLUMN/ADD CONSTRAINT→DROP;GRANT→REVOKE; RLS enable/force → disable/no-force;COMMENT ON→... IS NULL. Non-invertible statements (DML, dynamic SQL,ALTER ... SETwith unknown prior state, unnamed constraints,REVOKE) emit-- revert not derivable: <reason>plus a warning — never guessed.verifyFor— one raise-on-failure existence check per created object viaSELECT 1/(CASE WHEN <exists> THEN 1 ELSE 0 END);:to_regclass/to_regprocedure/to_regtypewhere a reg* cast exists, catalog lookups (pg_policies,pg_trigger,pg_extension,pg_roles,pg_auth_members,information_schema.columns/table_constraints) for the rest,has_table_privilege/has_function_privilege/has_schema_privilegefor grants.SUPPORTED_STATEMENTS,SUPPORTED_NODE_TAGS) and documented as a table in the package README — consumers can check support programmatically instead of only hitting warnings.Supporting changes in
@pgsql/transform:StatementFacts.stmt?now carries the raw parsed statement node so consumers can derive statements without a second parse.CreateDomainStmtclassification: the domain's name isdomainname(typeNameis its base type).45 exact-output unit tests in
packages/scripts/__tests__/invert.test.ts;@pgsql/scriptsadded to the CI test matrix.Link to Devin session: https://app.devin.ai/sessions/7f032c8e1bf245eeac2def99fdcc1623
Requested by: @pyramation