feat(pgpm): change-granularity dial — one change per alteration (planning #1342) - #1585
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
The fourth dial (planning constructive-planning#1342): statement granularity (
--granularity atomic|object|consolidated, SQL shape within a change) is now orthogonal to change granularity (--change-granularity object|alteration, how statements are distributed across pgpm changes). Defaultobjectis byte-identical to today.With
alteration, every single-commandALTER TABLE ADD COLUMN/ADD CONSTRAINTbecomes its own plan entry with its own deploy/revert/verify and requires:revert is
DROP COLUMN/DROP CONSTRAINT; verify checksinformation_schema.columns/table_constraints— so a single column can deploy or revert independently.How it works:
@pgpmjs/naming-spec: newcolumnidentity kind →schemas/{s}/tables/{t}/columns/{c}/column.@pgpmjs/transformsub-object.ts:subObjectIdentityOf(facts)recovers the column/constraint name from the raw parse node (facts.stmt) thatidentityOfsummarizes away — no parser changes needed.nameUnnamedConstraints(sql)rewritesADD PRIMARY KEY (id)→ADD CONSTRAINT users_pkey PRIMARY KEY (id)(the exact name Postgres would assign, viadefaultConstraintNamefrom feat(transform): constraint-placement-invariant semantic diff (planning #1341) #1584) so each constraint change is revertible.restructureChanges({ changeGranularity: 'alteration' })groups those statements by sub-object identity instead of owning object, and adds finer edges the statement graph (keyed by table) can't express: alteration → its table's change, constraint → the column changes it keys on (keys/fk_attrs).restructureExportRows,diffChangeSets,importDumpRows, and thepgpm transform/pgpm diff/pgpm importCLIs.Semantic invariance holds across both axes:
examples/pgpm-projectionsnow asserts atomic ≡ object ≡ consolidated ≡ alteration at the identity-keyed model (the old "atomic is only catalog-equivalent" caveat is removed — #1584 fixed that), and live-Postgres e2e (transform-e2e, diff-e2e) proves alteration-mode modules deploy to the identical catalog, verify, and revert clean.Link to Devin session: https://app.devin.ai/sessions/798445577ac8487abf80e28f9ff7a916
Requested by: @pyramation