Skip to content

feat(pgpm): pgpm regen — generate revert/verify scripts from deploys - #1566

Merged
pyramation merged 1 commit into
mainfrom
feat/pgpm-regen
Jul 31, 2026
Merged

feat(pgpm): pgpm regen — generate revert/verify scripts from deploys#1566
pyramation merged 1 commit into
mainfrom
feat/pgpm-regen

Conversation

@pyramation

Copy link
Copy Markdown
Contributor

Summary

Adds pgpm regen (constructive-io/constructive-planning#1329 dials roadmap; distinct from the future pgpm generate, constructive-io/constructive-planning#1333): fills in a module's revert/ and verify/ scripts mechanically from its deploy/ scripts, using the same @pgsql/scripts substrate that #1562 wired into restructured exports (classifyStatementsrevertFor/verifyFor).

pgpm regen                      # sweep: every plan change whose revert/verify is missing or an empty stub
pgpm regen <change...>          # targeted mode
    --revert-only|--verify-only
    --dry-run                   # report what would be written + warnings, write nothing
    --force                     # overwrite non-empty scripts (never done otherwise)

@pgpmjs/transform — new regen module (pure, parser-level):

  • classifyScript(sql)classifyStatements minus TransactionStmt (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 with warnings)

pgpm CLI — commands/regen.ts (engine-exempt, no DB connection): iterates pgpm.plan, reads deploy/<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 a generated / skipped / warnings summary.

Tests

  • pgpm/transform/__tests__/regen.test.ts — stub detection, wrapper exclusion, revert ordering, verify checks, non-derivable warnings
  • pgpm/cli/__tests__/regen.test.ts — sweep/targeted, --force, --dry-run, --revert-only/--verify-only, file emission conventions
  • pgpm/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 verify passes → pgpm revert leaves the DB clean (schema gone, ledger empty)

pnpm-lock.yaml re-resolved by pnpm 10 for the new @pgpmjs/transform dep of pgpm (same wholesale normalization as #1562).

Link to Devin session: https://app.devin.ai/sessions/d84ba7255ddc405ea0f83f21b3247642
Requested by: @pyramation

@pyramation pyramation self-assigned this Jul 31, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@pyramation
pyramation merged commit a10ea24 into main Jul 31, 2026
16 checks passed
@pyramation
pyramation deleted the feat/pgpm-regen branch July 31, 2026 16:07
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