Skip to content

feat(pgpm): generate revert/verify scripts for restructured exports - #1562

Merged
pyramation merged 3 commits into
mainfrom
feat/revert-verify-generation
Jul 31, 2026
Merged

feat(pgpm): generate revert/verify scripts for restructured exports#1562
pyramation merged 3 commits into
mainfrom
feat/revert-verify-generation

Conversation

@pyramation

@pyramation pyramation commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 4 follow-up to #1554 (refs constructive-io/constructive-planning#1329): granularity-restructured exports previously emitted empty revert/verify files. This wires the revertFor/verifyFor generators from @pgsql/scripts (constructive-io/pgsql-parser#327, published as @pgsql/scripts@18.0.1) through restructureChanges and pgpm export so every restructured change ships populated, mechanically-derived scripts.

  • @pgpmjs/transformrestructureChanges now returns RestructuredChange extends GranularityChange:
    interface RestructuredChange extends GranularityChange {
      revert: string;  // revertFor(groupFacts): inverse statements, reverse topo order within the group, no CASCADE
      verify: string;  // verifyFor(groupFacts): one raise-on-failure existence check per created object
    }
    Generation warnings (e.g. revert not derivable: ... for non-invertible statements) are surfaced in result.warnings, prefixed with the owning change name.
  • @pgpmjs/exportrestructureExportRows carries change.revert/change.verify into the emitted rows instead of ''. pgpm headers and transaction wrappers are unchanged (they're owned by writePgpmFiles).
  • Deps: @pgsql/scripts@^18.0.0 (new), @pgsql/transform@^18.11.0 (facts now carry the raw statement node the generators need).

e2e round-trip

export-granularity.test.ts proves the full loop against Postgres: export at consolidated → deploy → verify passes on the generated checks → revert succeeds and leaves the DB clean (pets_consolidated_public gone), with no CASCADE in any generated script.

pgpm/transform 43/43 and the granularity e2e suite 10/10 pass against the published packages; the 7 failures in other pgpm/export suites are pre-existing on main (confirmed on a clean worktree).

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

restructureChanges now derives per-change revert (mechanical inverses in
reverse topological order via revertFor) and verify (raise-on-failure
existence checks via verifyFor) scripts from each change's statement
group, and pgpm export writes them instead of empty files.

Refs constructive-planning#1329 (Phase 4 follow-up).
@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

revertFor/verifyFor moved out of @pgsql/transform into the new
@pgsql/scripts package upstream. Lockfile update deferred until the
package is published.
@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review July 31, 2026 08:38
@pyramation
pyramation merged commit 9b210da into main Jul 31, 2026
9 checks passed
@pyramation
pyramation deleted the feat/revert-verify-generation branch July 31, 2026 08:39
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