Skip to content

refactor(migration-tools): dag → migration-graph, MigrationChainEntry → MigrationEdge#383

Merged
saevarb merged 2 commits into
mainfrom
tml-2297-prereqs
Apr 28, 2026
Merged

refactor(migration-tools): dag → migration-graph, MigrationChainEntry → MigrationEdge#383
saevarb merged 2 commits into
mainfrom
tml-2297-prereqs

Conversation

@saevarb
Copy link
Copy Markdown
Contributor

@saevarb saevarb commented Apr 27, 2026

closes TML-2326
closes TML-2327
part of TML-2297

Intent

Two mechanical renames in the migration-tools package to land before the invariant-aware-routing work (M1/M2/M3 of TML-2297). Both names are legacy from the pre-graph linear-chain era and now misdirect readers; renaming first keeps the upcoming routing diff focused on routing.

  • dag.tsmigration-graph.ts (TML-2326) — the file holds the high-level migration-graph operations (reconstructGraph, findPath, findLeaf, findLatestMigration, findReachableLeaves, detectCycles, detectOrphans). "DAG" is a misnomer — the module detects cycles rather than forbidding them. After main's earlier reshape (44d73c6, e71f9fa) split the types into graph.ts and the generic BFS primitive into graph-ops.ts, this file has one clear job. The new name slots in alongside its siblings:

    • graph.ts → migration-graph types (MigrationGraph, MigrationEdge)
    • graph-ops.ts → generic BFS primitive
    • migration-graph.ts → migration-graph operations (this rename)

    The rename runs end-to-end: internal source file, test file, public subpath (@prisma-next/migration-tools/dag…/migration-graph), barrel file, package.json exports, tsdown entry, README, and every in-workspace consumer's import string.

  • MigrationChainEntryMigrationEdge (TML-2327) — the type is used exclusively as a graph edge: from / to endpoints, lives in neighbour-indexed maps (forwardChain, reverseChain, migrationByHash), returned as edge lists from findPath / detectOrphans. Every local variable holding one is already named edge / edges / incomingEdge. MigrationEdge matches the implementation vocabulary.

Change map

The story

Two commits:

  1. Rename the file + subpath in one commit. git mv src/dag.ts src/migration-graph.ts, plus test/dag.test.tstest/migration-graph.test.ts and src/exports/dag.tssrc/exports/migration-graph.ts. package.json exports map flips ./dag./migration-graph; tsdown.config.ts entry follows; README subpath table + module-graph diagram updated; every in-workspace consumer's import string flipped from @prisma-next/migration-tools/dag to …/migration-graph.
  2. Rename the type. MigrationChainEntryMigrationEdge at the declaration in src/graph.ts; every call site (graph internals, CLI, tests, fixtures, in-tree spec/plan docs) updated to match. Type-only change, no runtime impact.

Behavior changes & evidence

None. Two mechanical commits. No control-flow change, no API addition, no removed functionality.

  • Implementation: see Change map above.
  • Tests: existing dag.test.ts (now migration-graph.test.ts) suite continues to pass under the new name; no test logic changed. CLI suite green (757/757). Migration-tools suite green (195/195). Typecheck clean.

Compatibility / migration / risk

  • Public subpath rename: @prisma-next/migration-tools/dag@prisma-next/migration-tools/migration-graph. Every in-workspace consumer is updated in this PR. The package isn't published, so no out-of-tree consumers exist; any in-progress branch that still imports from …/dag will need a one-line edit on rebase.
  • MigrationChainEntryMigrationEdge. Same story — in-workspace rename, in-progress branches need a one-line edit on rebase.
  • No behavioural risk. Pure refactor; tests prove equivalence.

Follow-ups / open questions

  • Prereq for TML-2328 (M1 marker storage) and the upcoming M2 (invariantId authoring) and M3 (findPathWithInvariants) tickets — those PRs target the new names from the start.
  • ADRs and other markdown docs that still mention dag.ts / MigrationChainEntry will be cleaned up in a later sweep alongside the M3 spec finalization.

