Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughReplaces top-level migration identifier Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI Command
participant IO as readMigrationPackage (disk)
participant Hash as verifyMigrationHash
participant Runner as MigrationRunner
CLI->>IO: load migration package (migration.json + ops.json)
IO->>Hash: computeMigrationHash(metadata, ops)
Hash-->>IO: ok / mismatch (storedHash vs computedHash)
alt ok
IO-->>CLI: MigrationPackage(metadata, ops)
CLI->>Runner: execute migrations (uses metadata.from/to)
Runner-->>CLI: progress / result
else mismatch
IO-->>CLI: throw MIGRATION.HASH_MISMATCH error (dir, storedHash, computedHash)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/middleware-telemetry
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@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/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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/1-framework/3-tooling/cli/src/commands/migration-status.ts (1)
159-171:⚠️ Potential issue | 🟠 MajorTrack edge status by migration identity, not just endpoints.
assignedKeyscurrently collapses parallel migrations that share the samefrom/to. After this refactor, those edges are distinct bymigrationHash, so one package can hide another package’s status in the rendered result.Suggested fix
- const edgeKey = (e: MigrationChainEntry) => `${e.from}\0${e.to}`; + const edgeKey = (e: MigrationChainEntry) => 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` around lines 159 - 171, assignedKeys currently collapses parallel MigrationChainEntry edges that share the same from/to by using edgeKey(e) = `${e.from}\0${e.to}`, which hides distinct migrations; update the identity key to include the migrationHash so edges are tracked by migration identity (e.g., change edgeKey to include e.migrationHash and use that key everywhere assignedKeys is populated/checked), and ensure any logic that constructs or compares edge keys for statuses (references to edgeKey, assignedKeys, and the MigrationChainEntry shape) uses the new three-part key so parallel migrations are rendered separately.
🧹 Nitpick comments (1)
packages/1-framework/3-tooling/migration/test/fixtures.ts (1)
49-58: Keep the “attested package” helpers hash-safe.Both helpers promise a computed, internally consistent
migrationHash, butmetadataOverridescan still smuggle in a custom hash throughcreateTestMetadata(). That makes it easy for unrelated tests to create corrupt fixtures accidentally instead of via the explicit post-write tamper step.Suggested tightening
export function createAttestedPackage( dirName: string, - metadataOverrides: Partial<MigrationMetadata> = {}, + metadataOverrides: Omit<Partial<MigrationMetadata>, 'migrationHash'> = {}, ops: MigrationOps = createTestOps(), ): MigrationPackage {export async function writeTestPackage( dir: string, - metadataOverrides: Partial<MigrationMetadata> = {}, + metadataOverrides: Omit<Partial<MigrationMetadata>, 'migrationHash'> = {}, ops: MigrationOps = createTestOps(), ): Promise<{ metadata: MigrationMetadata; ops: MigrationOps }> {Also applies to: 85-91
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/migration/test/fixtures.ts` around lines 49 - 58, The attested-package helpers (e.g., createAttestedPackage) must ensure the MigrationMetadata.migrationHash cannot be injected via metadataOverrides; after building metadata with createTestMetadata(metadataOverrides, ops) strip any provided migrationHash or recompute and set metadata.migrationHash deterministically from the resulting metadata/ops so the returned MigrationPackage always contains an internally consistent computed hash; apply the same fix to the companion helper at lines 85–91 so neither helper accepts an override that can smuggle in a custom migrationHash.
🤖 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-plan.ts`:
- Around line 489-492: The "Next" message emitted after writeMigrationPackage()
incorrectly instructs users to run migration.ts to emit ops.json and attest the
migrationHash; update the message built where lines.push(...) constructs that
template string (the block that currently contains `Next: ${green_(`node
${result.dir ?? '<dir>'}/migration.ts`)} ...`) to instead show the correct next
step for the non-placeholder flow (for example instruct to run `prisma-next
migration apply` directly or otherwise reflect that ops.json and migration.json
have already been written). Modify the template string generation in the
migration-plan code path that follows writeMigrationPackage() so it no longer
references running migration.ts and accurately describes the next action for the
already-written package.
---
Outside diff comments:
In `@packages/1-framework/3-tooling/cli/src/commands/migration-status.ts`:
- Around line 159-171: assignedKeys currently collapses parallel
MigrationChainEntry edges that share the same from/to by using edgeKey(e) =
`${e.from}\0${e.to}`, which hides distinct migrations; update the identity key
to include the migrationHash so edges are tracked by migration identity (e.g.,
change edgeKey to include e.migrationHash and use that key everywhere
assignedKeys is populated/checked), and ensure any logic that constructs or
compares edge keys for statuses (references to edgeKey, assignedKeys, and the
MigrationChainEntry shape) uses the new three-part key so parallel migrations
are rendered separately.
---
Nitpick comments:
In `@packages/1-framework/3-tooling/migration/test/fixtures.ts`:
- Around line 49-58: The attested-package helpers (e.g., createAttestedPackage)
must ensure the MigrationMetadata.migrationHash cannot be injected via
metadataOverrides; after building metadata with
createTestMetadata(metadataOverrides, ops) strip any provided migrationHash or
recompute and set metadata.migrationHash deterministically from the resulting
metadata/ops so the returned MigrationPackage always contains an internally
consistent computed hash; apply the same fix to the companion helper at lines
85–91 so neither helper accepts an override that can smuggle in a custom
migrationHash.
🪄 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: 54693dc9-f095-40a1-b139-65312577fe5c
📒 Files selected for processing (176)
examples/mongo-demo/migrations/20260409T1030_migration/migration.jsonexamples/mongo-demo/migrations/20260415_add-posts-author-index/migration.jsonexamples/mongo-demo/test/manual-migration.test.tsexamples/prisma-next-demo/migration-fixtures/complex/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260302T1000_alice_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260302T1100_bob_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260302T1200_staging_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260303T1000_merge_alice/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260303T1100_merge_bob/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260304T1000_add_comments/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260305T1000_add_tags/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1100_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1200_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1000_merge_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1100_merge_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1200_merge_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1000_alice_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1100_bob_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1200_bob_experiment/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1000_merge_alice/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1100_merge_bob/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1200_bob_experiment_2/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond/20260302T1000_alice_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond/20260302T1100_bob_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond/20260303T1000_merge_alice/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond/20260303T1100_merge_bob/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1100_widen_email/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260303T1000_email_default/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260304T1000_change_default/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260305T1000_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260306T1000_add_comments/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260307T1000_kitchen_sink/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260308T1000_rollback/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260326T1428_migration/migration.jsonexamples/prisma-next-demo/migration-fixtures/linear/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/linear/20260302T1000_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260304T1000_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260305T1000_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260306T1000_add_comments/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260307T1000_add_tags/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260307T1100_late_branch/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260308T1000_add_everything/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1100_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1200_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1430_migration/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_foobar/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_migration/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1432_foobar/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1100_staging/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260304T1000_add_comments/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260305T1000_add_tags/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260306T1000_rollback_to_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260304T1000_rollback_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260305T1000_rollback_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260306T1000_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback/20260304T1000_rollback_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback/20260305T1000_rollback_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1000_alice_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1100_bob_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1000_merge_1a/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1100_merge_1b/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1000_add_comments/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1100_add_posts_branch/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1000_merge_2a/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1100_merge_2b/migration.jsonexamples/prisma-next-demo/migration-fixtures/single-branch/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/single-branch/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/single-branch/20260302T1100_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/single-branch/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260304T1000_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260305T1000_rollback_to_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260306T1000_rollback_to_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/sub-branches/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1100_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1100_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1100_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1200_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1300_add_category/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1400_add_settings/migration.jsonexamples/prisma-next-demo/migrations/20260422T0720_initial/migration.jsonexamples/prisma-next-demo/migrations/20260422T0742_migration/migration.jsonexamples/prisma-next-demo/migrations/20260422T0748_migration/migration.jsonexamples/retail-store/migrations/20260413T0314_migration/migration.jsonexamples/retail-store/migrations/20260415_add-product-validation/migration.jsonexamples/retail-store/migrations/20260416_backfill-product-status/migration.jsonexamples/retail-store/test/manual-migration.test.tspackages/1-framework/1-core/framework-components/src/control-migration-types.tspackages/1-framework/3-tooling/cli/README.mdpackages/1-framework/3-tooling/cli/src/commands/migration-apply.tspackages/1-framework/3-tooling/cli/src/commands/migration-new.tspackages/1-framework/3-tooling/cli/src/commands/migration-plan.tspackages/1-framework/3-tooling/cli/src/commands/migration-ref.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/control-api/operations/migration-apply.tspackages/1-framework/3-tooling/cli/src/migration-cli.tspackages/1-framework/3-tooling/cli/src/utils/cli-errors.tspackages/1-framework/3-tooling/cli/src/utils/command-helpers.tspackages/1-framework/3-tooling/cli/src/utils/formatters/graph-migration-mapper.tspackages/1-framework/3-tooling/cli/src/utils/formatters/migrations.tspackages/1-framework/3-tooling/cli/test/commands/migration-apply.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-e2e.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-plan.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-ref.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-show.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.tspackages/1-framework/3-tooling/cli/test/control-api/client.test.tspackages/1-framework/3-tooling/cli/test/migration-cli.test.tspackages/1-framework/3-tooling/cli/test/output.json-shapes.test.tspackages/1-framework/3-tooling/cli/test/utils/graph-helpers.tspackages/1-framework/3-tooling/migration/README.mdpackages/1-framework/3-tooling/migration/package.jsonpackages/1-framework/3-tooling/migration/src/attestation.tspackages/1-framework/3-tooling/migration/src/dag.tspackages/1-framework/3-tooling/migration/src/errors.tspackages/1-framework/3-tooling/migration/src/exports/attestation.tspackages/1-framework/3-tooling/migration/src/exports/errors.tspackages/1-framework/3-tooling/migration/src/exports/graph.tspackages/1-framework/3-tooling/migration/src/exports/hash.tspackages/1-framework/3-tooling/migration/src/exports/io.tspackages/1-framework/3-tooling/migration/src/exports/metadata.tspackages/1-framework/3-tooling/migration/src/exports/package.tspackages/1-framework/3-tooling/migration/src/exports/types.tspackages/1-framework/3-tooling/migration/src/graph.tspackages/1-framework/3-tooling/migration/src/hash.tspackages/1-framework/3-tooling/migration/src/io.tspackages/1-framework/3-tooling/migration/src/metadata.tspackages/1-framework/3-tooling/migration/src/migration-base.tspackages/1-framework/3-tooling/migration/src/package.tspackages/1-framework/3-tooling/migration/src/types.tspackages/1-framework/3-tooling/migration/test/attestation.test.tspackages/1-framework/3-tooling/migration/test/dag.test.tspackages/1-framework/3-tooling/migration/test/fixtures.tspackages/1-framework/3-tooling/migration/test/hash.test.tspackages/1-framework/3-tooling/migration/test/io.test.tspackages/1-framework/3-tooling/migration/test/migration-base.test.tspackages/1-framework/3-tooling/migration/tsdown.config.tspackages/2-mongo-family/9-family/src/core/mongo-target-descriptor.tstest/integration/test/cli-journeys/data-transform-enum-rebuild.e2e.test.tstest/integration/test/cli-journeys/data-transform-not-null-backfill.e2e.test.tstest/integration/test/cli-journeys/data-transform-nullable-tightening.e2e.test.tstest/integration/test/cli-journeys/data-transform-type-change.e2e.test.tstest/integration/test/cli-journeys/migration-plan-details.e2e.test.tstest/integration/test/cli-journeys/mongo-migration.e2e.test.tstest/integration/test/cli.migration-apply.e2e.test.ts
💤 Files with no reviewable changes (5)
- packages/1-framework/3-tooling/migration/src/exports/attestation.ts
- packages/1-framework/3-tooling/migration/test/attestation.test.ts
- packages/1-framework/3-tooling/migration/src/exports/types.ts
- packages/1-framework/3-tooling/migration/src/types.ts
- packages/1-framework/3-tooling/migration/src/attestation.ts
|
Thanks for the review @coderabbitai. Responding to the two findings in your review body:
|
|
Tip For best results, initiate chat on the files or code changes.
Since you've flagged the underlying |
When `migration plan` succeeds without placeholders, `writeMigrationPackage` has already emitted ops.json + migration.json with a fully attested migrationHash, so the previous `Next: node <dir>/migration.ts to emit ops.json and attest migrationHash before running prisma-next migration apply` instruction was actively misleading: it told the user to repeat work the planner had already done. Replace with a direct pointer at `prisma-next migration apply`. The placeholder branch keeps its existing `Then run: node <dir>/migration.ts` instruction, which is correct (placeholders genuinely require a self-emit round-trip). Addresses CodeRabbit review on PR #384.
…lpers createAttestedPackage and writeTestPackage are documented to always produce internally-consistent (attested) packages — the migrationHash is computed over the exact (metadata, ops) that get returned/written. The metadataOverrides parameter was typed Partial<MigrationMetadata>, which let callers smuggle a custom migrationHash past createTestMetadata's `overrides.migrationHash ?? computeMigrationHash(...)` fallback and produce an inconsistent fixture without going through the explicit post-write tamper step the helpers are designed for. Tighten the override type to Omit<Partial<MigrationMetadata>, 'migrationHash'> on both helpers so accidental hash injection becomes a compile error. createTestMetadata stays as-is — hash.test.ts intentionally injects a migrationHash to verify computeMigrationHash ignores the existing field. Addresses CodeRabbit review on PR #384 (review body, fixtures.ts:49-58 + 85-91).
|
Thanks @coderabbitai. Going to leave the follow-up tracking decision to a human teammate — the |
|
Tip For best results, initiate chat on the files or code changes.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts (1)
519-523: Clarify resolver docs to say “target contract hash”.On Line 519 and Line 528, wording says generic “hash”, but implementation matches
metadata.to(contract target hash), notmetadata.migrationHash. Tightening wording avoids future misuse.✏️ Suggested doc wording update
- * Resolve a migration package by exact hash or prefix match. + * Resolve a migration package by target contract hash (`metadata.to`) using + * exact match or prefix match. @@ - * the needle omits the scheme). Returns the matched package on success, or a + * the needle omits the scheme). Returns the matched package on success, or aAlso applies to: 528-537
🤖 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-plan.ts` around lines 519 - 523, Update the resolver docs that currently say “hash” to explicitly say “target contract hash” (i.e., the contract target stored in metadata.to) so the comments match the implementation which matches metadata.to rather than metadata.migrationHash; change the two doc blocks around the migration package resolver in migration-plan.ts (the comment starting “Resolve a migration package by exact hash or prefix match” and the later block covering lines ~528-537) to use the phrase “target contract hash” and briefly note that the resolver matches metadata.to (prefix/exact with optional auto-prepended sha256:) to avoid future confusion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts`:
- Around line 519-523: Update the resolver docs that currently say “hash” to
explicitly say “target contract hash” (i.e., the contract target stored in
metadata.to) so the comments match the implementation which matches metadata.to
rather than metadata.migrationHash; change the two doc blocks around the
migration package resolver in migration-plan.ts (the comment starting “Resolve a
migration package by exact hash or prefix match” and the later block covering
lines ~528-537) to use the phrase “target contract hash” and briefly note that
the resolver matches metadata.to (prefix/exact with optional auto-prepended
sha256:) to avoid future confusion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 62ba2426-62a8-4a37-9fbb-5d6bfea37a8f
📒 Files selected for processing (2)
packages/1-framework/3-tooling/cli/src/commands/migration-plan.tspackages/1-framework/3-tooling/migration/test/fixtures.ts
When `migration plan` succeeds without placeholders, `writeMigrationPackage` has already emitted ops.json + migration.json with a fully attested migrationHash, so the previous `Next: node <dir>/migration.ts to emit ops.json and attest migrationHash before running prisma-next migration apply` instruction was actively misleading: it told the user to repeat work the planner had already done. Replace with a direct pointer at `prisma-next migration apply`. The placeholder branch keeps its existing `Then run: node <dir>/migration.ts` instruction, which is correct (placeholders genuinely require a self-emit round-trip). Addresses CodeRabbit review on PR #384.
…lpers createAttestedPackage and writeTestPackage are documented to always produce internally-consistent (attested) packages — the migrationHash is computed over the exact (metadata, ops) that get returned/written. The metadataOverrides parameter was typed Partial<MigrationMetadata>, which let callers smuggle a custom migrationHash past createTestMetadata's `overrides.migrationHash ?? computeMigrationHash(...)` fallback and produce an inconsistent fixture without going through the explicit post-write tamper step the helpers are designed for. Tighten the override type to Omit<Partial<MigrationMetadata>, 'migrationHash'> on both helpers so accidental hash injection becomes a compile error. createTestMetadata stays as-is — hash.test.ts intentionally injects a migrationHash to verify computeMigrationHash ignores the existing field. Addresses CodeRabbit review on PR #384 (review body, fixtures.ts:49-58 + 85-91).
c011a52 to
5baddd5
Compare
…y verification Capture the design + execution plan for hoisting the apply-time migrationHash integrity check out of the CLI 'migration apply' loop and into the on-disk loader (readMigrationPackage), so every consumer inherits package-integrity verification at the load boundary. The spec also bundles a vocabulary + structure cleanup landing in the same PR: rename migrationId -> migrationHash, MigrationBundle -> MigrationPackage, MigrationManifest -> MigrationMetadata, split the dumping-ground types.ts into one file per concept, rename attestation.ts -> hash.ts, and codemod the 113 on-disk migration.json files (safe because computeMigrationHash strips the field before hashing). Plan sequences integrity behavior (Phases 1-3) before rename + restructure (Phases 4-6) so each phase has a clear review frame.
readMigrationPackage now performs hash verification after structural validation and throws MIGRATION.BUNDLE_CORRUPT on mismatch. The attestation primitive (verifyMigrationBundle) is reused, so the on-disk load boundary is the single point where every consumer (CLI commands, the future in-process apply path, the control client) inherits package-integrity verification by construction. readMigrationsDir inherits this transitively: any tampered child causes the directory enumeration to throw with the offending dir path in details. The convenience wrapper verifyMigration(dir) is removed since it is now strictly redundant with readMigrationPackage; verifyMigrationBundle remains the public in-memory primitive with an unchanged shape (and the storedMigrationId/computedMigrationId fields are tightened from optional to required to reflect the runtime invariant). Phase 1 of TML-2264. The CLI loop deletion in migration-apply.ts and the JSDoc invariants on the runner SPI are deferred to Phase 2. Refs TML-2264.
…ize bundle-corrupt path Address review-round-1 code findings on TML-2264 Phase 1. F01: Add `writeAttestedTestPackage(dir, manifestOverrides?, ops?)` helper to `migration-tools/test/fixtures.ts`. The previous fixture API required every caller to thread the same `ops` value through both `createTestManifest` (which seeds the `migrationId` hash) and `writeMigrationPackage` (which writes the file); forgetting to do so produced an internally inconsistent bundle that the post-Phase-1 verifying loader correctly rejects with `MIGRATION.BUNDLE_CORRUPT`. The new helper owns the threading, eliminating the silent foot-gun for happy-path tests. Migrate happy-path call sites in `io.test.ts` to use it; tampering tests keep the explicit two-step form because the corruption is the test`s point. Add an analogous local `writeAttestedPackage` helper to `migration-e2e.test.ts` (the CLI test cannot import `writeAttestedTestPackage` from migration-tools test fixtures across packages). F08: Render a `cwd`-relative path in the `errorBundleCorrupt` `why` and `fix` template strings (via `pathe.relative(process.cwd(), dir)`), keeping the absolute path in `details.dir` for machine consumers. Users typically run CLI commands from the project root and expect short relative paths in diagnostics; without this fix, post-Phase-2 (when the CLI loop is removed) `migration apply` would surface the absolute path instead of the friendlier relative path the existing CLI loop produces today. Extend the existing tampering tests in `io.test.ts` to assert the relative path appears in `why` and `fix`, and that `details.dir` is still the absolute path. Refs TML-2264.
Address review-round-1 planning-artifact findings. F02: Spec/plan now state explicitly that `MigrationOps` lives in `package.ts` (alongside `MigrationPackage`) after the Phase 4 file split. A package contains ops, so the type belongs with the package definition, not in `metadata.ts` (which is about the manifest envelope) or a new `ops.ts`. Update spec § File layout + Changes 7 and plan "Where we are going" diagram + Phase 4 T4.2. F03: Spec § Non-functional requirements `Plane-clean` claim now acknowledges the JSDoc-only ripple into `framework-components` (1-core) added by Phase 2 T2.2. JSDoc-only changes do not introduce code-level cross-plane edges, but the prior wording omitted the package entirely and was inaccurate as written. F04: Plan now states explicitly that Phase 1 and Phase 2 must ship together as a commit pair on `main`. The intermediate state ships double-verification (the loader recomputes the hash; the still-present CLI loop also recomputes it) — the duplicated work is wasted, and a future test asserting on the loop`s `errorRuntime` shape vs. the loader`s `errorBundleCorrupt` shape would surface confusing divergence. A grep verified no such test exists today; the constraint is recorded proactively. Both Phase 1`s validation gate and Phase 2`s intro carry the note. F06: Move T2.4 (audit other on-disk loaders) from Phase 2 to a new pre-flight section before Phase 1. The audit verifies the spec`s load-bearing claim that `readMigrationPackage` is the only on-disk loader; if a non-loader path constructed a `MigrationPackage` from disk, Phase 1`s design would be insufficient. Sequencing the audit as a gate aligns the plan structure with its assumption. F07: Phase 3 T3.1-T3.4 still assert `MIGRATION.BUNDLE_CORRUPT` substring presence, but the new T3.5 explicitly asserts diagnostic text equality across all four commands (`expect(new Set(diagnosticTexts).size).toBe(1)`). Substring presence is a necessary but not sufficient condition for the spec`s "same human-readable diagnostic regardless of which command triggered the load" criterion — without the equality check, two commands could both contain the code while differing on the surrounding `why`/`fix` text. T3.6 and T3.7 are renumbered accordingly; the test-coverage matrix is updated to point the uniformity AC at T3.5 and the intact-package and lint:deps ACs at T3.6. Refs TML-2264.
…ackage helper Replace writeAttestedTestPackage / writeAttestedPackage with a single writeTestPackage that always produces an attested package. Rewrite tampering tests to call writeTestPackage then surgically overwrite the offending file (ops.json or migration.json), eliminating the inconsistent-fixture foot-gun (F01) and making each tampering case self-document which file is being corrupted. Also migrate migration-plan.test.ts away from the attestedManifest() + writeMigrationPackage() two-step foot-gun pattern by introducing a local writeTestPackage helper there too. After this, every remaining writeMigrationPackage test call site is either the helper definition itself or io.test.ts:DIR_EXISTS asserting on the writer, exactly the two cases that genuinely require the production utility. Capture the cross-package test-helper consolidation as a Phase 4/6 follow-up in plan.md Open items (F10) — the duplication is now visible across three files all naming the helper writeTestPackage. Refs: TML-2264
readMigrationPackage performs hash verification at the load boundary (Phase 1, commit 6aad313ff), so the per-bundle loop in cli/src/commands/migration-apply.ts is now redundant. Delete the loop and its verifyMigrationBundle import. Add JSDoc invariant notes on MigrationRunner.execute and executeMigrationApply documenting that their plan/pendingMigrations parameters are trusted input requiring upstream verification (typically via readMigrationPackage). Refs TML-2264 (Phase 2).
Phase 2's CLI loop deletion (commit f427fd6d3) made the "Defense in depth" paragraph at cli/README.md:1038 stale. Capture the rewrite explicitly under T6.2 so it doesn't fall through Phase 6's docs-refresh mandate, which is currently scoped to migration-tools/README.md only. Refs TML-2264.
Commit `bd19d89791` raised `timeouts.databaseOperation` on three flaky `client.emit()` tests but missed `passes declared source inputs to the provider`, which still uses the package-default 100ms timeout. Same mechanism (CPU contention under `pnpm -r test`), same fix, applied to the fourth site. Surfaced during TML-2264 Phase 2 review (incorrectly diagnosed as a filesystem-isolation issue; actually a timeout asymmetry).
Adds an integration test (`migration-tamper.test.ts`) that drives all four CLI commands which load migration packages — `migration apply`, `migration plan`, `migration status`, `migration show` — against a tampered fixture (valid `writeTestPackage` followed by a surgical `fs.writeFile` that appends a synthetic op to `ops.json`). Each command is asserted to surface MIGRATION.BUNDLE_CORRUPT (T3.1-T3.4); a final assertion proves the four user-visible diagnostic envelopes are byte-equal (T3.5), pinning the spec acceptance criterion that integrity failures render the same human-readable diagnostic regardless of which command triggered the load. `migration show` exercises the `readMigrationPackage` direct-call path, distinct from the `loadAllBundles`/`readMigrationsDir` path used by the other three; both reach the same `errorBundleCorrupt` site, so the uniformity assertion confirms both code paths converge on identical output. Tempdir paths are normalized to a stable `<TMP_DIR>` token before comparison so the four diagnostics are byte-equal across per-test fixture directories. Refs TML-2264 (Phase 3, T3.1-T3.5).
…yMigration Phase 1 of TML-2264 (commit 6aad313ff) folded `verifyMigration(dir)` into `readMigrationPackage`'s load boundary, but the `migration-plan-details.e2e.test.ts` Journey H assertion still imported the removed helper. Replace the call with `readMigrationPackage(pkgDir)` — a successful read is now proof of attestation, since any tamper would throw MIGRATION.BUNDLE_CORRUPT. Surfaced by Phase 3 validation (`pnpm test:integration`); not caught during Phase 1 because integration tests were not part of that phase's validation gate. Refs TML-2264 (Phase 1 follow-up).
Phase 3 T3.7 filed [TML-2316](https://linear.app/prisma-company/issue/TML-2316) ("Implement ADR 192 step 2: emit-drift detection for migration.ts") under WS4 / M11. Replace the placeholder "file a separate Linear issue" line in spec.md § Out of scope with the actual ticket reference, and add a matching entry to § References. Refs TML-2264 (Phase 3, T3.7).
Phase 3 review round 1 (F14) overrode the original deferral of the `migration new` tamper case. The motivator: when the user asks to *create* a new migration but the diagnostic surfaces an *existing* corrupt package, that UX is confusing on its face and deserves an explicit pin — not just by-construction coverage from T1.2 + the unified diagnostic. Add T3.8 as a 5th `it()` block in `migration-tamper.test.ts`, between T3.4 and T3.5, following the same co-located pattern. The test mounts the existing `setupTamperFixture`, drives `createMigrationNewCommand` (which calls `readMigrationsDir` to compute the `from` reference), and asserts non-zero exit + `MIGRATION.BUNDLE_CORRUPT` substring. The capture flows into the shared `diagnostics` collection so T3.5's set-equality assertion (`expect(new Set(canonical).size).toBe(1)` and the rendered-text twin) automatically extends to 5 commands. Bump the length assertion `expect(diagnostics).toHaveLength(4)` → `5`. `migration new` resolves the contract path off `config.contract.output` with a different default than the other commands (`contract.json` next to the config vs. `src/prisma/contract.json`); align the shared `setupConfigMock` by setting `contract.output` explicitly. For the other four tests this is a no-op (their resolver already lands on the same path); for `migration new` it lets the contract read succeed so the flow reaches `readMigrationsDir` where the integrity check fires. Schema-mock complexity surfaced as a separate finding: the bail-out at `readMigrationsDir` happens *before* `migration new` reaches any schema/planner work, so no extra mocking was needed beyond the existing `loadConfig` mock plus the `contract.output` alignment. The user-visible envelope shape (summary/code/why/fix/where) is identical across all five commands; uniformity holds. The structured `meta` payload still diverges — `migration apply`/`plan` carry `error.details` into meta while `migration status`/`new` drop them. That divergence is captured separately in the plan as a Phase 6 follow-up (F12 → T6.4) and does not affect T3.5 (which only checks the user-visible portion). All gates green: - `pnpm -F @prisma-next/cli test test/commands/migration-tamper.test.ts` — 6 tests pass (5 tamper + 1 equality). - `pnpm -F @prisma-next/cli test` — 531 tests pass. - `pnpm test:integration` — 518 tests pass. - `pnpm lint:deps` — 0 violations. Refs TML-2264 (Phase 3, F14).
… 6 T6.4 Phase 3 review captured F15 (`migration new` defaults to a different contract path than `migration apply / plan / status / show`) as a follow-up. F12 (the `mapMigrationToolsError` extraction) already lived in Phase 6 T6.4. Both touch the same two files (`migration-status.ts`, `migration-new.ts`) and share the same "fold inline code into the shared helper" pattern, so they land in one task. This is a Phase 3 close-out artifact recorded in this branch but not committed before Phase 4 began.
…d → package/metadata/migrationHash (TML-2264 Phase 4 T4.1-T4.6)
Lands T4.1-T4.6 of TML-2264 Phase 4 in one atomic commit. The original
plan suggested splitting per-task, but T4.2 (rename `MigrationBundle.manifest`
field → `metadata`) and T4.3 (rename `MigrationChainEntry.migrationId`
field → `migrationHash`) are field-level renames that the type system
cannot bridge with legacy aliases — so any intermediate "barrel keeps
old names alive" commit would still break compilation. The split
collapses to two commits: this atomic rename, then T4.7 (deletion of
the transitional `types.ts` barrel) as a follow-up.
Renames (TS surface only — wire format `migrationId` field remains
on-disk until Phase 5):
Type renames
- `MigrationManifest` → `MigrationMetadata`
- `MigrationBundle` → `MigrationPackage`
- `bundle.manifest` → `pkg.metadata`
- `MigrationChainEntry.migrationId` → `migrationHash`
Function/file renames
- `attestation.ts` → `hash.ts` (via git mv)
- `computeMigrationId` → `computeMigrationHash`
- `verifyMigrationBundle` → `verifyMigrationHash`
- `VerifyResult.{stored,computed}MigrationId` → `{stored,computed}Hash`
- parameter names: `manifest` → `metadata`, `bundle` → `pkg`
Error factory + code renames
- `errorBundleCorrupt` → `errorMigrationHashMismatch`
- `MIGRATION.BUNDLE_CORRUPT` → `MIGRATION.HASH_MISMATCH`
- `errorDuplicateMigrationId` → `errorDuplicateMigrationHash`
- `MIGRATION.DUPLICATE_MIGRATION_ID` → `MIGRATION.DUPLICATE_MIGRATION_HASH`
File splits (`types.ts` decomposed into per-concept files)
- new `metadata.ts` — `MigrationMetadata`, `MigrationHints`
- new `package.ts` — `MigrationPackage`, `MigrationOps`
- new `graph.ts` — `MigrationGraph`, `MigrationChainEntry`
`types.ts` is left as a transitional barrel re-exporting all of the
above (and `MigrationToolsError` from `./errors`) so consumers that
still import from `@prisma-next/migration-tools/types` keep resolving
through the boundary; T4.7 deletes the barrel.
Wire-format coordination (constraint 4 of the orchestrator brief):
The on-disk `migration.json` files retain the `migrationId` field and
are codemoded in Phase 5. To keep the in-memory type renamed without
breaking the on-disk schema, `metadata.ts` introduces a wire shape
(`MigrationMetadataWire` with `migrationId`) and translation helpers
(`metadataFromWire` / `metadataToWire`). `io.ts` translates at the
read/write boundary; `migration-base.ts` translates inline when
re-emitting an existing manifest. The arktype schema in `io.ts` still
validates the on-disk wire shape (with `migrationId`), so the schema
and the in-memory type remain consistent across the rename — no
transient validation gap.
`MigrationMeta` (in `migration-base.ts`) is intentionally untouched
per Decision 7 / open question 3 — it is a different concept owned by
TML-2301.
CLI helpers (`loadMigrationBundles`, `loadAllBundles`,
`MigrationBundleSet`) keep their function/interface names — those
renames are Phase 6 T6.1. The types they reference are updated.
The structural-canonicalization rationale required by `spec.md §
Documentation home` lives as JSDoc on `computeMigrationHash` in
`hash.ts`.
Validation gates (all green):
- pnpm -F @prisma-next/migration-tools test ........ 175/175
- pnpm -F @prisma-next/cli test .................... 531/531
- pnpm typecheck ................................... 120/120 tasks
- pnpm test:integration ............................ 518/518
Per-symbol greps (`packages/ test/ examples/`): zero hits for
`MigrationManifest`, `verifyMigrationBundle`, `computeMigrationId`,
`errorBundleCorrupt`, `errorDuplicateMigrationId`,
`MIGRATION.BUNDLE_CORRUPT`, `MIGRATION.DUPLICATE_MIGRATION_ID`,
`bundle.manifest`. `MigrationBundle` hits remain only on the deferred
CLI helpers (T6.1). `migrationId` hits remain only in on-disk JSON
fixtures and integration tests that read the wire format directly via
`JSON.parse` (Phase 5 codemod scope).
…nToolsError` via `./errors` (TML-2264 Phase 4 T4.7)
Removes the transitional `types.ts` barrel introduced by the previous
commit and migrates the remaining `@prisma-next/migration-tools/types`
consumers to the per-concept subpaths (`./metadata`, `./package`,
`./graph`, plus a new `./errors` for `MigrationToolsError`).
`MigrationToolsError` does not belong to any of the three concept
files (metadata, package, graph) — it is cross-cutting. Per the plan
T4.7 deferral protocol on task ambiguity ("pick the most-spec-consistent
interpretation, document the choice"), this commit gives it its own
`./errors` subpath. `errors.ts` is already its own source file in the
package, so the subpath simply re-exports the existing module.
Changes:
- new `src/exports/errors.ts` re-exports `MigrationToolsError`.
- `package.json` exports: `./types` removed; `./errors` added.
Final shape replaces the single `./types` barrel with four
per-concept subpaths (`./metadata`, `./package`, `./graph`,
`./errors`).
- `tsdown.config.ts`: drop `exports/types`; add `exports/errors`.
- `src/types.ts` and `src/exports/types.ts` deleted.
- All `MigrationToolsError` consumers (six CLI commands plus two
test files) re-pointed at `@prisma-next/migration-tools/errors`.
- The lone `MigrationGraph` consumer
(`graph-migration-mapper.ts`) re-pointed at
`@prisma-next/migration-tools/graph`.
- `migration-tools/README.md` Export Subpaths table extended with
the new `./errors` row.
Validation gates (all green):
- pnpm -F @prisma-next/migration-tools test ........ 175/175
- pnpm -F @prisma-next/cli test .................... 531/531
- pnpm typecheck ................................... 120/120 tasks
- pnpm test:integration ............................ 518/518
Per-symbol greps (`packages/ test/ examples/`): zero hits for
`@prisma-next/migration-tools/types`,
`@prisma-next/migration-tools/attestation`,
`MigrationManifest`, `verifyMigrationBundle`, `computeMigrationId`,
`errorBundleCorrupt`, `errorDuplicateMigrationId`,
`MIGRATION.BUNDLE_CORRUPT`, `MIGRATION.DUPLICATE_MIGRATION_ID`.
The remaining `MigrationBundle*` hits are CLI helper names
(`MigrationBundleSet`, `loadMigrationBundles`, `loadAllBundles`)
explicitly deferred to Phase 6 T6.1.
This concludes Phase 4 of TML-2264.
…-2264 Phase 6 T6.5 Phase 4 review (commit 4b67994b4) surfaced a public-API naming inconsistency: MigrationGraph.migrationById retains the migrationId fragment while the Map indexes by what is now called migrationHash. Filed as F16 (low severity, naming consistency) in code-review.md and recommended as a Phase 6 fold-in. User accepted option (b): new sibling task T6.5 rather than expanding T6.1, on the rationale that T6.1 is scoped to cli-package helpers while F16 lives in migration-tools — one PR-review pass per package surface reads cleaner. T6.5 covers ~12 mechanical sites across migration-tools graph.ts / dag.ts / dag.test.ts and cli/test/utils/graph-helpers.ts. Bounded; typecheck-validated; no behavioral impact.
TML-2301 merged into main during this PR's development and was integrated via merge commit 39157ef76. Three spec/plan revisions follow from the merge: 1. Architectural reframing (Decision 6, was "TML-2301 coordination"). The original spec assumed Migration.run() would be an in-process apply orchestrator that loads MigrationPackages from disk. That assumption was wrong. TML-2301 landed MigrationCLI.run as a *write* path (regenerating packages from authored sources), not a read path. It reads migration.json only for scaffolding-context preservation (createdAt, fromContract, hints, labels) and never reads ops.json. It is structurally incapable of verifying hashes. Decision 6 rewritten to record the resulting two-loader architectural split: verifying loader at apply-time read paths; non-verifying loader at author-time write paths. The split is sharper than the original spec sketched and is recorded as the durable architectural picture. 2. Open questions resolved. Q3 (rename MigrationMeta?) resolved against renaming — TML-2301 chose to keep MigrationMeta as the durable name for the user-authored describe() return type, and the two names (MigrationMeta vs MigrationMetadata) coexist by design. Q2 (errorMigrationHashMismatch export visibility) reworded to drop the stale Migration.run() reference; default unchanged. 3. Phase 5 scope expansion. Phase 4's wire-translator pattern (MigrationMetadataWire, metadataFromWire, metadataToWire) was load-bearing for the merge — TML-2301's pure-function refactor integrated cleanly *because* the translator pattern already existed. After Phase 5 renames the on-disk field, the translator becomes redundant and must be deleted. New T5.3 task added covering deletion across migration-base.ts:234, migration-cli.ts's readExistingMetadata, and metadata.ts's type+helper exports. Existing T5.3 (test suite) renumbered to T5.4; T5.4 (sanity check) to T5.5. Validation gate strengthened with translator-pattern audit greps. Also: critical-risks section updated to record the merge resolution (TML-2301 timing + rename conflicts both resolved), Coordination collaborator entry marked resolved, and Open items list updated. Process learning recorded for the orchestrator skill: post-merge validation should include pnpm build (not just pnpm install) — stale dist/*.mjs from pre-merge builds caused 16 spurious test failures on first validation pass after the merge. Class-of-merge issue.
5baddd5 to
58735fc
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts (1)
165-205:⚠️ Potential issue | 🟠 MajorReturn a structured error if loading existing migrations fails.
A non-
MigrationToolsErrorfromloadAllMigrationPackages()is rethrown here, but the outer catch only starts at Line 257. That means fs/runtime failures in the migration-loading phase bypasshandleResult()and crash the command instead of producing the standard CLI envelope.Suggested fix
} catch (error) { if (MigrationToolsError.is(error)) { return notOk(mapMigrationToolsError(error)); } - throw error; + const message = error instanceof Error ? error.message : String(error); + return notOk( + errorUnexpected(message, { + why: `Unexpected error while loading migrations: ${message}`, + }), + ); }As per coding guidelines, "CLI commands must use structured errors (
CliStructuredError), the Result pattern (performAction), andprocess.exit()for exit codes. Commands should never throw errors except for unhandled failures that fail fast."🤖 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-plan.ts` around lines 165 - 205, The try/catch around loadAllMigrationPackages currently rethrows non-MigrationToolsError errors which crashes the CLI; instead catch any non-MigrationToolsError thrown by loadAllMigrationPackages and return a structured CLI error using the existing Result pattern (e.g., call notOk with errorRuntime or a CliStructuredError mapper) so the command returns a proper Result envelope; update the catch to: if MigrationToolsError -> mapMigrationToolsError as before, else convert the raw error into a runtime CliStructuredError (include the error message in the why field) and return notOk(...) rather than throwing; references: loadAllMigrationPackages, MigrationToolsError, mapMigrationToolsError, notOk, errorRuntime.
🧹 Nitpick comments (4)
packages/1-framework/3-tooling/cli/test/migration-cli.test.ts (1)
229-248: Assert the rewrittenmigrationHashin this preservation case.This fixture starts with
migrationHash: null, but the test never checks the output hash afterMigrationCLI.run(). A regression that preservesnullwould still pass here while producing a package thatreadMigrationPackage()now rejects. Add asha256:assertion on the rewrittenmigration.json.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/cli/test/migration-cli.test.ts` around lines 229 - 248, Test currently omits asserting that MigrationCLI.run rewrites migrationHash from null to the expected sha256 value; update the test after reading manifest (manifest = JSON.parse(...)) to assert manifest.migrationHash equals the expected "sha256:..." string so regressions that leave it null will fail. Locate the test block around MigrationCLI.run(...) and the manifest variable and add an expectation for migrationHash to match the generated sha256 value.packages/1-framework/3-tooling/cli/test/output.json-shapes.test.ts (1)
42-44: Assert theselectedPathentry shape directly.These snapshots only cover the top-level
pathDecisionkeys. If the JSON serializer dropsmigrationHashfromselectedPath, this test still passes because the object is constructed locally from the TS type. Add a key assertion forresult.pathDecision!.selectedPath[0]!.Also applies to: 85-87
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/cli/test/output.json-shapes.test.ts` around lines 42 - 44, Add an explicit assertion that checks the shape of the selectedPath entry rather than relying on the surrounding snapshot: assert result.pathDecision!.selectedPath[0]! includes the keys dirName, migrationHash, from, and to with expected values (e.g., { dirName: 'm1', migrationHash: 'sha256:mid', from: 'sha256:a', to: 'sha256:b' }) so the test fails if migrationHash (or any field) is dropped; repeat the same explicit key assertion for the corresponding case at lines 85-87.test/integration/test/cli-journeys/mongo-migration.e2e.test.ts (1)
265-268: Keep the parsed manifest type aligned with the current schema.
migrationHashis now a required string on disk, so thesestring | nullcasts still model the old shape and weaken the test. Tightening both annotations tomigrationHash: stringmakes this file catch nullable regressions instead of silently permitting them in the test type. As per coding guidelines, "Update tests to only test the current approach, removing test fixtures and examples that show old patterns."Also applies to: 483-486
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/integration/test/cli-journeys/mongo-migration.e2e.test.ts` around lines 265 - 268, The parsed manifest type is still declared as migrationHash: string | null which models the old nullable schema; update the type annotation on the JSON.parse result so manifest is typed as { migrationHash: string } (change both occurrences where the manifest variable is declared, e.g., the const manifest = JSON.parse(...) as { migrationHash: string | null } lines) so the test fails if migrationHash is ever null.packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts (1)
155-178: Finish the rename instead of keeping a same-behavior alias.
loadAllMigrationPackages()now just forwards toloadMigrationPackages(), and both surfaces still returnbundles. That preserves the old vocabulary/API shape after the draft/attested split was removed, which makes the newMigrationPackageterminology harder to follow.As per coding guidelines, "Do not add backward-compatibility shims, migration scaffolding, deprecation warnings, or comments explaining legacy vs. new approaches" and "Update all references immediately to use new approaches instead of maintaining parallel implementations."
🤖 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/utils/command-helpers.ts` around lines 155 - 178, Remove the alias function loadAllMigrationPackages and fold callers to use loadMigrationPackages directly; delete the loadAllMigrationPackages implementation and the MigrationPackageSet indirection (if unused) and update any references that call loadAllMigrationPackages to call loadMigrationPackages(migrationsDir) and expect the { bundles, graph } result shape from loadMigrationPackages; ensure imports/exports are updated to remove loadAllMigrationPackages and adjust any types to reference the concrete return shape or MigrationGraph/MigrationPackage types instead.
🤖 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/migration/src/errors.ts`:
- Around line 76-77: Update the remediation text for the invalid manifest error
so it lists migrationHash as a required field; locate the object with keys why
and fix (the invalid-manifest message) and modify the fix string to read
something like "Ensure migration.json has all required fields (from, to, kind,
toContract, migrationHash). If corrupt, delete and re-plan." so users are guided
to include migrationHash.
In `@packages/1-framework/3-tooling/migration/test/dag.test.ts`:
- Around line 28-37: The migrationHash is computed from a synthetic createdAt
value but the returned metadata keeps the original createdAt, causing package
inconsistency; update the flow in the helper so the metadata object used to
compute computeMigrationHash is the exact same metadata object returned (i.e.,
generate the synthetic createdAt once, assign it into metadata from
createTestMetadata before calling computeMigrationHash, then compute
migrationHash from that metadata and return metadata with migrationHash),
referencing metadata, createTestMetadata, computeMigrationHash, and
migrationHash to locate the change.
---
Outside diff comments:
In `@packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts`:
- Around line 165-205: The try/catch around loadAllMigrationPackages currently
rethrows non-MigrationToolsError errors which crashes the CLI; instead catch any
non-MigrationToolsError thrown by loadAllMigrationPackages and return a
structured CLI error using the existing Result pattern (e.g., call notOk with
errorRuntime or a CliStructuredError mapper) so the command returns a proper
Result envelope; update the catch to: if MigrationToolsError ->
mapMigrationToolsError as before, else convert the raw error into a runtime
CliStructuredError (include the error message in the why field) and return
notOk(...) rather than throwing; references: loadAllMigrationPackages,
MigrationToolsError, mapMigrationToolsError, notOk, errorRuntime.
---
Nitpick comments:
In `@packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts`:
- Around line 155-178: Remove the alias function loadAllMigrationPackages and
fold callers to use loadMigrationPackages directly; delete the
loadAllMigrationPackages implementation and the MigrationPackageSet indirection
(if unused) and update any references that call loadAllMigrationPackages to call
loadMigrationPackages(migrationsDir) and expect the { bundles, graph } result
shape from loadMigrationPackages; ensure imports/exports are updated to remove
loadAllMigrationPackages and adjust any types to reference the concrete return
shape or MigrationGraph/MigrationPackage types instead.
In `@packages/1-framework/3-tooling/cli/test/migration-cli.test.ts`:
- Around line 229-248: Test currently omits asserting that MigrationCLI.run
rewrites migrationHash from null to the expected sha256 value; update the test
after reading manifest (manifest = JSON.parse(...)) to assert
manifest.migrationHash equals the expected "sha256:..." string so regressions
that leave it null will fail. Locate the test block around MigrationCLI.run(...)
and the manifest variable and add an expectation for migrationHash to match the
generated sha256 value.
In `@packages/1-framework/3-tooling/cli/test/output.json-shapes.test.ts`:
- Around line 42-44: Add an explicit assertion that checks the shape of the
selectedPath entry rather than relying on the surrounding snapshot: assert
result.pathDecision!.selectedPath[0]! includes the keys dirName, migrationHash,
from, and to with expected values (e.g., { dirName: 'm1', migrationHash:
'sha256:mid', from: 'sha256:a', to: 'sha256:b' }) so the test fails if
migrationHash (or any field) is dropped; repeat the same explicit key assertion
for the corresponding case at lines 85-87.
In `@test/integration/test/cli-journeys/mongo-migration.e2e.test.ts`:
- Around line 265-268: The parsed manifest type is still declared as
migrationHash: string | null which models the old nullable schema; update the
type annotation on the JSON.parse result so manifest is typed as {
migrationHash: string } (change both occurrences where the manifest variable is
declared, e.g., the const manifest = JSON.parse(...) as { migrationHash: string
| null } lines) so the test fails if migrationHash is ever null.
🪄 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: 164cbd7c-7190-4292-8253-df7cec69e129
📒 Files selected for processing (176)
examples/mongo-demo/migrations/20260409T1030_migration/migration.jsonexamples/mongo-demo/migrations/20260415_add-posts-author-index/migration.jsonexamples/mongo-demo/test/manual-migration.test.tsexamples/prisma-next-demo/migration-fixtures/complex/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260302T1000_alice_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260302T1100_bob_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260302T1200_staging_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260303T1000_merge_alice/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260303T1100_merge_bob/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260304T1000_add_comments/migration.jsonexamples/prisma-next-demo/migration-fixtures/complex/20260305T1000_add_tags/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1100_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1200_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1000_merge_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1100_merge_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1200_merge_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1000_alice_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1100_bob_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1200_bob_experiment/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1000_merge_alice/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1100_merge_bob/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1200_bob_experiment_2/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond/20260302T1000_alice_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond/20260302T1100_bob_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond/20260303T1000_merge_alice/migration.jsonexamples/prisma-next-demo/migration-fixtures/diamond/20260303T1100_merge_bob/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1100_widen_email/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260303T1000_email_default/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260304T1000_change_default/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260305T1000_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260306T1000_add_comments/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260307T1000_kitchen_sink/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260308T1000_rollback/migration.jsonexamples/prisma-next-demo/migration-fixtures/kitchen-sink/20260326T1428_migration/migration.jsonexamples/prisma-next-demo/migration-fixtures/linear/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/linear/20260302T1000_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260304T1000_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260305T1000_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260306T1000_add_comments/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260307T1000_add_tags/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260307T1100_late_branch/migration.jsonexamples/prisma-next-demo/migration-fixtures/long-spine/20260308T1000_add_everything/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1100_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1200_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1430_migration/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_foobar/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_migration/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1432_foobar/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1100_staging/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260304T1000_add_comments/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260305T1000_add_tags/migration.jsonexamples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260306T1000_rollback_to_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260304T1000_rollback_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260305T1000_rollback_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback-continue/20260306T1000_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback/20260304T1000_rollback_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/rollback/20260305T1000_rollback_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1000_alice_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1100_bob_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1000_merge_1a/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1100_merge_1b/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1000_add_comments/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1100_add_posts_branch/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1000_merge_2a/migration.jsonexamples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1100_merge_2b/migration.jsonexamples/prisma-next-demo/migration-fixtures/single-branch/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/single-branch/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/single-branch/20260302T1100_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/single-branch/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260304T1000_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260305T1000_rollback_to_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/skip-rollback/20260306T1000_rollback_to_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/sub-branches/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1100_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1000_add_bio/migration.jsonexamples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1100_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260301T1000_init/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1000_add_phone/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1100_add_posts/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1200_add_avatar/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1300_add_category/migration.jsonexamples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1400_add_settings/migration.jsonexamples/prisma-next-demo/migrations/20260422T0720_initial/migration.jsonexamples/prisma-next-demo/migrations/20260422T0742_migration/migration.jsonexamples/prisma-next-demo/migrations/20260422T0748_migration/migration.jsonexamples/retail-store/migrations/20260413T0314_migration/migration.jsonexamples/retail-store/migrations/20260415_add-product-validation/migration.jsonexamples/retail-store/migrations/20260416_backfill-product-status/migration.jsonexamples/retail-store/test/manual-migration.test.tspackages/1-framework/1-core/framework-components/src/control-migration-types.tspackages/1-framework/3-tooling/cli/README.mdpackages/1-framework/3-tooling/cli/src/commands/migration-apply.tspackages/1-framework/3-tooling/cli/src/commands/migration-new.tspackages/1-framework/3-tooling/cli/src/commands/migration-plan.tspackages/1-framework/3-tooling/cli/src/commands/migration-ref.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/control-api/operations/migration-apply.tspackages/1-framework/3-tooling/cli/src/migration-cli.tspackages/1-framework/3-tooling/cli/src/utils/cli-errors.tspackages/1-framework/3-tooling/cli/src/utils/command-helpers.tspackages/1-framework/3-tooling/cli/src/utils/formatters/graph-migration-mapper.tspackages/1-framework/3-tooling/cli/src/utils/formatters/migrations.tspackages/1-framework/3-tooling/cli/test/commands/migration-apply.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-e2e.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-plan.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-ref.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-show.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.tspackages/1-framework/3-tooling/cli/test/control-api/client.test.tspackages/1-framework/3-tooling/cli/test/migration-cli.test.tspackages/1-framework/3-tooling/cli/test/output.json-shapes.test.tspackages/1-framework/3-tooling/cli/test/utils/graph-helpers.tspackages/1-framework/3-tooling/migration/README.mdpackages/1-framework/3-tooling/migration/package.jsonpackages/1-framework/3-tooling/migration/src/attestation.tspackages/1-framework/3-tooling/migration/src/dag.tspackages/1-framework/3-tooling/migration/src/errors.tspackages/1-framework/3-tooling/migration/src/exports/attestation.tspackages/1-framework/3-tooling/migration/src/exports/errors.tspackages/1-framework/3-tooling/migration/src/exports/graph.tspackages/1-framework/3-tooling/migration/src/exports/hash.tspackages/1-framework/3-tooling/migration/src/exports/io.tspackages/1-framework/3-tooling/migration/src/exports/metadata.tspackages/1-framework/3-tooling/migration/src/exports/package.tspackages/1-framework/3-tooling/migration/src/exports/types.tspackages/1-framework/3-tooling/migration/src/graph.tspackages/1-framework/3-tooling/migration/src/hash.tspackages/1-framework/3-tooling/migration/src/io.tspackages/1-framework/3-tooling/migration/src/metadata.tspackages/1-framework/3-tooling/migration/src/migration-base.tspackages/1-framework/3-tooling/migration/src/package.tspackages/1-framework/3-tooling/migration/src/types.tspackages/1-framework/3-tooling/migration/test/attestation.test.tspackages/1-framework/3-tooling/migration/test/dag.test.tspackages/1-framework/3-tooling/migration/test/fixtures.tspackages/1-framework/3-tooling/migration/test/hash.test.tspackages/1-framework/3-tooling/migration/test/io.test.tspackages/1-framework/3-tooling/migration/test/migration-base.test.tspackages/1-framework/3-tooling/migration/tsdown.config.tspackages/2-mongo-family/9-family/src/core/mongo-target-descriptor.tstest/integration/test/cli-journeys/data-transform-enum-rebuild.e2e.test.tstest/integration/test/cli-journeys/data-transform-not-null-backfill.e2e.test.tstest/integration/test/cli-journeys/data-transform-nullable-tightening.e2e.test.tstest/integration/test/cli-journeys/data-transform-type-change.e2e.test.tstest/integration/test/cli-journeys/migration-plan-details.e2e.test.tstest/integration/test/cli-journeys/mongo-migration.e2e.test.tstest/integration/test/cli.migration-apply.e2e.test.ts
💤 Files with no reviewable changes (5)
- packages/1-framework/3-tooling/migration/src/types.ts
- packages/1-framework/3-tooling/migration/src/exports/attestation.ts
- packages/1-framework/3-tooling/migration/src/attestation.ts
- packages/1-framework/3-tooling/migration/test/attestation.test.ts
- packages/1-framework/3-tooling/migration/src/exports/types.ts
✅ Files skipped from review due to trivial changes (122)
- examples/prisma-next-demo/migration-fixtures/diamond/20260303T1100_merge_bob/migration.json
- examples/prisma-next-demo/migration-fixtures/long-spine/20260308T1000_add_everything/migration.json
- examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260307T1000_kitchen_sink/migration.json
- examples/prisma-next-demo/migration-fixtures/complex/20260303T1000_merge_alice/migration.json
- examples/prisma-next-demo/migration-fixtures/linear/20260302T1000_add_posts/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond/20260302T1100_bob_add_avatar/migration.json
- examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1000_merge_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/long-spine/20260305T1000_add_avatar/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1432_foobar/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1000_merge_alice/migration.json
- examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1000_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1000_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/rollback-continue/20260306T1000_add_posts/migration.json
- examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1200_bob_experiment/migration.json
- examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1100_merge_posts/migration.json
- examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1200_add_avatar/migration.json
- examples/prisma-next-demo/migration-fixtures/single-branch/20260302T1100_add_posts/migration.json
- examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1400_add_settings/migration.json
- examples/prisma-next-demo/migration-fixtures/skip-rollback/20260306T1000_rollback_to_init/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1100_merge_bob/migration.json
- examples/prisma-next-demo/migration-fixtures/long-spine/20260306T1000_add_comments/migration.json
- examples/mongo-demo/migrations/20260415_add-posts-author-index/migration.json
- packages/1-framework/3-tooling/cli/src/utils/formatters/graph-migration-mapper.ts
- examples/prisma-next-demo/migration-fixtures/complex/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1100_merge_2b/migration.json
- examples/prisma-next-demo/migration-fixtures/long-spine/20260303T1000_add_bio/migration.json
- examples/prisma-next-demo/migration-fixtures/rollback/20260302T1000_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/sub-branches/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/complex/20260305T1000_add_tags/migration.json
- examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260303T1000_email_default/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/wide-fan/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1000_alice_add_phone/migration.json
- packages/2-mongo-family/9-family/src/core/mongo-target-descriptor.ts
- examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1100_add_posts_branch/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-branch/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1430_migration/migration.json
- examples/prisma-next-demo/migration-fixtures/rollback-continue/20260303T1000_add_bio/migration.json
- examples/prisma-next-demo/migration-fixtures/skip-rollback/20260303T1000_add_bio/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1100_add_posts/migration.json
- examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1100_bob_add_avatar/migration.json
- examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260302T1100_widen_email/migration.json
- examples/prisma-next-demo/migration-fixtures/converging-branches/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/complex/20260304T1000_add_comments/migration.json
- examples/prisma-next-demo/migration-fixtures/rollback/20260303T1000_add_bio/migration.json
- examples/retail-store/test/manual-migration.test.ts
- examples/prisma-next-demo/migrations/20260422T0720_initial/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260305T1000_add_tags/migration.json
- examples/prisma-next-demo/migration-fixtures/rollback-continue/20260305T1000_rollback_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/linear/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1100_add_avatar/migration.json
- examples/prisma-next-demo/migration-fixtures/complex/20260302T1000_alice_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260302T1000_alice_add_phone/migration.json
- examples/retail-store/migrations/20260415_add-product-validation/migration.json
- examples/prisma-next-demo/migration-fixtures/single-branch/20260303T1000_add_bio/migration.json
- examples/prisma-next-demo/migration-fixtures/long-spine/20260307T1000_add_tags/migration.json
- examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1100_add_posts/migration.json
- packages/1-framework/3-tooling/migration/src/exports/graph.ts
- examples/prisma-next-demo/migration-fixtures/rollback-continue/20260302T1000_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_migration/migration.json
- packages/1-framework/3-tooling/migration/src/exports/io.ts
- examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260306T1000_add_comments/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260303T1200_bob_experiment_2/migration.json
- examples/prisma-next-demo/migration-fixtures/sub-branches/20260303T1000_add_bio/migration.json
- examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260308T1000_rollback/migration.json
- examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1000_merge_1a/migration.json
- examples/prisma-next-demo/migration-fixtures/long-spine/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260306T1000_rollback_to_phone/migration.json
- packages/1-framework/3-tooling/migration/src/exports/package.ts
- examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260303T1100_merge_1b/migration.json
- examples/prisma-next-demo/migration-fixtures/skip-rollback/20260305T1000_rollback_to_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1000_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond/20260303T1000_merge_alice/migration.json
- examples/mongo-demo/migrations/20260409T1030_migration/migration.json
- examples/prisma-next-demo/migration-fixtures/rollback/20260305T1000_rollback_phone/migration.json
- packages/1-framework/3-tooling/cli/src/control-api/operations/migration-apply.ts
- examples/prisma-next-demo/migration-fixtures/multi-branch/20260326T1431_foobar/migration.json
- examples/prisma-next-demo/migration-fixtures/long-spine/20260304T1000_add_posts/migration.json
- examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260304T1000_add_comments/migration.json
- examples/prisma-next-demo/migrations/20260422T0742_migration/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260304T1000_add_comments/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond/20260302T1000_alice_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1300_add_category/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1100_staging/migration.json
- examples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1000_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond/20260301T1000_init/migration.json
- examples/retail-store/migrations/20260416_backfill-product-status/migration.json
- test/integration/test/cli-journeys/data-transform-type-change.e2e.test.ts
- examples/prisma-next-demo/migration-fixtures/single-branch/20260302T1000_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/rollback-continue/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/single-branch/20260301T1000_init/migration.json
- packages/1-framework/1-core/framework-components/src/control-migration-types.ts
- examples/prisma-next-demo/migration-fixtures/wide-fan/20260302T1000_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260305T1000_add_posts/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-branch/20260302T1200_add_avatar/migration.json
- examples/prisma-next-demo/migration-fixtures/long-spine/20260307T1100_late_branch/migration.json
- examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1200_add_avatar/migration.json
- examples/prisma-next-demo/migration-fixtures/sequential-diamonds/20260305T1000_merge_2a/migration.json
- examples/prisma-next-demo/migration-fixtures/skip-rollback/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/sub-branches/20260302T1100_add_posts/migration.json
- packages/1-framework/3-tooling/migration/src/exports/metadata.ts
- examples/prisma-next-demo/migration-fixtures/multi-branch/20260303T1000_add_bio/migration.json
- examples/prisma-next-demo/migration-fixtures/rollback-continue/20260304T1000_rollback_bio/migration.json
- examples/prisma-next-demo/migration-fixtures/complex/20260303T1100_merge_bob/migration.json
- packages/1-framework/3-tooling/cli/test/control-api/client.test.ts
- examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/rollback/20260301T1000_init/migration.json
- examples/prisma-next-demo/migration-fixtures/diamond-sub-branch/20260302T1100_bob_add_avatar/migration.json
- packages/1-framework/3-tooling/migration/src/metadata.ts
- examples/prisma-next-demo/migration-fixtures/long-spine/20260302T1000_add_phone/migration.json
- packages/1-framework/3-tooling/migration/src/graph.ts
- examples/prisma-next-demo/migration-fixtures/skip-rollback/20260302T1000_add_phone/migration.json
- examples/prisma-next-demo/migration-fixtures/rollback/20260304T1000_rollback_bio/migration.json
- examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260326T1428_migration/migration.json
- examples/prisma-next-demo/migration-fixtures/complex/20260302T1200_staging_posts/migration.json
- examples/prisma-next-demo/migration-fixtures/converging-branches/20260302T1100_add_posts/migration.json
- examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260302T1000_add_phone/migration.json
- examples/retail-store/migrations/20260413T0314_migration/migration.json
- examples/prisma-next-demo/migrations/20260422T0748_migration/migration.json
- examples/prisma-next-demo/migration-fixtures/kitchen-sink/20260304T1000_change_default/migration.json
🚧 Files skipped from review as they are similar to previous changes (21)
- examples/prisma-next-demo/migration-fixtures/converging-branches/20260303T1200_merge_avatar/migration.json
- examples/prisma-next-demo/migration-fixtures/skip-rollback/20260304T1000_add_posts/migration.json
- packages/1-framework/3-tooling/migration/src/exports/errors.ts
- examples/prisma-next-demo/migration-fixtures/multi-rollback-branch/20260303T1000_add_bio/migration.json
- examples/prisma-next-demo/migration-fixtures/complex/20260302T1100_bob_add_avatar/migration.json
- test/integration/test/cli-journeys/data-transform-nullable-tightening.e2e.test.ts
- packages/1-framework/3-tooling/cli/src/utils/formatters/migrations.ts
- packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts
- test/integration/test/cli-journeys/data-transform-enum-rebuild.e2e.test.ts
- packages/1-framework/3-tooling/migration/test/hash.test.ts
- packages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.ts
- test/integration/test/cli-journeys/data-transform-not-null-backfill.e2e.test.ts
- packages/1-framework/3-tooling/migration/src/exports/hash.ts
- packages/1-framework/3-tooling/cli/test/commands/migration-ref.test.ts
- packages/1-framework/3-tooling/migration/tsdown.config.ts
- packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
- packages/1-framework/3-tooling/cli/README.md
- packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts
- packages/1-framework/3-tooling/cli/src/migration-cli.ts
- packages/1-framework/3-tooling/cli/test/commands/migration-plan.test.ts
- packages/1-framework/3-tooling/cli/test/commands/migration-show.test.ts
`MIGRATION.FILE_MISSING`, `MIGRATION.INVALID_JSON`, `MIGRATION.INVALID_MANIFEST`, and `MIGRATION.SAME_SOURCE_AND_TARGET` previously instructed users to delete the directory and re-run `migration plan`. That is the wrong primitive — `migration plan` emits a *new* package, while every existing package can self-emit by running its author-time `migration.ts`, regenerating `migration.json` and `ops.json` with the correct hash + metadata. Mirror the existing `MIGRATION.HASH_MISMATCH` wording via a shared `reemitHint(dir, fallback)` helper. `errorSameSourceAndTarget` now takes the package `dirPath` so it can render the same cwd-relative hint; `dag.ts` updated accordingly. Addresses CodeRabbit thread on `errorInvalidManifest` (#384 (comment)) and the operator’s broader directive to standardise migration-tools remediation wording.
Previously the dag.test.ts `pkg()` helper computed `migrationHash` from a synthetic `createdAt` (with the per-pkg counter appended) but returned metadata with the original `createdAt`. Each fixture package was therefore internally inconsistent and could never round-trip through `readMigrationPackage()`. Bake the counter into the metadata `createdAt` once and hash that exact metadata, so fixtures are loader-safe and would catch hash-verification regressions. Addresses CodeRabbit thread #384 (comment).
…lure (A12a) `migration plan` previously rethrew non-`MigrationToolsError` exceptions from the migration-load phase, bypassing `handleResult()` and crashing the command. Wrap such failures in `errorUnexpected(...)` so the user sees the same structured CLI envelope (Result pattern) as every other failure path. Addresses CodeRabbit review-body finding #384 (review) (migration-plan.ts ~165-205, outside-diff major).
…t contract hash) (A11) The JSDoc on `resolveBundleByPrefix` said "exact hash or prefix match" without specifying which hash. The implementation matches `metadata.to` (the contract hash a migration produces), not `metadata.migrationHash` (the package's content-addressed identity). Tighten wording so future maintainers do not mistakenly switch the resolver to migrationHash semantics. Addresses CodeRabbit nitpick #384 (review).
…12b, A12c, A12d)
Three small assertion tightenings flagged by CodeRabbit on the migrationHash
contract — each one currently a silent gap that would let a real regression
slip through:
- migration-cli.test.ts `preserves contract bookends`: assert that
`migrationHash` is rewritten from on-disk `null` to a real `sha256:...`
digest. Without this assertion, MigrationCLI.run could silently keep the
null and produce a package readMigrationPackage() rejects.
- output.json-shapes.test.ts pathDecision blocks: assert `selectedPath[0]`
shape directly (dirName / migrationHash / from / to). The surrounding
Object.keys snapshot only covered top-level pathDecision keys, so dropping
`migrationHash` from the wire shape would not have failed.
- mongo-migration.e2e.test.ts manifest casts: tighten from
`{ migrationHash: string | null }` to `{ migrationHash: string }` so
ever producing `null` on disk fails type-checking.
Addresses three nitpicks from CodeRabbit review
#384 (review).
…geSet (A12e) `loadAllMigrationPackages` was a same-behaviour wrapper around `loadMigrationPackages`, retained only for naming clarity from the era when the CLI distinguished attested and draft package sets. The draft state was removed earlier in this PR — the alias now just preserves stale vocabulary and breaks the "no backward-compat shims" guideline. Inline the alias and the `MigrationPackageSet` type at the three callers (`migration plan` / `migration apply` / `migration status`); update mocks and explanatory comments in `migration-plan-command.test.ts` and `migration-tamper.test.ts`. The single `MigrationPackageSet` user (`migration-apply.ts`) now uses `Awaited<ReturnType<typeof loadMigrationPackages>>` directly so the return shape stays in one place. Addresses CodeRabbit nitpick #384 (review) (command-helpers.ts ~155-178).
|
Thanks for the second review pass @coderabbitai — addressed the review-body findings (PRR_kwDOQM0QJc75S_qP and PRR_kwDOQM0QJc75gWAF) below. Each item was committed individually so the diffs are easy to scan.
|
|
Tip For best results, initiate chat on the files or code changes.
All findings resolved, tests green, typecheck clean — this looks good to me. [approve] |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
packages/1-framework/3-tooling/cli/test/migration-cli.test.ts (1)
249-252: Assert the rewritten hash is valid, not just prefixed.Line 252 only checks
^sha256:, so this test still passes ifMigrationCLI.runwrites any hash-looking placeholder. Since the comment explicitly ties this to loader acceptance, it would be stronger to recompute the expected hash frommigration.json+ops.json(or round-trip throughreadMigrationPackage()) and assert equality here.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/cli/test/migration-cli.test.ts` around lines 249 - 252, The test currently only checks that manifest.migrationHash starts with "sha256:", which is weak; change it to compute the actual expected digest and assert equality: after running MigrationCLI.run, either call readMigrationPackage() on the generated package to obtain the normalized migration hash or recompute the sha256 over the exact inputs (migration.json + ops.json) the loader uses, then replace the toMatch assertion with expect(manifest.migrationHash).toBe(expectedHash) so the test verifies the real digest produced by MigrationCLI.run rather than just the prefix.packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts (1)
148-161: Finish the bundle → package rename in this helper API.
loadMigrationPackages()now returnsMigrationPackage[], but the public property is still calledbundles. That keeps the old vocabulary alive in every caller (migrations.bundles,statusResult.bundles) even though this PR is otherwise standardizing on “package”. Renaming the property here would make the migration/package split much clearer going forward.🤖 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/utils/command-helpers.ts` around lines 148 - 161, The public return property "bundles" still uses the old name; update loadMigrationPackages to return "packages" instead. Rename the local variable bundles (result of readMigrationsDir) to packages, keep using reconstructGraph(packages) (or pass the same variable name), and change the Promise return type from { bundles: readonly MigrationPackage[]; graph: MigrationGraph } to { packages: readonly MigrationPackage[]; graph: MigrationGraph } and return { packages, graph } so callers can use migrations.packages instead of migrations.bundles.packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts (1)
210-215: Avoid making the uniformity check depend on prior tests' side effects.The module-scoped
diagnosticsarray makes T3.5 order-dependent: if someone runs only that test, or if this file is re-used with persistent module state,expect(diagnostics).toHaveLength(5)fails before any CLI behavior is exercised. Collecting the five captures inside T3.5 itself (or in a localbeforeAll) would keep the uniformity assertion deterministic and self-contained.Also applies to: 395-439
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts` around lines 210 - 215, The module-scoped diagnostics array causes order-dependent failures; remove the top-level const diagnostics and instead declare and populate a local diagnostics array inside the specific uniformity test (the describe block "migration tamper diagnostic uniformity (T3.1-T3.5, T3.8)") or in a beforeAll scoped to that describe so the expectation expect(diagnostics).toHaveLength(5) in test T3.5 always observes exactly the five captures after invoking the CLI behavior; update the places that push into diagnostics to use this local variable (also apply the same fix for the analogous code around the 395-439 region).packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts (1)
219-228: Assert the newmigrationHashwrite path directly.These checks prove the CLI result shape, but they do not pin the new behavior that
writeMigrationPackage()receives a computedmetadata.migrationHash. A regression in the package write path would still pass here as long as the JSON envelope stayed unchanged.🧪 Suggested assertion
expect(result).toMatchObject({ ok: true, noOp: false, from: OLD_HASH, to: NEW_HASH, operations: [ { id: 'table.user', label: 'Create table "user"', operationClass: 'additive' }, ], }); expect(result).not.toHaveProperty('migrationHash'); + expect(mocks.writeMigrationPackage).toHaveBeenCalledWith( + expect.any(String), + expect.objectContaining({ + from: OLD_HASH, + to: NEW_HASH, + migrationHash: expect.stringMatching(/^sha256:/), + }), + expect.any(Array), + );I’d mirror the same assertion once in a placeholder case too, so both the real-ops and
[]hash paths stay covered.Also applies to: 299-305
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts` around lines 219 - 228, The test currently asserts the CLI result shape but doesn't verify that writeMigrationPackage was called with a computed metadata.migrationHash; update the test to spy/mock writeMigrationPackage (the existing spy used in this file) and add an assertion that the mock was called with a metadata object containing migrationHash equal to the expected computed hash for the real-ops case (the same value you expect from OLD_HASH -> NEW_HASH run), and add the analogous assertion in the placeholder/empty-operations test case to ensure writeMigrationPackage was called with the placeholder migrationHash; refer to the writeMigrationPackage spy and the result object in the assertions so the package write path is directly validated.
🤖 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/migration/test/dag.test.ts`:
- Around line 28-35: The helper currently appends `-<migrationCounter>` to
`createdAt` (producing values like `2026-02-25T14:00:00.000Z-0`) which breaks
loader-valid timestamp shape; instead keep `metadata.createdAt` a valid ISO
timestamp while still introducing per-package uniqueness for hashing: compute a
separate unique salt (e.g., `hashSalt = \`-${migrationCounter++}\``) and pass
the original `createdAt` into `createTestMetadata`, but include the `hashSalt`
when calling `computeMigrationHash(metadata, ops, hashSalt)` (or combine salt
into the hash input) so `uniqueCreatedAt` is not stored in metadata but the hash
remains per-package unique; update references to `uniqueCreatedAt`/`createdAt`
accordingly and ensure `readMigrationPackage()` can round-trip.
---
Nitpick comments:
In `@packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts`:
- Around line 148-161: The public return property "bundles" still uses the old
name; update loadMigrationPackages to return "packages" instead. Rename the
local variable bundles (result of readMigrationsDir) to packages, keep using
reconstructGraph(packages) (or pass the same variable name), and change the
Promise return type from { bundles: readonly MigrationPackage[]; graph:
MigrationGraph } to { packages: readonly MigrationPackage[]; graph:
MigrationGraph } and return { packages, graph } so callers can use
migrations.packages instead of migrations.bundles.
In
`@packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts`:
- Around line 219-228: The test currently asserts the CLI result shape but
doesn't verify that writeMigrationPackage was called with a computed
metadata.migrationHash; update the test to spy/mock writeMigrationPackage (the
existing spy used in this file) and add an assertion that the mock was called
with a metadata object containing migrationHash equal to the expected computed
hash for the real-ops case (the same value you expect from OLD_HASH -> NEW_HASH
run), and add the analogous assertion in the placeholder/empty-operations test
case to ensure writeMigrationPackage was called with the placeholder
migrationHash; refer to the writeMigrationPackage spy and the result object in
the assertions so the package write path is directly validated.
In `@packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts`:
- Around line 210-215: The module-scoped diagnostics array causes
order-dependent failures; remove the top-level const diagnostics and instead
declare and populate a local diagnostics array inside the specific uniformity
test (the describe block "migration tamper diagnostic uniformity (T3.1-T3.5,
T3.8)") or in a beforeAll scoped to that describe so the expectation
expect(diagnostics).toHaveLength(5) in test T3.5 always observes exactly the
five captures after invoking the CLI behavior; update the places that push into
diagnostics to use this local variable (also apply the same fix for the
analogous code around the 395-439 region).
In `@packages/1-framework/3-tooling/cli/test/migration-cli.test.ts`:
- Around line 249-252: The test currently only checks that
manifest.migrationHash starts with "sha256:", which is weak; change it to
compute the actual expected digest and assert equality: after running
MigrationCLI.run, either call readMigrationPackage() on the generated package to
obtain the normalized migration hash or recompute the sha256 over the exact
inputs (migration.json + ops.json) the loader uses, then replace the toMatch
assertion with expect(manifest.migrationHash).toBe(expectedHash) so the test
verifies the real digest produced by MigrationCLI.run rather than just the
prefix.
🪄 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: 4225fe01-3830-4204-a5fe-cc3fef928135
📒 Files selected for processing (12)
packages/1-framework/3-tooling/cli/src/commands/migration-apply.tspackages/1-framework/3-tooling/cli/src/commands/migration-plan.tspackages/1-framework/3-tooling/cli/src/commands/migration-status.tspackages/1-framework/3-tooling/cli/src/utils/command-helpers.tspackages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.tspackages/1-framework/3-tooling/cli/test/migration-cli.test.tspackages/1-framework/3-tooling/cli/test/output.json-shapes.test.tspackages/1-framework/3-tooling/migration/src/dag.tspackages/1-framework/3-tooling/migration/src/errors.tspackages/1-framework/3-tooling/migration/test/dag.test.tstest/integration/test/cli-journeys/mongo-migration.e2e.test.ts
✅ Files skipped from review due to trivial changes (1)
- test/integration/test/cli-journeys/mongo-migration.e2e.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/1-framework/3-tooling/migration/src/errors.ts
| // Bake a per-pkg counter into createdAt so distinct packages get distinct | ||
| // hashes — and use the same metadata for both hashing and the returned | ||
| // package, so each fixture is internally consistent (round-trips through | ||
| // readMigrationPackage()). | ||
| const uniqueCreatedAt = `${createdAt}-${migrationCounter++}`; | ||
| const metadata = createTestMetadata({ from, to, createdAt: uniqueCreatedAt, labels }); | ||
| const ops = createTestOps(); | ||
| const migrationId = computeMigrationId( | ||
| { ...manifest, createdAt: `${createdAt}-${migrationCounter++}` }, | ||
| ops, | ||
| ); | ||
| const migrationHash = computeMigrationHash(metadata, ops); |
There was a problem hiding this comment.
Keep fixture createdAt loader-valid.
Line 32 now produces values like 2026-02-25T14:00:00.000Z-0, so these fixtures no longer have a timestamp shape that can round-trip through the same loader path the comment describes. That weakens the “loader-safe fixture” guarantee this helper is trying to preserve.
Suggested fix
- const uniqueCreatedAt = `${createdAt}-${migrationCounter++}`;
+ const uniqueCreatedAt = new Date(
+ Date.parse(createdAt) + migrationCounter++,
+ ).toISOString();
const metadata = createTestMetadata({ from, to, createdAt: uniqueCreatedAt, labels });
const ops = createTestOps();
const migrationHash = computeMigrationHash(metadata, ops);Based on learnings: "Returned metadata.createdAt and the hashed createdAt now match, so each fixture is internally consistent and could round-trip through readMigrationPackage()."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/1-framework/3-tooling/migration/test/dag.test.ts` around lines 28 -
35, The helper currently appends `-<migrationCounter>` to `createdAt` (producing
values like `2026-02-25T14:00:00.000Z-0`) which breaks loader-valid timestamp
shape; instead keep `metadata.createdAt` a valid ISO timestamp while still
introducing per-package uniqueness for hashing: compute a separate unique salt
(e.g., `hashSalt = \`-${migrationCounter++}\``) and pass the original
`createdAt` into `createTestMetadata`, but include the `hashSalt` when calling
`computeMigrationHash(metadata, ops, hashSalt)` (or combine salt into the hash
input) so `uniqueCreatedAt` is not stored in metadata but the hash remains
per-package unique; update references to `uniqueCreatedAt`/`createdAt`
accordingly and ensure `readMigrationPackage()` can round-trip.
When `migration plan` succeeds without placeholders, `writeMigrationPackage` has already emitted ops.json + migration.json with a fully attested migrationHash, so the previous `Next: node <dir>/migration.ts to emit ops.json and attest migrationHash before running prisma-next migration apply` instruction was actively misleading: it told the user to repeat work the planner had already done. Replace with a direct pointer at `prisma-next migration apply`. The placeholder branch keeps its existing `Then run: node <dir>/migration.ts` instruction, which is correct (placeholders genuinely require a self-emit round-trip). Addresses CodeRabbit review on PR #384.
…lpers createAttestedPackage and writeTestPackage are documented to always produce internally-consistent (attested) packages — the migrationHash is computed over the exact (metadata, ops) that get returned/written. The metadataOverrides parameter was typed Partial<MigrationMetadata>, which let callers smuggle a custom migrationHash past createTestMetadata's `overrides.migrationHash ?? computeMigrationHash(...)` fallback and produce an inconsistent fixture without going through the explicit post-write tamper step the helpers are designed for. Tighten the override type to Omit<Partial<MigrationMetadata>, 'migrationHash'> on both helpers so accidental hash injection becomes a compile error. createTestMetadata stays as-is — hash.test.ts intentionally injects a migrationHash to verify computeMigrationHash ignores the existing field. Addresses CodeRabbit review on PR #384 (review body, fixtures.ts:49-58 + 85-91).
`MIGRATION.FILE_MISSING`, `MIGRATION.INVALID_JSON`, `MIGRATION.INVALID_MANIFEST`, and `MIGRATION.SAME_SOURCE_AND_TARGET` previously instructed users to delete the directory and re-run `migration plan`. That is the wrong primitive — `migration plan` emits a *new* package, while every existing package can self-emit by running its author-time `migration.ts`, regenerating `migration.json` and `ops.json` with the correct hash + metadata. Mirror the existing `MIGRATION.HASH_MISMATCH` wording via a shared `reemitHint(dir, fallback)` helper. `errorSameSourceAndTarget` now takes the package `dirPath` so it can render the same cwd-relative hint; `dag.ts` updated accordingly. Addresses CodeRabbit thread on `errorInvalidManifest` (#384 (comment)) and the operator’s broader directive to standardise migration-tools remediation wording.
Previously the dag.test.ts `pkg()` helper computed `migrationHash` from a synthetic `createdAt` (with the per-pkg counter appended) but returned metadata with the original `createdAt`. Each fixture package was therefore internally inconsistent and could never round-trip through `readMigrationPackage()`. Bake the counter into the metadata `createdAt` once and hash that exact metadata, so fixtures are loader-safe and would catch hash-verification regressions. Addresses CodeRabbit thread #384 (comment).
…lure (A12a) `migration plan` previously rethrew non-`MigrationToolsError` exceptions from the migration-load phase, bypassing `handleResult()` and crashing the command. Wrap such failures in `errorUnexpected(...)` so the user sees the same structured CLI envelope (Result pattern) as every other failure path. Addresses CodeRabbit review-body finding #384 (review) (migration-plan.ts ~165-205, outside-diff major).
…t contract hash) (A11) The JSDoc on `resolveBundleByPrefix` said "exact hash or prefix match" without specifying which hash. The implementation matches `metadata.to` (the contract hash a migration produces), not `metadata.migrationHash` (the package's content-addressed identity). Tighten wording so future maintainers do not mistakenly switch the resolver to migrationHash semantics. Addresses CodeRabbit nitpick #384 (review).
…12b, A12c, A12d)
Three small assertion tightenings flagged by CodeRabbit on the migrationHash
contract — each one currently a silent gap that would let a real regression
slip through:
- migration-cli.test.ts `preserves contract bookends`: assert that
`migrationHash` is rewritten from on-disk `null` to a real `sha256:...`
digest. Without this assertion, MigrationCLI.run could silently keep the
null and produce a package readMigrationPackage() rejects.
- output.json-shapes.test.ts pathDecision blocks: assert `selectedPath[0]`
shape directly (dirName / migrationHash / from / to). The surrounding
Object.keys snapshot only covered top-level pathDecision keys, so dropping
`migrationHash` from the wire shape would not have failed.
- mongo-migration.e2e.test.ts manifest casts: tighten from
`{ migrationHash: string | null }` to `{ migrationHash: string }` so
ever producing `null` on disk fails type-checking.
Addresses three nitpicks from CodeRabbit review
#384 (review).
When `migration plan` succeeds without placeholders, `writeMigrationPackage` has already emitted ops.json + migration.json with a fully attested migrationHash, so the previous `Next: node <dir>/migration.ts to emit ops.json and attest migrationHash before running prisma-next migration apply` instruction was actively misleading: it told the user to repeat work the planner had already done. Replace with a direct pointer at `prisma-next migration apply`. The placeholder branch keeps its existing `Then run: node <dir>/migration.ts` instruction, which is correct (placeholders genuinely require a self-emit round-trip). Addresses CodeRabbit review on PR #384.
…lpers createAttestedPackage and writeTestPackage are documented to always produce internally-consistent (attested) packages — the migrationHash is computed over the exact (metadata, ops) that get returned/written. The metadataOverrides parameter was typed Partial<MigrationMetadata>, which let callers smuggle a custom migrationHash past createTestMetadata's `overrides.migrationHash ?? computeMigrationHash(...)` fallback and produce an inconsistent fixture without going through the explicit post-write tamper step the helpers are designed for. Tighten the override type to Omit<Partial<MigrationMetadata>, 'migrationHash'> on both helpers so accidental hash injection becomes a compile error. createTestMetadata stays as-is — hash.test.ts intentionally injects a migrationHash to verify computeMigrationHash ignores the existing field. Addresses CodeRabbit review on PR #384 (review body, fixtures.ts:49-58 + 85-91).
`MIGRATION.FILE_MISSING`, `MIGRATION.INVALID_JSON`, `MIGRATION.INVALID_MANIFEST`, and `MIGRATION.SAME_SOURCE_AND_TARGET` previously instructed users to delete the directory and re-run `migration plan`. That is the wrong primitive — `migration plan` emits a *new* package, while every existing package can self-emit by running its author-time `migration.ts`, regenerating `migration.json` and `ops.json` with the correct hash + metadata. Mirror the existing `MIGRATION.HASH_MISMATCH` wording via a shared `reemitHint(dir, fallback)` helper. `errorSameSourceAndTarget` now takes the package `dirPath` so it can render the same cwd-relative hint; `dag.ts` updated accordingly. Addresses CodeRabbit thread on `errorInvalidManifest` (#384 (comment)) and the operator’s broader directive to standardise migration-tools remediation wording.
Previously the dag.test.ts `pkg()` helper computed `migrationHash` from a synthetic `createdAt` (with the per-pkg counter appended) but returned metadata with the original `createdAt`. Each fixture package was therefore internally inconsistent and could never round-trip through `readMigrationPackage()`. Bake the counter into the metadata `createdAt` once and hash that exact metadata, so fixtures are loader-safe and would catch hash-verification regressions. Addresses CodeRabbit thread #384 (comment).
…lure (A12a) `migration plan` previously rethrew non-`MigrationToolsError` exceptions from the migration-load phase, bypassing `handleResult()` and crashing the command. Wrap such failures in `errorUnexpected(...)` so the user sees the same structured CLI envelope (Result pattern) as every other failure path. Addresses CodeRabbit review-body finding #384 (review) (migration-plan.ts ~165-205, outside-diff major).
…t contract hash) (A11) The JSDoc on `resolveBundleByPrefix` said "exact hash or prefix match" without specifying which hash. The implementation matches `metadata.to` (the contract hash a migration produces), not `metadata.migrationHash` (the package's content-addressed identity). Tighten wording so future maintainers do not mistakenly switch the resolver to migrationHash semantics. Addresses CodeRabbit nitpick #384 (review).
…12b, A12c, A12d)
Three small assertion tightenings flagged by CodeRabbit on the migrationHash
contract — each one currently a silent gap that would let a real regression
slip through:
- migration-cli.test.ts `preserves contract bookends`: assert that
`migrationHash` is rewritten from on-disk `null` to a real `sha256:...`
digest. Without this assertion, MigrationCLI.run could silently keep the
null and produce a package readMigrationPackage() rejects.
- output.json-shapes.test.ts pathDecision blocks: assert `selectedPath[0]`
shape directly (dirName / migrationHash / from / to). The surrounding
Object.keys snapshot only covered top-level pathDecision keys, so dropping
`migrationHash` from the wire shape would not have failed.
- mongo-migration.e2e.test.ts manifest casts: tighten from
`{ migrationHash: string | null }` to `{ migrationHash: string }` so
ever producing `null` on disk fails type-checking.
Addresses three nitpicks from CodeRabbit review
#384 (review).
…geSet (A12e) `loadAllMigrationPackages` was a same-behaviour wrapper around `loadMigrationPackages`, retained only for naming clarity from the era when the CLI distinguished attested and draft package sets. The draft state was removed earlier in this PR — the alias now just preserves stale vocabulary and breaks the "no backward-compat shims" guideline. Inline the alias and the `MigrationPackageSet` type at the three callers (`migration plan` / `migration apply` / `migration status`); update mocks and explanatory comments in `migration-plan-command.test.ts` and `migration-tamper.test.ts`. The single `MigrationPackageSet` user (`migration-apply.ts`) now uses `Awaited<ReturnType<typeof loadMigrationPackages>>` directly so the return shape stays in one place. Addresses CodeRabbit nitpick #384 (review) (command-helpers.ts ~155-178).
closes TML-2264
Intent
Make every read of an on-disk migration package a verified read. Before this branch, hash verification of
(metadata, ops)lived as a defensive loop insidemigration applyonly — every other migration command (plan,status,show,new,ref) and every future programmatic consumer trusted what came back from disk. The fix is to move the integrity check into the loader itself, so the apply path no longer carries a redundant loop, and any other caller that goes throughreadMigrationPackageinherits hash verification by construction.The work also brings the migration-tools vocabulary in line with what the package now does:
migrationHash(notmigrationId),MigrationPackage(notMigrationBundle),MigrationMetadata(notMigrationManifest),hash.ts(notattestation.ts). Identity is computed by hashing; that's now the name of the field, the file, and the helper.Change map
computeMigrationHash+verifyMigrationHashreadMigrationPackagecallsverifyMigrationHashafter structural validation; throwsMIGRATION.HASH_MISMATCHon mismatcherrorMigrationHashMismatchfactory with cwd-relativedirin the human surface and absolutedir+storedHash+computedHashindetailsmapMigrationToolsErrorhelper used by every command that loads packagesmigration-plan.ts,migration-status.ts,migration-show.ts,migration-new.ts,migration-ref.ts— all route theirMigrationToolsErrorthrough the shared helperMigrationRunner.executeexecuteMigrationApplytypes.tsdecomposed into per-concept filesmigration.jsonfiles underexamples/carrymigrationHash(wasmigrationId); the codemod was a pure-text rename of the top-level key onlyapply/plan/status/show/newplus a cross-command envelope-uniformity assertionrefreadMigrationPackageitself (ops tampered, metadata tampered)readMigrationsDirpropagatesMIGRATION.HASH_MISMATCHfrom any tampered childThe story
readMigrationPackagebecomes the single point of trust: parse → structurally validate → rehash(metadata, ops)→ fail closed if the recomputed hash doesn't match the storedmigrationHash. Any caller — CLI command, programmatic apply, future consumer — inherits verification by virtue of using the loader.readMigrationsDirinherits transitively, so directory enumeration also fails closed on the first tampered child.migration applywas the original (and only) integrity gate, and it became strictly redundant once the loader owned the check. Deleting it removes the second source of truth and the mismatched diagnostic shape it would have produced.MigrationRunner.executeandexecuteMigrationApplynow carry a JSDoc invariant: theirplan/pendingMigrationsparameters are trusted input. Programmatic callers must come throughreadMigrationPackageupstream. Author-time write paths (MigrationCLI.runfrom TML-2301) are intentionally non-verifying — re-authoring a migration is expected to invalidate the prior hash, so verifying there would block legitimate regenerations. The result is a clean two-loader split: verifying loader for apply-time reads, non-verifying loader for author-time writes.refhad drifted into three different envelope shapes forMigrationToolsError. Lift a singlemapMigrationToolsErrorhelper intocli-errors.ts; every command calls it, so the JSON envelope (code,dir,storedHash,computedHash, plus the rest ofdetails) and the human-rendered diagnostic (summary,why,fix) are now identical regardless of which command triggered the load. While here, fix the divergence wheremigration newdefaulted to a differentcontract.jsonpath than its sister commands.migrationId→migrationHash(the value is a hash; "id" was historical);MigrationBundle→MigrationPackage(the on-disk thing was always called a package elsewhere);MigrationManifest→MigrationMetadata(it's a metadata envelope, not an Apple-style "manifest");attestation.ts→hash.ts;verifyMigrationBundle→verifyMigrationHash;computeMigrationId→computeMigrationHash. The on-disk wire field renamed in lockstep across 113 example migrations via codemod.types.tsis gone; its contents are now split intometadata.ts,package.ts,graph.ts, anderrors.ts— one concept per file.Behavior changes & evidence
readMigrationPackagefails closed on tamper. Any read of a migration package that doesn't round-trip itsmigrationHashraisesMIGRATION.HASH_MISMATCHwith the offendingdir,storedHash, andcomputedHashindetails. Previously, onlymigration apply's loop caught this; every other path silently trusted the on-disk bytes.readMigrationsDirpropagates from a tampered childattestation.test.ts)All package-loading CLI commands surface the same diagnostic on tamper.
apply,plan,status,show, andnewall produce a byte-equal user-rendered diagnostic and a structurally identical JSON envelope (code: MIGRATION.HASH_MISMATCH, plusdir/storedHash/computedHashinmeta) when they load a tampered package.migration refcarries the same envelope shape for its own loader-surface errors (e.g.MIGRATION.UNKNOWN_REF).MigrationToolsError → CliStructuredErrormapper means there's one definition of "what does the CLI tell users about a tooling error." Diverging mappers had been silently droppingdetailspayloads on three of the five commands, so JSON consumers (--json) couldn't read structural fields likedireven though the human text was uniform.refdelegates to the same helper instead of hand-building an enveloperefmigration applyno longer carries a per-bundle verify-loop. The apply command used to rehash every loaded bundle in a defensive loop before driving the runner; that loop is removed and the runner'spendingMigrationsparameter is documented as trusted input.MigrationRunner.executeandexecuteMigrationApply).e621a2062)MigrationRunner.executeexecuteMigrationApplyapplystill surfacesMIGRATION.HASH_MISMATCHbefore connecting to the database; the diagnostic now comes from the loader rather than the deleted loop, but the user-visible behaviour is unchangedmigration newresolvescontract.jsonfrom the same path as its sister commands. Previouslynewdefaulted to<config-dir>/contract.json; the four loading commands defaulted tosrc/prisma/contract.json.newnow uses the sameresolveContractPath(config)helper.new. The author wanted to scaffold a new migration in a project laid out the standard way and got "contract not found" becausenewlooked in the wrong place.newarm ofmigration-tamper.test.ts— the test no longer needs the explicitcontract.outputworkaround it had been carryingNo behavior change (refactor):
MigrationBundle→MigrationPackage,MigrationManifest→MigrationMetadata,migrationId→migrationHash(in-memory and on-disk),attestation.ts→hash.ts,verifyMigrationBundle→verifyMigrationHash,computeMigrationId→computeMigrationHash,loadMigrationBundles→loadMigrationPackages,loadAllBundles→loadAllMigrationPackages,MigrationGraph.migrationById→MigrationGraph.migrationByHash,errorDuplicateMigrationId→errorDuplicateMigrationHash.types.tsdeleted; contents split intometadata.ts,package.ts,graph.ts,errors.ts. The on-disk JSON for the 113 example migrations is byte-identical apart from the top-level field rename.Compatibility / migration / risk
migration.jsonrenames frommigrationIdtomigrationHash. Identity is still computed by hashing the same payload — the field name is the only delta. The repo-internal codemod (commitf506fb2d6) renamed the field across all 113 example/fixture migrations. No downstream consumer outsideprisma-nextreads this field directly, so the change is internal.apply/plan/status/show/newwill now fail withMIGRATION.HASH_MISMATCHinstead of silently using the edited bytes. This is the intended behaviour, and the diagnostic includes a re-emit hint:node migrations/<dir>/migration.ts.MigrationRunner.executeandexecuteMigrationApply: documented in JSDoc, not enforced. Programmatic callers that bypassreadMigrationPackageand feed a hand-builtplan/pendingMigrationsinto the runner are responsible for verifying their own input. Inside this PR, every CLI call site routes through the verifying loader, so the invariant holds in practice.verifyMigrationHashrehashes(metadata, ops)per package on load. Migration packages are small, hashes are cheap, and the loader runs once per CLI invocation.Follow-ups / open questions
ops.json") is a separate guarantee tracked under TML-2316.MigrationCLI.runauthor-time orchestrator landed via merge mid-project. The two-loader split (verifyingreadMigrationPackagefor apply-time reads, non-verifyingreadExistingMetadatainsideMigrationCLI.runfor author-time writes) is the resulting architecture and is documented inline at the non-verifying call site.Non-goals / intentionally out of scope
hash.tsJSDoc references it for the canonicalization-rule rationale, but the ADR itself is untouched.signaturefield onMigrationMetadatais read through but is not part of the integrity check this PR adds; the field is intentionally stripped before hashing so a future signing scheme can co-exist with structural verification.Summary by CodeRabbit
New Features
Bug Fixes
Chores
Documentation
Tests