Repository navigation
feat(cli): color migration graph lanes + add --legend (TML-2773) - #674
Conversation
📝 WalkthroughWalkthroughAdds a ChangesMigration Graph Legend with Lane-Aware Colorization
Sequence Diagram(s)sequenceDiagram
participant CLI as migration-graph command
participant Helper as CLI helpers
participant Renderer as renderMigrationGraphTree
participant LaneColor as laneColorForColumn
participant Legend as renderMigrationGraphLegend
participant stderr as stderr
CLI->>Helper: migrationGraphUsesTree(options)
Helper-->>CLI: true if --tree or --legend
alt uses tree rendering
CLI->>Renderer: Render tree
Renderer->>Renderer: resolveRowLaneColors()
Renderer->>LaneColor: laneColorForColumn(col)
LaneColor-->>Renderer: LaneColorizer
Renderer->>Renderer: Apply colors to glyphs/cells/connectors
end
CLI->>Helper: migrationGraphShowsLegend(options, flags)
Helper-->>CLI: true if --legend and not suppressed
alt Show Legend
CLI->>Legend: renderMigrationGraphLegend(opts)
Legend->>stderr: Emit legend (glyphs + palette)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
size-limit report 📦
|
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
packages/1-framework/3-tooling/cli/test/utils/formatters/migration-graph-tree-render.test.ts (1)
576-614: 💤 Low valueExtract the duplicated convergence-fan edge setup into a helper.
The same 7-edge fan graph (
init…mergeAvatar) is built inline here and again at lines 596-603 and 654-660. AconvergenceFanEdges()helper would mirror the existingdiamondEdges()/skipArcEdges()pattern in this suite and keep the three tests focused on assertions.♻️ Proposed helper
+ function convergenceFanEdges(): readonly MigrationEdge[] { + const init = edge(EMPTY_CONTRACT_HASH, 'ef9de27', 'init'); + const addPhone = edge('ef9de27', '73e3abe', 'add_phone'); + const addPosts = edge('ef9de27', 'a94b7b4', 'add_posts'); + const addAvatar = edge('ef9de27', '6656a6e', 'add_avatar'); + const mergePhone = edge('73e3abe', '3116048', 'merge_phone'); + const mergePosts = edge('a94b7b4', '3116048', 'merge_posts'); + const mergeAvatar = edge('6656a6e', '3116048', 'merge_avatar'); + return [init, addPhone, addPosts, addAvatar, mergePhone, mergePosts, mergeAvatar]; + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/1-framework/3-tooling/cli/test/utils/formatters/migration-graph-tree-render.test.ts` around lines 576 - 614, Extract the repeated 7-edge fan graph into a new helper convergenceFanEdges() that returns the array of edges currently built inline (using edge(EMPTY_CONTRACT_HASH, 'ef9de27', 'init') ... mergeAvatar), mirror the style of existing helpers like diamondEdges() and skipArcEdges(); then replace the inline edge array arguments in the tests that call tree([...], { colorize: true }) with convergenceFanEdges() and keep the rest of the assertions (references: functions/values edge, tree, laneColorForColumn and the tests that assert on fanLine and hues).packages/1-framework/3-tooling/cli/src/utils/formatters/migration-graph-tree-render.ts (1)
538-543: 💤 Low valueStatic analysis false positive —
ANSI_ESCAPEis a compile-time constant.The flagged pattern is safe:
ANSI_ESCAPE(line 538) is a literal'\x1b', not runtime/user input. The resulting regex has no overlapping quantifiers that could cause catastrophic backtracking.Minor note: the
RegExpis instantiated on every call. Hoisting it to module scope would avoid the repeated construction, but this is a non-hot rendering path so it's negligible.♻️ Optional: hoist the regex to module scope
const ANSI_ESCAPE = '\x1b'; +const TRAILING_SPACE_BEFORE_RESET = new RegExp(`[\\t ]+((?:${ANSI_ESCAPE}\\[[0-9;]*m)+)$`); function trimTrailingWhitespace(line: string): string { - const trailingSpaceBeforeReset = new RegExp(`[\\t ]+((?:${ANSI_ESCAPE}\\[[0-9;]*m)+)$`); - return line.replace(trailingSpaceBeforeReset, '$1').replace(/\s+$/, ''); + return line.replace(TRAILING_SPACE_BEFORE_RESET, '$1').replace(/\s+$/, ''); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/1-framework/3-tooling/cli/src/utils/formatters/migration-graph-tree-render.ts` around lines 538 - 543, The static analyzer warning is a false positive; to silence it and avoid reconstructing the regex on every call, hoist the dynamically-built RegExp out of trimTrailingWhitespace into module scope: create a module-level constant (e.g., TRAILING_SPACE_BEFORE_RESET) constructed once using the existing ANSI_ESCAPE and the same pattern, then update trimTrailingWhitespace to use that constant instead of creating new RegExp each call; keep the replacement logic identical and retain the ANSI_ESCAPE const and function name trimTrailingWhitespace.packages/1-framework/3-tooling/cli/test/commands/migration-graph.test.ts (1)
64-64: 💤 Low valueConsider including
glyphModeparameter for consistency with command usage.The command invokes
renderMigrationGraphLegend({ colorize, glyphMode })(lines 95-98 in migration-graph.ts), but this test calls it with only{ colorize: false }. While the test's primary focus is routing behavior (stderr vs. stdout), including theglyphModeparameter would better mirror production usage and avoid potential type errors ifglyphModebecomes required.♻️ Suggested update
- ui.stderr(renderMigrationGraphLegend({ colorize: false })); + ui.stderr(renderMigrationGraphLegend({ colorize: false, glyphMode: ui.resolveGlyphMode(false) }));🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/1-framework/3-tooling/cli/test/commands/migration-graph.test.ts` at line 64, The test calls renderMigrationGraphLegend with only { colorize: false } but production usage passes both colorize and glyphMode; update the test invocation in migration-graph.test.ts to include glyphMode (e.g., renderMigrationGraphLegend({ colorize: false, glyphMode })) so the call signature matches renderMigrationGraphLegend in migration-graph.ts and prevents future type/behavior mismatches; ensure glyphMode value mirrors the command usage or test default used elsewhere in the file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@packages/1-framework/3-tooling/cli/src/utils/formatters/migration-graph-tree-render.ts`:
- Around line 538-543: The static analyzer warning is a false positive; to
silence it and avoid reconstructing the regex on every call, hoist the
dynamically-built RegExp out of trimTrailingWhitespace into module scope: create
a module-level constant (e.g., TRAILING_SPACE_BEFORE_RESET) constructed once
using the existing ANSI_ESCAPE and the same pattern, then update
trimTrailingWhitespace to use that constant instead of creating new RegExp each
call; keep the replacement logic identical and retain the ANSI_ESCAPE const and
function name trimTrailingWhitespace.
In `@packages/1-framework/3-tooling/cli/test/commands/migration-graph.test.ts`:
- Line 64: The test calls renderMigrationGraphLegend with only { colorize: false
} but production usage passes both colorize and glyphMode; update the test
invocation in migration-graph.test.ts to include glyphMode (e.g.,
renderMigrationGraphLegend({ colorize: false, glyphMode })) so the call
signature matches renderMigrationGraphLegend in migration-graph.ts and prevents
future type/behavior mismatches; ensure glyphMode value mirrors the command
usage or test default used elsewhere in the file.
In
`@packages/1-framework/3-tooling/cli/test/utils/formatters/migration-graph-tree-render.test.ts`:
- Around line 576-614: Extract the repeated 7-edge fan graph into a new helper
convergenceFanEdges() that returns the array of edges currently built inline
(using edge(EMPTY_CONTRACT_HASH, 'ef9de27', 'init') ... mergeAvatar), mirror the
style of existing helpers like diamondEdges() and skipArcEdges(); then replace
the inline edge array arguments in the tests that call tree([...], { colorize:
true }) with convergenceFanEdges() and keep the rest of the assertions
(references: functions/values edge, tree, laneColorForColumn and the tests that
assert on fanLine and hues).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: a3f4c7dc-21c7-4d94-81d8-47d224a7a244
⛔ Files ignored due to path filters (8)
projects/migration-graph-rendering/README.mdis excluded by!projects/**projects/migration-graph-rendering/decisions.mdis excluded by!projects/**projects/migration-graph-rendering/mockups.mdis excluded by!projects/**projects/migration-graph-rendering/slices/lane-colors-and-legend/spec.mdis excluded by!projects/**projects/migration-graph-rendering/slices/ledger-foundation/spec.mdis excluded by!projects/**projects/migration-graph-rendering/slices/list-renders-tree/spec.mdis excluded by!projects/**projects/migration-graph-rendering/slices/migration-graph-space-flag/spec.mdis excluded by!projects/**projects/migration-graph-rendering/slices/remove-list-graph-renderer/spec.mdis excluded by!projects/**
📒 Files selected for processing (6)
docs/reference/migration-graph-rendering.mdpackages/1-framework/3-tooling/cli/src/commands/migration-graph.tspackages/1-framework/3-tooling/cli/src/utils/formatters/migration-graph-lane-colors.tspackages/1-framework/3-tooling/cli/src/utils/formatters/migration-graph-tree-render.tspackages/1-framework/3-tooling/cli/test/commands/migration-graph.test.tspackages/1-framework/3-tooling/cli/test/utils/formatters/migration-graph-tree-render.test.ts
Folds in the cross-cutting design decisions for the migration read-command family (list / graph / status / log) and the ledger foundation that status and log depend on: - decisions.md: D1-D10 (command-family model, shared renderer, space policy B, list/graph split, list->tree, ledger foundation, log, status reframe with --from/--to, and where path/invariants live). - New slice specs: migration-graph-space-flag (TML-2767), list-renders-tree (TML-2768). - README: full slice list incl. ledger (TML-2769), status (TML-2748), log (TML-2770) and the future siblings (TML-2771, TML-2772). Signed-off-by: Will Madden <[email protected]>
Investigation found the on-apply ledger records one collapsed row per space-apply (not per migration) and the three target schemas have diverged (PG/SQLite lack a space column; Mongo lacks operations). status and log both need one row per migration edge, so the foundation slice is a restructure into a per-edge journal (space + name + hash per row), not an additive field bump. - New slice spec: slices/ledger-foundation/spec.md. - decisions.md D7 rewritten to the per-migration-journal restructure. Signed-off-by: Will Madden <[email protected]>
Per-column rotating hues replace flat dim gutter styling when colorize is on; node markers and direction arrows stay bright. Plain output is unchanged when colorize is false. Signed-off-by: Will Madden <[email protected]>
--legend prints a palette- and color-aware key for the --tree visual language (node marker, direction arrows, empty baseline, data arrow, (refs) overlay, and the rotating per-column lane palette). It prints to stderr alongside the command header, implies --tree, and is suppressed under --json / --dot / --quiet. Reuses the D1 lane-color helpers. Signed-off-by: Will Madden <[email protected]>
Color each routed back-arc in one hue (its owning back-lane), keeping crossings neutral; leave the leftmost lane (column 0) uncolored so the common linear graph reads monochrome; and color the contract node glyph by its lane while direction arrows stay bright. Signed-off-by: Will Madden <[email protected]>
…-2773) Add the in-project slice spec (chosen design, dispatch plan, and the operator-confirmed color refinements: per-arc single hue, neutral leftmost lane, node glyph colored by lane), link it from the project README, and record the colored-lane extension to the locked visual language in mockups.md. Signed-off-by: Will Madden <[email protected]>
…ML-2773) Forward branch/merge connector runs (├─┬─╮, ├───╯) rendered each cell by its pass-through column, so a fork or merge spine read as gray-then-per-column rather than as one line. Resolve each connector cell to the lane it serves: corners and intermediate tees own their column, while the leading tee and horizontal segments inherit the nearest branch point to their right, so a run into a branch — or collapsing into a merge corner — is a single hue end-to-end. Vertical lanes, node glyphs, arrows, routed back-arcs, neutral crossings, and column-0 neutrality are unchanged. Signed-off-by: Will Madden <[email protected]>
A routed back-arc's horizontal bridge cells (─ segments and the source-tee ○─ connector) already took the arc's owning-lane hue, but its ┼ arc-crossing cells stayed dim — so the run read as one hue broken by gray gaps. A crossing can only be one colour and is unavoidably wrong for one of the two crossing lines, so leaving it dim is wrong for both; color it the arc owning the horizontal run (the nearest corner to its right) instead. The crossed forward-vertical lane is simply occluded at that one cell and reappears on the next row, and the whole arc run now reads as one continuous colour. Crossings, bridges, corners, and node-by-lane otherwise unchanged. Signed-off-by: Will Madden <[email protected]>
…-2773) Three colorized-output refinements to the migration graph tree. A branch connector tee's trailing `─` now takes the hue of the branch on its right (the lane it leads into) rather than the tee's own left lane, so a `┬─` reads "this lane, then onward". Direction arrows (↑ ↓ ⟲) and the migration name now take their edge's lane hue instead of staying bright/bold, so a branched row reads in one branch colour; column-0 edges keep their default styling, so a linear chain stays uncoloured. Plain (colorize:false) output is byte-identical, and node-by-lane, vertical lanes, routed-arc hue, and legend are unchanged. Signed-off-by: Will Madden <[email protected]>
A branched edge name (lane >= 1) took on its lane colour but lost its bold in the colorized tree. Compose a forced bold with the lane hue so the name renders bold AND coloured, matching the lane and arrow it sits with; column-0 names keep their default bold-only styling. Arrows stay lane-coloured (not bold). Plain-text output is unchanged. Refs TML-2773 Signed-off-by: Will Madden <[email protected]>
Tighten the --tree legend per review: drop "node" from the contract
marker, spell out self-edges as "migration without schema change", call
the empty source an "empty database (baseline)", and trim the (refs)
line to "db / contract markers". Remove the data-column "from -> to"
entry and the rotating lane sample, and add a worked hash-arrow sample
("aaaaaa -> bbbbbb migration from contract aaaaaa to bbbbbb"). Spread
the entries over several lines and emit a trailing blank line so the
stderr key is visibly separated from the graph on stdout. The colorize
gate and glyph-mode honoring are unchanged.
Refs TML-2773
Signed-off-by: Will Madden <[email protected]>
8fbb5e0 to
60edee5
Compare
Summary
Makes
migration graph --treeoutput readable in color and adds an optional--legendkey (TML-2773).○) colored by their lane.┼arc-crossings (which take the owning arc's hue rather than gray).┬─tee the trailing dash takes the right-hand branch's color.↑↓⟲) and migration names inherit their edge's lane hue; branched names stay bold as well as colored.--legend: opt-in key explaining the glyphs/colors; auto-enables--tree.Plain-text output (
--no-color/ non-TTY) is byte-identical to before — all coloring resolves to the identity styler when colorize is off, so existing goldens are untouched.Commits
2d254bebecolor tree lanes by column5a99b3001add--legendkeya6d58d566refine lane colors (per-arc single hue, column-0 neutral, node-by-lane)11dd7fd2acolor forward connectors by served lane78f9a4dcbcolor routed back-arc crossings with the arc huebe90398bacolor branch arrows, names, and┬─dashes by branch36d374c6ckeep branched names bold under their lane hueTest plan
pnpm --filter @prisma-next/cli typecheckpnpm --filter @prisma-next/cli test— formatter + migration-graph suites green (39/39 targeted)--tree+--legendin a real TTYSummary by CodeRabbit
New Features
--legendflag to the migration graph command; legend implies tree rendering and is suppressed for JSON/DOT/quiet modes.Documentation
Tests