Skip to content

refactor(pg-delta): move execution phase classification onto BaseChange.phase#245

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/refactor-basechange-phase
Draft

refactor(pg-delta): move execution phase classification onto BaseChange.phase#245
Copilot wants to merge 3 commits into
mainfrom
copilot/refactor-basechange-phase

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 2, 2026

This refactor removes phase classification from sort-layer helpers and colocates it with change objects via BaseChange.phase, while preserving existing execution behavior. It also renames the phase value from create_alter_object to forward across pg-delta.

  • Phase ownership moved to change model

    • Added Phase = "drop" | "forward" and default phase getter to BaseChange.
    • Made phase selection total over operation (create/alter/drop) with no fallback default.
  • Layering cleanup

    • Deleted core/sort/utils.ts (getExecutionPhase, old Phase, table-specific instanceof logic).
    • Moved isMetadataStableId to core/stable-id.ts so BaseChange and sort code can share it without sort→object coupling.
  • Load-bearing table alter overrides

    • Added phase overrides in:
      • AlterTableAlterColumnDropDefaultdrop
      • AlterTableAlterColumnDropIdentitydrop
      • AlterTableAlterColumnTypeforward for custom type, otherwise drop
  • Sort pipeline updated to consume change.phase

    • Updated logical-sort.ts and sort-changes.ts to partition on change.phase.
    • Replaced create_alter_object buckets/maps with forward.
  • Top-level drop predicate left intact (with clarification)

    • Kept catalog.diff.ts object-drop filtering logic (operation === "drop" && scope === "object") and added a clarifying comment that this is intentionally different from phase checks.
  • Docs and tests

    • Added CONTEXT.md at repo root with canonical terms: catalog, change, phase, plan.
    • Added base.change.test.ts matrix coverage for default phase behavior, metadata-only drops, and mixed metadata+object drops.
    • Added focused phase tests in table.alter.test.ts for each override case.
// BaseChange default phase classification
get phase(): Phase {
  switch (this.operation) {
    case "drop":
      return "drop";
    case "create":
      return "forward";
    case "alter": {
      const dropsRealObject = this.drops.some((id) => !isMetadataStableId(id));
      return dropsRealObject ? "drop" : "forward";
    }
  }
}

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 2, 2026

⚠️ No Changeset found

Latest commit: 410f2f7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI and others added 2 commits May 2, 2026 17:16
Copilot AI changed the title [WIP] Refactor pg-delta to move execution phase onto BaseChange refactor(pg-delta): move execution phase classification onto BaseChange.phase May 2, 2026
Copilot AI requested a review from avallete May 2, 2026 17:21
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.

refactor(pg-delta): move execution phase onto BaseChange as change.phase

2 participants