Non-goals / intentionally out of scope

  • No invariant-aware routing behaviour. M3 ships separately under TML-2297.
  • No marker-storage changes. M1 is TML-2328, shipping in parallel.
  • No re-thinking of findPath / findPathWithDecision semantics. That's the routing-spec work, not these renames.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

This PR refactors the migration graph module by renaming dag to migration-graph and updating the graph edge type from MigrationChainEntry to MigrationEdge throughout the codebase. Import paths, type usages, package exports, and documentation are updated consistently across CLI commands, utilities, tests, and core migration modules.

Changes

Cohort / File(s) Summary
CLI Commands
packages/1-framework/3-tooling/cli/src/commands/migration-{apply,new,plan,show}.ts, migration-status.ts
Updated imports from @prisma-next/migration-tools/dag to migration-graph. migration-status.ts additionally migrates internal edge type from MigrationChainEntry to MigrationEdge in graph processing and status derivation functions.
CLI Utilities
packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts, formatters/graph-migration-mapper.ts
Switched import sources from dag to migration-graph for graph utility functions (reconstructGraph, findPath, PathDecision).
CLI Tests
packages/1-framework/3-tooling/cli/test/commands/migration-{apply,e2e,plan,ref}.test.ts, migration-plan-command.test.ts, test/utils/graph-helpers.ts
Updated test imports and mock targets from dag to migration-graph. Test helper graph-helpers.ts updated to use MigrationEdge instead of MigrationChainEntry in utility types and builders.
Core Migration Module Types
packages/1-framework/3-tooling/migration/src/graph.ts, src/exports/graph.ts
Renamed exported type MigrationChainEntry to MigrationEdge. Updated MigrationGraph interface properties (forwardChain, reverseChain, migrationByHash) to reference MigrationEdge.
Migration Export Surface
packages/1-framework/3-tooling/migration/src/exports/migration-graph.ts
Updated re-exports of PathDecision and utility functions (reconstructGraph, findPath, findPathWithDecision, detectCycles, detectOrphans) to source from ../migration-graph instead of ../dag.
Core Migration Graph Implementation
packages/1-framework/3-tooling/migration/src/migration-graph.ts
Replaced all uses of MigrationChainEntry with MigrationEdge across type signatures, internal Maps, and function returns. Updated public function return types: findPath(), findLatestMigration(), detectOrphans(), and PathDecision.selectedPath now use MigrationEdge.
Migration Package Configuration & Docs
packages/1-framework/3-tooling/migration/package.json, tsdown.config.ts, README.md
Updated package exports to remove ./dag subpath and introduce ./migration-graph. Updated build config entry from exports/dag to exports/migration-graph. Documentation reflects renamed module and updated type exports.
Migration Tests
packages/1-framework/3-tooling/migration/test/migration-graph.test.ts
Updated test imports from ../src/dag to ../src/migration-graph and retyped test data structures to use MigrationEdge.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Suggested reviewers

  • wmadden

Poem

🐰 Hoppity-hop! The dag is now a graph,
🌿 MigrationChainEntry's found a better path,
💫 MigrationEdge bounds in all its glory bright,
🎯 Exports renamed from ./dag to ./migration-graph delight,
✨ The refactoring hops—consistent, clean, and right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately and concisely describes the main refactoring changes: renaming dag to migration-graph and MigrationChainEntry to MigrationEdge, which aligns with the primary changes across the migration-tools package.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2297-prereqs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 27, 2026

Open in StackBlitz

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-runtime@383

@prisma-next/family-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/family-mongo@383

@prisma-next/sql-runtime

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-runtime@383

@prisma-next/family-sql

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/family-sql@383

@prisma-next/middleware-telemetry

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/middleware-telemetry@383

@prisma-next/mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo@383

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-paradedb@383

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-pgvector@383

@prisma-next/postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/postgres@383

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-orm-client@383

@prisma-next/sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sqlite@383

@prisma-next/target-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-mongo@383

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-mongo@383

@prisma-next/driver-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-mongo@383

@prisma-next/contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract@383

@prisma-next/utils

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/utils@383

@prisma-next/config

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/config@383

@prisma-next/errors

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/errors@383

@prisma-next/framework-components

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/framework-components@383

