feat(pgpm): pgpm regen — generate revert/verify scripts from deploys - #1566
Merged
Conversation
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:
|
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
Adds
pgpm regen(constructive-io/constructive-planning#1329 dials roadmap; distinct from the futurepgpm generate, constructive-io/constructive-planning#1333): fills in a module'srevert/andverify/scripts mechanically from itsdeploy/scripts, using the same@pgsql/scriptssubstrate that #1562 wired into restructured exports (classifyStatements→revertFor/verifyFor).@pgpmjs/transform— newregenmodule (pure, parser-level):classifyScript(sql)—classifyStatementsminusTransactionStmt(the BEGIN/COMMIT wrapper scripts carry is the file convention's job, not a statement to invert)isStubScript(sql)— stub = parses to zero substantive statements (comments, whitespace, bare transaction wrapper). Unparseable content is not a stub, so it is never overwritten.regenerateScripts(deploySql)→{ revert, verify }(GeneratedScripts withwarnings)pgpmCLI —commands/regen.ts(engine-exempt, no DB connection): iteratespgpm.plan, readsdeploy/<change>.sql, and writes generated scripts in repo convention —-- Revert <change> from pg+BEGIN;…COMMIT;,-- Verify <change> on pg+BEGIN;…ROLLBACK;. Non-derivable statements (e.g. DML) become-- revert not derivable: <reason>comments; the run ends with agenerated / skipped / warningssummary.Tests
pgpm/transform/__tests__/regen.test.ts— stub detection, wrapper exclusion, revert ordering, verify checks, non-derivable warningspgpm/cli/__tests__/regen.test.ts— sweep/targeted,--force,--dry-run,--revert-only/--verify-only, file emission conventionspgpm/cli/__tests__/regen-e2e.test.ts— fixture module with mixed kinds (schema, table, ALTER columns/constraints, function, trigger, RLS policy, grant, index), all stubs →pgpm regen→ live-Postgres round-trip: deploy →pgpm verifypasses →pgpm revertleaves the DB clean (schema gone, ledger empty)pnpm-lock.yamlre-resolved by pnpm 10 for the new@pgpmjs/transformdep ofpgpm(same wholesale normalization as #1562).Link to Devin session: https://app.devin.ai/sessions/d84ba7255ddc405ea0f83f21b3247642
Requested by: @pyramation