Repository navigation
TML-2836: one consistent, schema-locked --json shape for the migration read commands - #741
Conversation
…/toContract/current+targetContract) (D1) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Will Madden <[email protected]>
- Add src/commands/json/schemas.ts with migrationEntrySchema, contractRefSchema, successEnvelopeBaseSchema, migrationSpaceListEntrySchema, migrationListResultSchema - MigrationListEntry/MigrationSpaceListEntry/MigrationListResult in migration-list-types.ts are now re-exported from the arktype schemas (schema is the single source of truth) - Rename MigrationListEntry.migrationHash → .hash to match the spec JSON target shape; update all construction sites and readers (migration-list.ts, migration-list-render.ts, migration-list-graph-topology.ts, migration-status.ts) and all affected tests - Fix output.json-shapes.test.ts broken by D1 rename (currentContract/space/targetContract) - migration-list-json-golden.test.ts now validates real list --json output against the exported migrationListResultSchema (schema parse must not return ArkErrors) Co-Authored-By: Will Madden <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Will Madden <[email protected]>
- Rename SerializedLedgerEntryRecord.migrationName → name, migrationHash → hash
- Rename MigrationLogResult.entries → records, add summary field
- Add ledgerRecordSchema and migrationLogResultSchema to json/schemas.ts
- Derive MigrationLogResult from the schema (single source of truth)
- serializeLedgerEntriesForJson emits {name, hash} field names
- Tests validate against migrationLogResultSchema; empty case covered
- Parity test type-shape lock updated for new records/summary shape
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ract fix (D8) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ew + drive trace Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThis PR centralizes JSON schema contracts for all CLI migration-command outputs (list, graph, status, log, show, check) by creating a new ChangesMigration CLI JSON Schema Centralization and Type Refactoring
Sequence Diagram(s)sequenceDiagram
participant Cmd as migration_check
participant Helper as integrity_helpers
participant Mapper as violation_mapper
participant Output as cli_output
Cmd->>Helper: run check helpers with spaceId
Helper->>Mapper: map IntegrityViolation
Mapper-->>Helper: CheckFailure(code, space, where, why, fix)
Helper-->>Cmd: failures[]
Cmd->>Output: print failure code labels
sequenceDiagram
participant List as migration_list
participant Agg as aggregate
participant Build as entry_builder
participant Format as formatter
List->>Agg: load spaces and migration packages
Agg-->>Build: packages per space
Build->>Build: map to name hash fromContract toContract
Build-->>List: normalized entries
List->>Format: renderMigrationListWithStyle
Format->>Format: graphForSpace(space.space)
Format->>Format: buildEdgeAnnotations(entry.hash)
Format-->>List: rendered tree output
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
|
@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: |
size-limit report 📦
|
--json shape for the migration read commands
--json shape for the migration read commandsThere was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/1-framework/3-tooling/cli/src/commands/json/schemas.ts (1)
78-101: ⚡ Quick win
missingInvariantsDiagnosticSchemais inconsistent (noseverity) with the other diagnostic variants
packages/1-framework/3-tooling/cli/src/commands/json/schemas.tsdefinesseverityforCONTRACT.UNREADABLEandMIGRATION.MARKER_NOT_IN_HISTORY, butMIGRATION.MISSING_INVARIANTSomits it. No downstream usage ofdiagnostic.severitywas found inpackages/1-framework/3-tooling/cli/, so CLI rendering is unaffected; either addseverityfor a uniform union or document that consumers must narrow bycodebefore readingseverity.🤖 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/commands/json/schemas.ts` around lines 78 - 101, The union variant missingInvariantsDiagnosticSchema lacks the severity property present on contractUnreadableDiagnosticSchema and markerNotInHistoryDiagnosticSchema; update missingInvariantsDiagnosticSchema to include a severity: '"warn" | "info"' field (matching the other schemas) so statusDiagnosticSchema is a consistent discriminated union, or alternatively add a comment/docstring on missingInvariantsDiagnosticSchema explaining consumers must narrow by code before accessing severity—preferably add the severity field to missingInvariantsDiagnosticSchema for uniformity.
🤖 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.
Inline comments:
In
`@packages/1-framework/3-tooling/cli/test/commands/migration-read-commands-parity.test.ts`:
- Around line 1059-1099: The test builds a failing migration-check result with
runMigrationCheck(...) but never invokes the CLI to assert a non-zero exit;
update the test to actually run the check command via
executeCommand(createMigrationCheckCommand(), ['--json']) (use
setupCommandMocks()/cleanup like the list case), capture and parse the CLI JSON
output (as you do for listOutput) and assert that the parsed ok is false and
that the exit code is non-zero; keep the existing runMigrationCheck usage for
inspecting structure but add the executeCommand call and assertions against its
exit code and JSON output to cover the CLI path.
In `@packages/1-framework/3-tooling/cli/test/commands/migration-status.test.ts`:
- Around line 127-131: The test teardown is only calling vi.clearAllMocks(),
which does not restore spies like vi.spyOn(configLoader, 'loadConfig') to their
original implementations; update the afterEach in migration-status.test.ts (the
teardown block containing afterEach) to call vi.restoreAllMocks() (either
replace or add alongside vi.clearAllMocks()) so any spies are fully restored
between tests and prevent cross-test leakage.
---
Nitpick comments:
In `@packages/1-framework/3-tooling/cli/src/commands/json/schemas.ts`:
- Around line 78-101: The union variant missingInvariantsDiagnosticSchema lacks
the severity property present on contractUnreadableDiagnosticSchema and
markerNotInHistoryDiagnosticSchema; update missingInvariantsDiagnosticSchema to
include a severity: '"warn" | "info"' field (matching the other schemas) so
statusDiagnosticSchema is a consistent discriminated union, or alternatively add
a comment/docstring on missingInvariantsDiagnosticSchema explaining consumers
must narrow by code before accessing severity—preferably add the severity field
to missingInvariantsDiagnosticSchema for uniformity.
🪄 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: 1d3ceec6-ab75-450e-9813-7fb31890cc1c
⛔ Files ignored due to path filters (4)
projects/migration-graph-rendering/slices/read-command-json-redesign/code-review.mdis excluded by!projects/**projects/migration-graph-rendering/slices/read-command-json-redesign/plan.mdis excluded by!projects/**projects/migration-graph-rendering/slices/read-command-json-redesign/spec.mdis excluded by!projects/**projects/migration-graph-rendering/trace.jsonlis excluded by!projects/**
📒 Files selected for processing (32)
packages/1-framework/3-tooling/cli/src/commands/json/schemas.tspackages/1-framework/3-tooling/cli/src/commands/migration-check.tspackages/1-framework/3-tooling/cli/src/commands/migration-graph.tspackages/1-framework/3-tooling/cli/src/commands/migration-list.tspackages/1-framework/3-tooling/cli/src/commands/migration-log.tspackages/1-framework/3-tooling/cli/src/commands/migration-show.tspackages/1-framework/3-tooling/cli/src/commands/migration-status.tspackages/1-framework/3-tooling/cli/src/utils/formatters/migration-list-graph-topology.tspackages/1-framework/3-tooling/cli/src/utils/formatters/migration-list-render.tspackages/1-framework/3-tooling/cli/src/utils/formatters/migration-list-types.tspackages/1-framework/3-tooling/cli/src/utils/formatters/migration-log-table.tspackages/1-framework/3-tooling/cli/src/utils/formatters/migrations.tspackages/1-framework/3-tooling/cli/src/utils/integrity-violation-to-check-failure.tspackages/1-framework/3-tooling/cli/test/commands/cross-consumer-integrity.test.tspackages/1-framework/3-tooling/cli/test/commands/format-status-summary.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-check-multi-space-command.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-check-multi-space.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-check-single-target-multi-space.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-graph.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-list-json-golden.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-list.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-log.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-read-commands-parity.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-show.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-status.test.tspackages/1-framework/3-tooling/cli/test/commands/read-commands-json-golden.test.tspackages/1-framework/3-tooling/cli/test/output.json-shapes.test.tspackages/1-framework/3-tooling/cli/test/utils/formatters/migration-list-graph-topology.test.tspackages/1-framework/3-tooling/cli/test/utils/formatters/migration-list-render.test.tspackages/1-framework/3-tooling/cli/test/utils/formatters/migration-list-styler.test.tspackages/1-framework/3-tooling/cli/test/utils/formatters/migration-log-table.test.tstest/integration/test/cli-journeys/migration-check.e2e.test.ts
…shape (CI fix) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…bbit (restore spies, assert real check exit code) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Will Madden <[email protected]>
The decision: the six migration read commands —
list,graph,status,log,show,check— now emit--jsonin one shared, self-describing vocabulary, and each command's shape is defined by an arktype schema that its TypeScript type is derived from. Read one command's output and you can read them all; validate any of them at runtime against its exported schema.At a glance
migration graph --json, before and after:The same naming now runs through every command: a migration's name is
name(wasdirName, andmigrationNameinlog); its own identifier ishash(wasmigrationHash); the contracts it moves between arefromContract/toContract(wasfrom/to, andnullat the first migration in every command); and the contract space isspace(wasspaceId).Why
The read commands grew their JSON shapes one at a time, so the same idea ended up with three different names — a migration was
dirNamein some commands andmigrationNamein others; a space wasspaceIdhere andspacethere — andgraphleaned on the consumer already knowing the model (that nodes meant contracts and edges meant migrations). Nothing was wrong, but a tool reading the output couldn't reuse a single parser across commands, and the field names taught the reader nothing on their own.The reader we care about most is an AI agent: it sees
--jsonby default. So the goal here is output an agent can both parse mechanically and understand at a glance — structured fields as the source of truth, a plain-Englishsummaryalongside them, and names that describe what they point at without outside knowledge.What changed, command by command
Each command applies that one decision to its own data:
list— migrations grouped underspaces[], each migration carrying the shared fields above.graph— the before/after above:nodes/edgesbecame self-describingcontracts+migrations, grouped by space instead of one flat global list.status— per-spacecurrentContract/targetContract(wasmarkerHash/targetHash), and its diagnostics are now structured objects ({ code, …, message }) rather than English sentences a tool would have to scrape.log— returns ledgerrecords(wasentries): these are apply events, not migration definitions, so they read as a record stream.show— dropped a leaked filesystem path (dirPath) and a redundant inner summary; one top-levelsummarynow.check— each failure is{ space, code, where, why, fix }, the same vocabulary our structured errors already use.Two rules tie it together.
okalways mirrors the exit code, so a consumer branches on it the same way everywhere — includingcheck, which returnsok: false(exit 4) when it finds integrity problems, distinguishable from a usage error by carryingfailuresinstead of a top-level errorcode. And the shape nests by space only where a command actually holds per-space state (list,graph,status);logandcheckstay flat with aspacetag on each item, because forcinglog's time-ordered history into per-space groups would destroy the chronology that is its whole point.How the shape is held in place
Each command's
--jsonshape lives as an exported arktype schema insrc/commands/json/schemas.ts, and the command's result type is derived from that schema — so the shape and the schema cannot drift apart. A cross-command parity test validates every command's real output against its schema and asserts the consistency rules directly: no retired field name reappears,fromContractisnull(never a sentinel) at the first migration,okmatches the exit code, and the nest-vs-flat rule holds.Out of scope
The shared error envelope (we aligned
checkto it rather than change it), the human-readable (non-JSON) output, and command behaviour/flags are all untouched. No new flags.Alternatives considered
passedfield oncheckinstead of overloadingok. Rejected: tyingokto the exit code gives one rule a consumer applies everywhere, andfailures-vs-codealready disambiguates the twook: falsecases.logis a time-ordered stream andstatus/graphcarry real per-space state — a single structure fights one or the other, so structure follows the data.summaryfrom the JSON as decoration. Rejected: the JSON's main reader is an agent, and a one-line human summary earns its place next to the structured fields.{ hash, refs }, so a contract carries the names pointing at it and self-describes.Note for CI
The full
@prisma-next/clisuite passes (1225 tests). There is a pre-existing order-dependent flake inmigration-list-json-golden.test.ts(aprocess.chdirinteraction under the package'sisolate: falsevitest) that also reproduces on the base branch and passes in a clean run — not introduced here.Closes TML-2836.
🤖 Generated with Claude Code
Summary by CodeRabbit