@prisma-next/operations

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/operations@383

@prisma-next/ts-render

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/ts-render@383

@prisma-next/contract-authoring

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract-authoring@383

@prisma-next/ids

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/ids@383

@prisma-next/psl-parser

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/psl-parser@383

@prisma-next/psl-printer

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/psl-printer@383

@prisma-next/cli

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/cli@383

@prisma-next/emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/emitter@383

@prisma-next/migration-tools

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/migration-tools@383

prisma-next

npm i https://pkg.pr.new/prisma/prisma-next@383

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/vite-plugin-contract-emit@383

@prisma-next/mongo-codec

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-codec@383

@prisma-next/mongo-contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract@383

@prisma-next/mongo-value

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-value@383

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract-psl@383

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract-ts@383

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-emitter@383

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-schema-ir@383

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-query-ast@383

@prisma-next/mongo-orm

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-orm@383

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-query-builder@383

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-lowering@383

@prisma-next/mongo-wire

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-wire@383

@prisma-next/sql-contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract@383

@prisma-next/sql-errors

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-errors@383

@prisma-next/sql-operations

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-operations@383

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-schema-ir@383

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-psl@383

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-ts@383

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-emitter@383

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-lane-query-builder@383

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-relational-core@383

@prisma-next/sql-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-builder@383

@prisma-next/target-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-postgres@383

@prisma-next/target-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-sqlite@383

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-postgres@383

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-sqlite@383

@prisma-next/driver-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-postgres@383

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-sqlite@383

commit: 9719418

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/planning/benchmarks/migration-graph-baseline.md (1)

168-178: Residual "dag" terminology in the rendering-pipeline section.

After the module rename, the table caption ("Relies on") and the prose still describe the underlying layer as "dag layer" / "dag-shaped loop" / "dag ops". For consistency with the rest of the document (and the renamed graph.ts source it points at), consider replacing these with "graph layer" / "graph-shaped loop" / "graph ops". Same applies to the file path mention graph-render.ts already being correct — only the surrounding labels are stale.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/planning/benchmarks/migration-graph-baseline.md` around lines 168 - 178,
Update all remaining "dag" terminology in the rendering-pipeline section to
"graph" for consistency: change table cells "dag layer" → "graph layer" and
"dag-shaped loop" → "graph-shaped loop", and update prose references like "dag
ops" to "graph ops"; ensure occurrences near the functions/methods
migrationGraphToRenderInput, extractRelevantSubgraph, truncateGraph and in the
paragraph mentioning graph-render.ts are replaced accordingly. Search the block
for any other "dag" tokens and rename them to "graph" so labels/captions and
surrounding text match the renamed graph.ts source.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/planning/benchmarks/migration-graph-baseline.md`:
- Line 7: The docs refer to the old export path
`@prisma-next/migration-tools/dag` which no longer exists; update the "Scope"
paragraph in migration-graph-baseline.md to reference the current export path
(`@prisma-next/migration-tools/graph` or the package's `./graph` export) and
adjust any mention of the `MigrationGraph` data structure accordingly; also
replace or add a canonical link to the package README or package.json export
section to avoid future drift (look for mentions of MigrationGraph and the
string "dag" in migration-graph-baseline.md to locate the text to change).

---

Nitpick comments:
In `@docs/planning/benchmarks/migration-graph-baseline.md`:
- Around line 168-178: Update all remaining "dag" terminology in the
rendering-pipeline section to "graph" for consistency: change table cells "dag
layer" → "graph layer" and "dag-shaped loop" → "graph-shaped loop", and update
prose references like "dag ops" to "graph ops"; ensure occurrences near the
functions/methods migrationGraphToRenderInput, extractRelevantSubgraph,
truncateGraph and in the paragraph mentioning graph-render.ts are replaced
accordingly. Search the block for any other "dag" tokens and rename them to
"graph" so labels/captions and surrounding text match the renamed graph.ts
source.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 53f80e8b-bf1e-4a5d-8169-b2aff33e5e19

📥 Commits

Reviewing files that changed from the base of the PR and between 2c70cd8 and 0658d18.

📒 Files selected for processing (22)
  • docs/planning/benchmarks/migration-graph-baseline.md
  • packages/1-framework/3-tooling/cli/src/commands/migration-apply.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-new.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-show.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
  • packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts
  • packages/1-framework/3-tooling/cli/src/utils/formatters/graph-migration-mapper.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-apply.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-e2e.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref.test.ts
  • packages/1-framework/3-tooling/cli/test/utils/graph-helpers.ts
  • packages/1-framework/3-tooling/migration/README.md
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/src/exports/graph.ts
  • packages/1-framework/3-tooling/migration/src/exports/types.ts
  • packages/1-framework/3-tooling/migration/src/graph.ts
  • packages/1-framework/3-tooling/migration/src/types.ts
  • packages/1-framework/3-tooling/migration/test/graph.test.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts

Comment thread docs/planning/benchmarks/migration-graph-baseline.md
@saevarb saevarb force-pushed the tml-2297-prereqs branch 2 times, most recently from c42f69e to dfa911e Compare April 27, 2026 14:20
Copy link
Copy Markdown
Contributor

@wmadden wmadden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍🏻

saevarb added 2 commits April 28, 2026 09:33
The file holds the high-level migration-graph operations
(`reconstructGraph`, `findPath`, `findLeaf`, `findLatestMigration`,
`findReachableLeaves`, `detectCycles`, `detectOrphans`). "DAG" is a
misnomer — the module detects cycles, doesn't forbid them. Now that
the previous reshape (44d73c6, e71f9fa) split out the types into
`graph.ts` and the generic BFS primitive into `graph-ops.ts`, this
file has one clear job; rename to match.

The new name pairs with the existing structure:

* `graph.ts` → migration-graph types
* `graph-ops.ts` → generic BFS primitive
* `migration-graph.ts` → migration-graph operations

Mechanical rename:

* `git mv src/dag.ts → src/migration-graph.ts`
* `git mv src/exports/dag.ts → src/exports/migration-graph.ts`
* `git mv test/dag.test.ts → test/migration-graph.test.ts`
* Public subpath: `./dag` → `./migration-graph` in package.json
  exports + tsdown.config entry
* README subpath table + module-graph diagram
* All in-workspace consumers updated to import from
  `@prisma-next/migration-tools/migration-graph`

No behavioural change; tests + typecheck green.
The type is used exclusively as a graph edge: it has `from` / `to`
endpoints, lives in neighbour-indexed maps (`forwardChain`,
`reverseChain`, `migrationByHash`), is returned as edge lists from
`findPath` / `detectOrphans`, and every local variable holding one is
already named `edge` / `edges` / `incomingEdge`. `MigrationEdge`
matches the implementation vocabulary; `ChainEntry` is legacy from the
pre-graph linear-chain era and actively misleads readers.

Type-only change. No runtime impact.

* Type declaration in `src/graph.ts`
* Re-export name in `src/exports/graph.ts` and the README subpath table
* Every call site updated (CLI src + tests + fixture helpers + README)
* In-tree spec/plan docs that mention the type also updated
@saevarb saevarb changed the title refactor(migration-tools): dag → graph, MigrationChainEntry → MigrationEdge refactor(migration-tools): dag → migration-graph, MigrationChainEntry → MigrationEdge Apr 28, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/1-framework/3-tooling/migration/src/migration-graph.ts (1)

24-24: Rename residual entry wording to edge for consistency.

After the type rename, these identifiers/comments still use old terminology and can cause minor confusion during maintenance.

♻️ Suggested cleanup
-function appendEdge(map: Map<string, MigrationEdge[]>, key: string, entry: MigrationEdge): void {
+function appendEdge(map: Map<string, MigrationEdge[]>, key: string, edge: MigrationEdge): void {
   const bucket = map.get(key);
-  if (bucket) bucket.push(entry);
-  else map.set(key, [entry]);
+  if (bucket) bucket.push(edge);
+  else map.set(key, [edge]);
 }
- * Find the latest migration entry by traversing from EMPTY_CONTRACT_HASH
+ * Find the latest migration edge by traversing from EMPTY_CONTRACT_HASH

As per coding guidelines: "**/*.{md,ts,tsx}: Keep docs current (READMEs, rules, links) and prefer links to canonical docs over long comments."

Also applies to: 315-316

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/migration/src/migration-graph.ts` at line 24,
The identifier "entry" is a leftover from an old type name and should be renamed
to "edge" for clarity; update the appendEdge function signature (appendEdge(map:
Map<string, MigrationEdge[]>, key: string, entry: MigrationEdge) -> use "edge"
instead of "entry"), change all internal references inside appendEdge from entry
to edge, and similarly rename any other residual identifiers/comments referring
to "entry" (notably the other occurrences around the MigrationEdge handling) to
"edge" to keep naming consistent with the MigrationEdge type.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/1-framework/3-tooling/cli/src/commands/migration-status.ts`:
- Line 159: The current edgeKey in deriveEdgeStatuses (`const edgeKey = (e:
MigrationEdge) => `${e.from}\0${e.to}``) only uses from/to and will collide when
two distinct MigrationEdge instances share endpoints; change the key to include
a unique identifier for the MigrationEdge (for example add or use an existing
field like e.id, e.migrationId or e.name) so the key becomes something like
`${e.from}\0${e.to}\0${e.id ?? e.migrationId ?? e.name}`; update the
MigrationEdge type if necessary to expose a stable unique id and use that
property in edgeKey and any lookups to ensure edges are disambiguated.

---

Nitpick comments:
In `@packages/1-framework/3-tooling/migration/src/migration-graph.ts`:
- Line 24: The identifier "entry" is a leftover from an old type name and should
be renamed to "edge" for clarity; update the appendEdge function signature
(appendEdge(map: Map<string, MigrationEdge[]>, key: string, entry:
MigrationEdge) -> use "edge" instead of "entry"), change all internal references
inside appendEdge from entry to edge, and similarly rename any other residual
identifiers/comments referring to "entry" (notably the other occurrences around
the MigrationEdge handling) to "edge" to keep naming consistent with the
MigrationEdge type.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 184260aa-b131-499a-8ae8-d81a94db0c74

📥 Commits

Reviewing files that changed from the base of the PR and between dfa911e and 9719418.

📒 Files selected for processing (21)
  • packages/1-framework/3-tooling/cli/src/commands/migration-apply.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-new.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-show.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
  • packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts
  • packages/1-framework/3-tooling/cli/src/utils/formatters/graph-migration-mapper.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-apply.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-e2e.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref.test.ts
  • packages/1-framework/3-tooling/cli/test/utils/graph-helpers.ts
  • packages/1-framework/3-tooling/migration/README.md
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/src/exports/graph.ts
  • packages/1-framework/3-tooling/migration/src/exports/migration-graph.ts
  • packages/1-framework/3-tooling/migration/src/graph.ts
  • packages/1-framework/3-tooling/migration/src/migration-graph.ts
  • packages/1-framework/3-tooling/migration/test/migration-graph.test.ts
  • packages/1-framework/3-tooling/migration/tsdown.config.ts
✅ Files skipped from review due to trivial changes (10)
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-e2e.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-apply.test.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-show.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-new.ts
  • packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan.test.ts
  • packages/1-framework/3-tooling/migration/src/exports/migration-graph.ts
  • packages/1-framework/3-tooling/cli/test/utils/graph-helpers.ts
  • packages/1-framework/3-tooling/migration/src/graph.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/migration/src/exports/graph.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-apply.ts
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/README.md

if (mode === 'offline') return [];

const edgeKey = (e: MigrationChainEntry) => `${e.from}\0${e.to}`;
const edgeKey = (e: MigrationEdge) => `${e.from}\0${e.to}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Disambiguate edge identity in deriveEdgeStatuses to avoid collisions.

Line 159 keys edges only by from/to. Distinct migrations with the same endpoints will collide, which can hide or misclassify statuses for one of those edges.

🐛 Proposed fix
-  const edgeKey = (e: MigrationEdge) => `${e.from}\0${e.to}`;
+  const edgeKey = (e: MigrationEdge) => `${e.from}\0${e.to}\0${e.migrationHash}`;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/3-tooling/cli/src/commands/migration-status.ts` at line
159, The current edgeKey in deriveEdgeStatuses (`const edgeKey = (e:
MigrationEdge) => `${e.from}\0${e.to}``) only uses from/to and will collide when
two distinct MigrationEdge instances share endpoints; change the key to include
a unique identifier for the MigrationEdge (for example add or use an existing
field like e.id, e.migrationId or e.name) so the key becomes something like
`${e.from}\0${e.to}\0${e.id ?? e.migrationId ?? e.name}`; update the
MigrationEdge type if necessary to expose a stable unique id and use that
property in edgeKey and any lookups to ensure edges are disambiguated.

@saevarb saevarb enabled auto-merge (squash) April 28, 2026 07:46
@saevarb saevarb merged commit fde3a23 into main Apr 28, 2026
16 checks passed
@saevarb saevarb deleted the tml-2297-prereqs branch April 28, 2026 07:50
wmadden pushed a commit that referenced this pull request May 4, 2026
… → MigrationEdge (#383)

closes
[TML-2326](https://linear.app/prisma-company/issue/TML-2326/rename-dagts-graphts-p2-of-tml-2297)
closes
[TML-2327](https://linear.app/prisma-company/issue/TML-2327/rename-migrationchainentry-migrationedge-p3-of-tml-2297)
part of
[TML-2297](https://linear.app/prisma-company/issue/TML-2297/pn-invariant-aware-routing)

## Intent

Two mechanical renames in the migration-tools package to land before the
invariant-aware-routing work (M1/M2/M3 of
[TML-2297](https://linear.app/prisma-company/issue/TML-2297)). Both
names are legacy from the pre-graph linear-chain era and now misdirect
readers; renaming first keeps the upcoming routing diff focused on
routing.

- **`dag.ts` → `migration-graph.ts`**
([TML-2326](https://linear.app/prisma-company/issue/TML-2326)) — the
file holds the high-level migration-graph operations
(`reconstructGraph`, `findPath`, `findLeaf`, `findLatestMigration`,
`findReachableLeaves`, `detectCycles`, `detectOrphans`). "DAG" is a
misnomer — the module detects cycles rather than forbidding them. After
main's earlier reshape (44d73c6, e71f9fa) split the types into
`graph.ts` and the generic BFS primitive into `graph-ops.ts`, this file
has one clear job. The new name slots in alongside its siblings:
- `graph.ts` → migration-graph types (`MigrationGraph`, `MigrationEdge`)
  - `graph-ops.ts` → generic BFS primitive
  - `migration-graph.ts` → migration-graph operations (this rename)

The rename runs end-to-end: internal source file, test file, public
subpath (`@prisma-next/migration-tools/dag` → `…/migration-graph`),
barrel file, `package.json` exports, `tsdown` entry, README, and every
in-workspace consumer's import string.

- **`MigrationChainEntry` → `MigrationEdge`**
([TML-2327](https://linear.app/prisma-company/issue/TML-2327)) — the
type is used exclusively as a graph edge: `from` / `to` endpoints, lives
in neighbour-indexed maps (`forwardChain`, `reverseChain`,
`migrationByHash`), returned as edge lists from `findPath` /
`detectOrphans`. Every local variable holding one is already named
`edge` / `edges` / `incomingEdge`. `MigrationEdge` matches the
implementation vocabulary.

## Change map

- **Implementation (file/type renames)**:
- [packages/1-framework/3-tooling/migration/src/migration-graph.ts (was
dag.ts)](packages/1-framework/3-tooling/migration/src/migration-graph.ts)
— migration-graph operations
-
[packages/1-framework/3-tooling/migration/src/exports/migration-graph.ts
(was
exports/dag.ts)](packages/1-framework/3-tooling/migration/src/exports/migration-graph.ts)
— public-subpath barrel, re-exports from `../migration-graph`
-
[packages/1-framework/3-tooling/migration/src/graph.ts](packages/1-framework/3-tooling/migration/src/graph.ts)
— `MigrationEdge` declaration (type lives in the existing types-only
file, not the renamed operations file)
-
[packages/1-framework/3-tooling/migration/src/exports/graph.ts](packages/1-framework/3-tooling/migration/src/exports/graph.ts)
— re-exported name follows the rename
- **Implementation (package wiring)**:
-
[packages/1-framework/3-tooling/migration/package.json](packages/1-framework/3-tooling/migration/package.json)
— `exports` map: `./dag` → `./migration-graph`
-
[packages/1-framework/3-tooling/migration/tsdown.config.ts](packages/1-framework/3-tooling/migration/tsdown.config.ts)
— entry: `exports/dag` → `exports/migration-graph`
-
[packages/1-framework/3-tooling/migration/README.md](packages/1-framework/3-tooling/migration/README.md)
— subpath table + module-graph diagram updated
- **Implementation (consumers)**:
- CLI commands and helpers under
`packages/1-framework/3-tooling/cli/src/**` — every `from
'@prisma-next/migration-tools/dag'` flipped to `…/migration-graph`, plus
`MigrationEdge`-typed call sites
- CLI test files under `packages/1-framework/3-tooling/cli/test/**` —
same import-path updates, including
`vi.mock('@prisma-next/migration-tools/migration-graph', …)`
- **Tests (evidence)**:
- [packages/1-framework/3-tooling/migration/test/migration-graph.test.ts
(was
dag.test.ts)](packages/1-framework/3-tooling/migration/test/migration-graph.test.ts)
— same assertions under the new file name; no behavioural drift

## The story

Two commits:

1. **Rename the file + subpath in one commit.** `git mv src/dag.ts
src/migration-graph.ts`, plus `test/dag.test.ts` →
`test/migration-graph.test.ts` and `src/exports/dag.ts` →
`src/exports/migration-graph.ts`. `package.json` exports map flips
`./dag` → `./migration-graph`; `tsdown.config.ts` entry follows; README
subpath table + module-graph diagram updated; every in-workspace
consumer's import string flipped from `@prisma-next/migration-tools/dag`
to `…/migration-graph`.
2. **Rename the type.** `MigrationChainEntry` → `MigrationEdge` at the
declaration in `src/graph.ts`; every call site (graph internals, CLI,
tests, fixtures, in-tree spec/plan docs) updated to match. Type-only
change, no runtime impact.

## Behavior changes & evidence

**None.** Two mechanical commits. No control-flow change, no API
addition, no removed functionality.

- **Implementation**: see Change map above.
- **Tests**: existing `dag.test.ts` (now `migration-graph.test.ts`)
suite continues to pass under the new name; no test logic changed. CLI
suite green (757/757). Migration-tools suite green (195/195). Typecheck
clean.

## Compatibility / migration / risk

- **Public subpath rename: `@prisma-next/migration-tools/dag` →
`@prisma-next/migration-tools/migration-graph`.** Every in-workspace
consumer is updated in this PR. The package isn't published, so no
out-of-tree consumers exist; any in-progress branch that still imports
from `…/dag` will need a one-line edit on rebase.
- **`MigrationChainEntry` → `MigrationEdge`.** Same story — in-workspace
rename, in-progress branches need a one-line edit on rebase.
- **No behavioural risk.** Pure refactor; tests prove equivalence.

## Follow-ups / open questions

- Prereq for
[TML-2328](https://linear.app/prisma-company/issue/TML-2328) (M1 marker
storage) and the upcoming M2 (`invariantId` authoring) and M3
(`findPathWithInvariants`) tickets — those PRs target the new names from
the start.
- ADRs and other markdown docs that still mention `dag.ts` /
`MigrationChainEntry` will be cleaned up in a later sweep alongside the
M3 spec finalization.

## Non-goals / intentionally out of scope

- No invariant-aware routing behaviour. M3 ships separately under
[TML-2297](https://linear.app/prisma-company/issue/TML-2297).
- No marker-storage changes. M1 is
[TML-2328](https://linear.app/prisma-company/issue/TML-2328), shipping
in parallel.
- No re-thinking of `findPath` / `findPathWithDecision` semantics.
That's the routing-spec work, not these renames.
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.

2 participants