@prisma/orm-mongo 8.0.1-dev.3 → 8.0.1-dev.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/contract-builder.d.mts +10 -12
- package/dist/contract-builder.d.mts.map +1 -1
- package/dist/contract-types.d.mts +3 -3
- package/dist/{mongo-static-BV3j1fN5-TbRr6qQe.mjs → mongo-static-mpUQsCV6-Djox0d1n.mjs} +4 -4
- package/dist/mongo-static-mpUQsCV6-Djox0d1n.mjs.map +1 -0
- package/dist/runtime.d.mts +2 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +6 -6
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.mjs +1 -1
- package/package.json +12 -81
- package/skills/prisma-8/SKILL.md +7 -7
- package/skills/prisma-8/references/contract.md +1 -1
- package/skills/prisma-8/references/debug.md +11 -11
- package/skills/prisma-8/references/migration-model.md +17 -17
- package/skills/prisma-8/references/migration-review.md +21 -21
- package/skills/prisma-8/references/migrations.md +58 -42
- package/skills/prisma-8/references/queries-postgres.md +7 -7
- package/skills/prisma-8/references/quickstart.md +11 -11
- package/skills/prisma-8/references/runtime.md +3 -3
- package/skills/prisma-8/references/upgrade-app.md +55 -17
- package/skills/prisma-8/references/upgrade-extension.md +34 -11
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +1 -1
- package/skills/prisma-8/upgrading/extension/upgrades/0.8-to-0.9/instructions.md +1 -1
- package/skills/prisma-8/upgrading/extension/upgrades/0.9-to-0.10/instructions.md +1 -1
- package/dist/adapter.d.mts +0 -1
- package/dist/adapter.mjs +0 -2
- package/dist/adapter__control.d.mts +0 -3
- package/dist/adapter__control.mjs +0 -3
- package/dist/adapter__runtime.d.mts +0 -3
- package/dist/adapter__runtime.mjs +0 -3
- package/dist/components.d.mts +0 -1
- package/dist/components.mjs +0 -2
- package/dist/components__authoring.d.mts +0 -1
- package/dist/components__authoring.mjs +0 -2
- package/dist/components__codec.d.mts +0 -1
- package/dist/components__codec.mjs +0 -2
- package/dist/components__components.d.mts +0 -1
- package/dist/components__components.mjs +0 -2
- package/dist/components__control.d.mts +0 -1
- package/dist/components__control.mjs +0 -2
- package/dist/components__emission.d.mts +0 -1
- package/dist/components__emission.mjs +0 -2
- package/dist/components__execution.d.mts +0 -1
- package/dist/components__execution.mjs +0 -2
- package/dist/components__ir.d.mts +0 -1
- package/dist/components__ir.mjs +0 -2
- package/dist/components__psl-ast.d.mts +0 -1
- package/dist/components__psl-ast.mjs +0 -2
- package/dist/components__utils.d.mts +0 -1
- package/dist/components__utils.mjs +0 -2
- package/dist/contract.d.mts +0 -1
- package/dist/contract.mjs +0 -2
- package/dist/contract__apply-specifier-default-control-policy.d.mts +0 -1
- package/dist/contract__apply-specifier-default-control-policy.mjs +0 -2
- package/dist/contract__contract-validation-error.d.mts +0 -1
- package/dist/contract__contract-validation-error.mjs +0 -2
- package/dist/contract__default-namespace.d.mts +0 -1
- package/dist/contract__default-namespace.mjs +0 -2
- package/dist/contract__enum-accessor.d.mts +0 -1
- package/dist/contract__enum-accessor.mjs +0 -2
- package/dist/contract__format-version.d.mts +0 -1
- package/dist/contract__format-version.mjs +0 -2
- package/dist/contract__hashing-utils.d.mts +0 -1
- package/dist/contract__hashing-utils.mjs +0 -2
- package/dist/contract__hashing.d.mts +0 -1
- package/dist/contract__hashing.mjs +0 -2
- package/dist/contract__internal__format-version.d.mts +0 -1
- package/dist/contract__internal__format-version.mjs +0 -2
- package/dist/contract__is-plain-record.d.mts +0 -1
- package/dist/contract__is-plain-record.mjs +0 -2
- package/dist/contract__resolve-domain-model.d.mts +0 -1
- package/dist/contract__resolve-domain-model.mjs +0 -2
- package/dist/contract__validate-domain.d.mts +0 -1
- package/dist/contract__validate-domain.mjs +0 -2
- package/dist/contract__validate-once.d.mts +0 -1
- package/dist/contract__validate-once.mjs +0 -2
- package/dist/contract__validate-storage.d.mts +0 -1
- package/dist/contract__validate-storage.mjs +0 -2
- package/dist/driver.d.mts +0 -1
- package/dist/driver.mjs +0 -2
- package/dist/driver__control.d.mts +0 -3
- package/dist/driver__control.mjs +0 -3
- package/dist/driver__runtime.d.mts +0 -3
- package/dist/driver__runtime.mjs +0 -3
- package/dist/family-contract__canonicalization-hooks.d.mts +0 -1
- package/dist/family-contract__canonicalization-hooks.mjs +0 -2
- package/dist/family-contract__data-type.d.mts +0 -1
- package/dist/family-contract__data-type.mjs +0 -2
- package/dist/family-contract__entity-kinds.d.mts +0 -1
- package/dist/family-contract__entity-kinds.mjs +0 -2
- package/dist/family__control-adapter.d.mts +0 -1
- package/dist/family__control-adapter.mjs +0 -2
- package/dist/family__ir.d.mts +0 -1
- package/dist/family__ir.mjs +0 -2
- package/dist/family__migration.d.mts +0 -1
- package/dist/family__migration.mjs +0 -2
- package/dist/family__pack.d.mts +0 -3
- package/dist/family__pack.mjs +0 -3
- package/dist/family__runtime.d.mts +0 -1
- package/dist/family__runtime.mjs +0 -2
- package/dist/family__schema-verify.d.mts +0 -1
- package/dist/family__schema-verify.mjs +0 -2
- package/dist/migration-tools__contract-snapshot-store.d.mts +0 -1
- package/dist/migration-tools__contract-snapshot-store.mjs +0 -2
- package/dist/mongo-static-BV3j1fN5-TbRr6qQe.mjs.map +0 -1
- package/dist/query-ast.d.mts +0 -1
- package/dist/query-ast.mjs +0 -2
- package/dist/query-ast__control.d.mts +0 -1
- package/dist/query-ast__control.mjs +0 -2
- package/dist/query-builder__contract-free.d.mts +0 -1
- package/dist/query-builder__contract-free.mjs +0 -2
- package/dist/target__codecs.d.mts +0 -1
- package/dist/target__codecs.mjs +0 -2
- package/dist/target__control.d.mts +0 -1
- package/dist/target__control.mjs +0 -2
- package/dist/target__data-types.d.mts +0 -1
- package/dist/target__data-types.mjs +0 -2
- package/dist/target__pack.d.mts +0 -3
- package/dist/target__pack.mjs +0 -3
- package/dist/target__server-version.d.mts +0 -1
- package/dist/target__server-version.mjs +0 -2
- package/dist/utils.d.mts +0 -1
- package/dist/utils.mjs +0 -2
- package/dist/utils__abortable.d.mts +0 -1
- package/dist/utils__abortable.mjs +0 -2
- package/dist/utils__array-equal.d.mts +0 -1
- package/dist/utils__array-equal.mjs +0 -2
- package/dist/utils__assertions.d.mts +0 -1
- package/dist/utils__assertions.mjs +0 -2
- package/dist/utils__canonical-stringify.d.mts +0 -1
- package/dist/utils__canonical-stringify.mjs +0 -2
- package/dist/utils__casts.d.mts +0 -1
- package/dist/utils__casts.mjs +0 -2
- package/dist/utils__defined.d.mts +0 -1
- package/dist/utils__defined.mjs +0 -2
- package/dist/utils__guards.d.mts +0 -1
- package/dist/utils__guards.mjs +0 -2
- package/dist/utils__hash-content.d.mts +0 -1
- package/dist/utils__hash-content.mjs +0 -2
- package/dist/utils__internal-error.d.mts +0 -1
- package/dist/utils__internal-error.mjs +0 -2
- package/dist/utils__json.d.mts +0 -1
- package/dist/utils__json.mjs +0 -2
- package/dist/utils__promise.d.mts +0 -1
- package/dist/utils__promise.mjs +0 -2
- package/dist/utils__redact-db-url.d.mts +0 -1
- package/dist/utils__redact-db-url.mjs +0 -2
- package/dist/utils__result.d.mts +0 -1
- package/dist/utils__result.mjs +0 -2
- package/dist/utils__simplify-deep.d.mts +0 -1
- package/dist/utils__simplify-deep.mjs +0 -2
- package/dist/utils__structured-error.d.mts +0 -1
- package/dist/utils__structured-error.mjs +0 -2
- package/dist/utils__suppress-idle-connection-errors.d.mts +0 -1
- package/dist/utils__suppress-idle-connection-errors.mjs +0 -2
- package/dist/utils__text.d.mts +0 -1
- package/dist/utils__text.mjs +0 -2
- package/dist/utils__types.d.mts +0 -1
- package/dist/utils__types.mjs +0 -2
- package/dist/utils__upgrade-guides.d.mts +0 -1
- package/dist/utils__upgrade-guides.mjs +0 -2
- package/dist/value__mongodb-types.d.mts +0 -1
- package/dist/value__mongodb-types.mjs +0 -2
|
@@ -49,7 +49,7 @@ Every code is a dotted `NAMESPACE.SUBCODE`; the namespace is the prefix (`CONFIG
|
|
|
49
49
|
{ name: 'RuntimeError', code: 'BUDGET.TIME_EXCEEDED', category: 'BUDGET', severity: 'error', message: '...', details: { ... } }
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
`category` is the prefix of `code` (`PLAN`, `CONTRACT`, `LINT`, `BUDGET`, `RUNTIME`, `ORM`, …). `details` holds the structured context (`details` is the runtime envelope's equivalent of the CLI envelope's `meta`). Recognise
|
|
52
|
+
`category` is the prefix of `code` (`PLAN`, `CONTRACT`, `LINT`, `BUDGET`, `RUNTIME`, `ORM`, …). `details` holds the structured context (`details` is the runtime envelope's equivalent of the CLI envelope's `meta`). Recognise a thrown runtime error with `isStructuredError`, imported from the database package's `runtime` (`import { isStructuredError } from '@prisma/orm-postgres/runtime'`), and match on `error.code` — never `instanceof`. The CLI envelope is JSON output, with `summary` and no `message`, so `isStructuredError` does not recognise it; a script reads `code` from the parsed JSON instead.
|
|
53
53
|
|
|
54
54
|
**3. SQL driver errors** — surface as `SqlQueryError` / `SqlConnectionError` (see `packages/2-sql-family/1-core/errors/`). Fields on `SqlQueryError`: `kind: 'sql_query'`, `sqlState` (Postgres SQLSTATE, e.g. `'23505'`), `constraint`, `table`, `column`, `detail`, `cause`. These carry no dotted code — route on `sqlState` and the constraint metadata. SQL driver errors are typically wrapped by middleware before reaching the user, but raw-SQL paths can surface them directly.
|
|
55
55
|
|
|
@@ -84,18 +84,18 @@ The single source of truth: read the envelope, find the row by `code`, follow th
|
|
|
84
84
|
| `CONTRACT.VALIDATION_FAILED` | `contract emit`, `db *` | Re-run `pnpm prisma contract emit` after fixing the contract source named in `where.path`; `meta.errors` lists the issues. See `references/contract.md`. |
|
|
85
85
|
| `CONFIG.DB_CONNECTION_REQUIRED` | `db *`, `db migrate`, `migration status` | Pass `--db <url>` or set `db.connection` in `prisma.config.ts`. |
|
|
86
86
|
| `CONFIG.MISSING_EXTENSION_PACKS` | `contract emit` (e.g. contract uses `pgvector.Vector(...)` but config does not list the pgvector descriptor) | Add the descriptors named in `meta.missingExtensionPacks` to `extensions` in `prisma.config.ts`. See `references/contract.md`. |
|
|
87
|
-
| `MIGRATION.PLANNING_FAILED` | `db init`, `db update`, `migration plan` | Inspect `meta.conflicts`. Recovery is per-conflict — chain to `references/migrations.md`. When `migration plan` raises it for a first migration whose contract describes nothing to create (conflict kind `nothingToCreate`), the conflict's `why` gives the next step: `migration new`, with the operations written by hand. A plan from an earlier contract with no operations is not refused: it is written, and `db migrate` moves the
|
|
87
|
+
| `MIGRATION.PLANNING_FAILED` | `db init`, `db update`, `migration plan` | Inspect `meta.conflicts`. Recovery is per-conflict — chain to `references/migrations.md`. When `migration plan` raises it for a first migration whose contract describes nothing to create (conflict kind `nothingToCreate`), the conflict's `why` gives the next step: `migration new`, with the operations written by hand. A plan from an earlier contract with no operations is not refused: it is written, and `db migrate` moves the contract signature. |
|
|
88
88
|
| `CLI.INIT_MISSING_FLAGS` / `CLI.INIT_INVALID_FLAG_VALUE` / `CLI.INIT_REINIT_NEEDS_FORCE` / `CLI.INIT_*` | `prisma orm init` | Re-run with the flags listed in `meta.missingFlags` or `meta.allowed`; a re-init needs `--confirm <directory name>`. `CLI.INIT_INSTALL_FAILED` (exit 4) and `CLI.INIT_EMIT_FAILED` (exit 5) are findings on a completed scaffold — the files are on disk; fix and re-run the named step. |
|
|
89
89
|
| `MIGRATION.UNFILLED_PLACEHOLDER` | `node <package dir>/migration.ts` (self-emit) or `db migrate` | Edit `migration.ts`, replace the `placeholder("<slot>")` named by `meta.slot` with a real query closure, self-emit. See `references/migrations.md`. |
|
|
90
90
|
| `MIGRATION.FILE_MISSING` | Reading a migration package | Restore from version control or scaffold a fresh package with `migration plan` / `migration new`. |
|
|
91
91
|
| `MIGRATION.INVALID_DEFAULT_EXPORT` | Loading `migration.ts` | Use `export default class extends Migration<Start, End> { ... }` (or a factory returning `{ operations, targetId, destination }`). See `references/migrations.md`. |
|
|
92
92
|
| `MIGRATION.DATA_TRANSFORM_CONTRACT_MISMATCH` | Building a data-transform query plan | Pass the `contract` that `postgres({ contract: contractFromJson<End>(endContract) })` returns to `this.dataTransform(contract, …)`, and build the queries with that client's `sql`. |
|
|
93
93
|
| `MIGRATION.HASH_MISMATCH` | Any read of a migration package (`plan`, `list`, `db migrate`) | `ops.json` / `migration.json` were edited without self-emitting. Run `node <package dir>/migration.ts` to re-emit. |
|
|
94
|
-
| `CONTRACT.
|
|
95
|
-
| `CONTRACT.
|
|
94
|
+
| `CONTRACT.SIGNATURE_MISSING` | `db verify` (`error` diagnostic, exit 4), runtime startup (warning) | DB has no signature yet. Run `prisma db init --db <url>` (baseline empty DB), `db update --db <url>` (apply contract directly), or `db sign --db <url>` if the schema already matches the contract. |
|
|
95
|
+
| `CONTRACT.SIGNATURE_MISMATCH` | `db verify` (exit 4), runtime startup (warning) | Signature disagrees with contract hash (`meta.expected` / `meta.actual`). Either migrate forward (`db migrate` / `db update`), or — if the DB is correct after a manual fix-up — `db sign`. See `references/migrations.md`. |
|
|
96
96
|
| `CONTRACT.TARGET_MISMATCH` | `db verify`, runtime startup | Contract target ≠ config target; align them (see `meta.expected` / `meta.actual`). |
|
|
97
97
|
| `CONTRACT.SCHEMA_VERIFICATION_FAILED` | `db verify`, `db sign` (both exit 4 with the finding) | Live schema does not satisfy the contract; `meta.schemaIssues` lists the schema diff issues per `meta.space`, in the same shape as `MIGRATION.SCHEMA_VERIFY_FAILED`. Run `db update` to reconcile, or adjust the contract. |
|
|
98
|
-
| `MIGRATION.SCHEMA_VERIFY_FAILED` | `db migrate`, `db update`, `db init` | The schema after apply does not satisfy the contract; the
|
|
98
|
+
| `MIGRATION.SCHEMA_VERIFY_FAILED` | `db migrate`, `db update`, `db init` | The schema after apply does not satisfy the contract; the signature stays at its origin, and on SQL targets the apply rolled back (on MongoDB the operations that ran stay applied). `meta.schemaIssues` lists the issues and `why` names them. Change the contract source to resolve them, re-emit, and re-run; `db migrate` also says how to plan the failed migration again. |
|
|
99
99
|
| `MIGRATION.PRECHECK_FAILED` | `db migrate`, `db update`, `db init` | An operation's check before it ran did not hold (`meta.failedCheck`); the apply rolled back on SQL targets. `meta.rowsWithoutValue` is set when a field becoming required has rows with no value. Follow `nextActions`. |
|
|
100
100
|
| `CLI.CONSENT_REQUIRED` | `migration plan` / `db update` when a plan would lose data (or, on `db update`, widen access) and nobody can answer (`--no-interactive`, CI, `--yes`) | `meta.unanswered[]` and `nextActions` list each question with its flags. Re-run with `--delete <subject>`, `--rename <subject>:<new name>` or `--allow <Model>` as each subject means. `--confirm` and `--yes` answer none of them. `db migrate` does not ask. |
|
|
101
101
|
| `CLI.CONSENT_UNUSED` | `migration plan` / `db update` | Every question was answered, and a `--delete` or `--allow` was left over: a typo, a subject the plan does not touch, or a `--confirm` (which consents to nothing). Fix or drop the flag. A typo next to a question nobody answered is reported as `CLI.CONSENT_REQUIRED` instead, which names the flag that matched nothing. On `db update --dry-run` the same mistake is `MIGRATION.STATEMENT_ANSWERS_NO_QUESTION`. |
|
|
@@ -103,14 +103,14 @@ The single source of truth: read the envelope, find the row by `code`, follow th
|
|
|
103
103
|
| `MIGRATION.NO_INVARIANT_PATH` / `MIGRATION.UNKNOWN_INVARIANT` | `db migrate` | Concurrent-migration and invariant flows — `references/migration-review.md`. |
|
|
104
104
|
| `DRIVER.NOT_CONNECTED` with message `Runtime is closed` | A query, prepared statement or `db.runtime().connection()` that starts after `db.close()` and after the runtime was idle for one turn of the event loop, or after the `await using` scope that held a serverless connection ended | The work started after the runtime closed. Almost always it is a lazy read (`db.orm...all()`, `db.query(...)`) returned without `await`, which starts only when the caller awaits it, or work that waited on something other than the database first. Write `return await ...`, or move the call before `close()`. See `references/runtime.md` § *Workflow — Serverless and per-request runtimes*. |
|
|
105
105
|
| `await db.close()` or the end of an `await using` scope never settles in a test | A test that installed fake timers (`vi.useFakeTimers()`, Jest's modern fake timers) before the Prisma runtime module was imported | `close()` waits one turn of the event loop through a `setTimeout(0)` that the runtime module takes when it loads. Install fake timers after the imports, or advance the fake clock (`await vi.runAllTimersAsync()`) before awaiting the close. |
|
|
106
|
-
| `MIGRATION.
|
|
106
|
+
| `MIGRATION.SIGNATURE_NOT_IN_GRAPH` | `db migrate`, `db migrate --show`, a Composer deploy | The database's signature is not in the migration graph, usually because a migration it applied was planned again or deleted. `why` names the last graph contract it applied and the missing migrations. `nextActions` gives the one recovery the database's change policy permits. Follow `references/migrations.md` § *A database whose signature is not in the migration graph*. Never reset or drop the database. |
|
|
107
107
|
| `MIGRATION.CHANGE_POLICY_FORBIDS` | `db update`, `db sign`, `db migrate` | The database's change policy does not include what the command does. When `db update` or `db sign` is refused, follow its advice: apply the migrations on disk that already lead to the target with `db migrate`, or author one (with `migration plan`, or with `migration new` when the database is already at the target and lacks only invariants) and apply it with `db migrate`. See `references/migrations.md` § *Policies*. |
|
|
108
108
|
| `MIGRATION.DATA_PROTECTION_FORBIDS` | `db update`, `db migrate`, `migration plan --to <ref>`, a Composer deploy | The database's data protection policy (or the ref's, for `migration plan --to <ref>` and a run given `--permit-policy-change`) forbids an operation that loses data or changes who can read or write rows. `meta.operations` lists them. The operation cannot run on that database. For `db update` and `migration plan`, a refused data loss: state a `--rename` if it was only a rename, plan a type change with `migration plan --convert`, or keep the model or field. A refused access change: keep the contract's access rules as they are. For `db migrate`, first find out whether another database has applied the refused migration; if one has, keep it as it is and tell the user that this database cannot run it. If none has, delete it and every later migration no database has applied, and plan once from where the first one started, with `--rename`, `--convert`, or after putting back in the contract what it removes; never only take the operation out of the migration. The full steps (saving hand-written operations, `--from`, `contract emit`, moving refs) are in `references/migrations.md` § *Policies*. For `db migrate` and `db update`, an operation in an extension's contract space belongs to the extension: do not edit or delete its migration; ask the extension's author for a version without the operation, and tell the user. `--delete` and `--allow` do not help. Never change a database's or a ref's policy to make a deploy pass, and never suggest that anyone does. See `references/migrations.md` § *Policies*. |
|
|
109
109
|
| `MIGRATION.POLICY_MISMATCH` | `db migrate --to <ref>`, `db update --to <ref>`, a Composer deploy | The ref declares a policy that differs from the database's, and nothing runs while they differ. The error says to report the difference to whoever owns the database: tell the user. Never change the ref's or the database's policies to make them match, and never suggest that anyone does. See `references/migrations.md` § *Policies*. |
|
|
110
|
-
| `MIGRATION.PATH_UNREACHABLE` | `db migrate`, a Composer deploy | The
|
|
110
|
+
| `MIGRATION.PATH_UNREACHABLE` | `db migrate`, a Composer deploy | The signature is in the graph but no migration reaches the target from it. Run the two commands the error prints: a `migration plan --from <contract>`, with `--to <target>` unless the target is the emitted contract (a contract change emitted but not planned), then the `db migrate` that was run, with its flags. To the emitted contract, `--from` is where the history that continues from the signature ends, so the new migration extends the history instead of forking it; to any other target it is the signature. On an empty database, `--from` is where the migration history ends. When the history has more than one end, the error names each end for you to choose from. A database with no signature in a project with no migrations gets the plan from `@empty` as a choice: run it only on an empty database, and adopt one that already has tables with `db sign` first. When the path ends at the empty contract (`--to @empty`), or the project has migrations and the path starts at a contract none of them records, no plan can author it, and the error prints only `migration list`. In a project with no migrations yet, the plan starts from the ref that names the database's contract, and with no such ref the error prints no plan and says why. When an extension space has no path, the error says to install a version of the extension whose migrations start where the database is. `migration list` audits the graph. |
|
|
111
111
|
| `MIGRATION.PLAN_ORIGIN_UNKNOWN` / `MIGRATION.HASH_NOT_IN_GRAPH` / `MIGRATION.SNAPSHOT_MISSING` | `migration plan`, `migration new` | Origin resolution — `references/migration-model.md` § *The trap* and `references/migrations.md` § *Dev → ship transition*. |
|
|
112
|
-
| `MIGRATION.MISSING_INVARIANTS` | `migration status` `warn` diagnostic (exit 0) | The live
|
|
113
|
-
| `MIGRATION.
|
|
112
|
+
| `MIGRATION.MISSING_INVARIANTS` | `migration status` `warn` diagnostic (exit 0) | The live signature reached the destination hash structurally but doesn't carry all invariants the target ref requires. Run `db migrate --to <name> --db $URL` to take a path that covers the missing invariants. See `references/migration-review.md`. |
|
|
113
|
+
| `MIGRATION.SIGNATURE_NOT_IN_GRAPH` / `CONTRACT.UNREADABLE` | `migration status` `warn` diagnostics (exit 0) | Read `severity` *and* `code`. Up-to-date / pending / no-signature states are not codes — read `spaces[].currentContract` and `migrations[].status` in the `--json` document. `references/migration-review.md` covers the signature-out-of-history flow. |
|
|
114
114
|
| `BUDGET.ROWS_EXCEEDED` / `BUDGET.TIME_EXCEEDED` | Runtime, when the `budgets` middleware is active | Tune `budgets({ maxRows, maxLatencyMs, ... })` or rewrite the query. See `references/runtime.md`. |
|
|
115
115
|
| `LINT.SELECT_STAR` / `LINT.NO_LIMIT` / `LINT.DELETE_WITHOUT_WHERE` / `LINT.UPDATE_WITHOUT_WHERE` / `LINT.READ_ONLY_MUTATION` | Runtime, when the `lints` middleware is active | Fix the query (add a `WHERE` / `LIMIT` / explicit columns), or relax the lint config. See `references/runtime.md`. |
|
|
116
116
|
| `PLAN.HASH_MISMATCH` | Runtime, executing a precompiled plan | The contract the plan was built against does not match the runtime contract. Re-emit, rebuild, redeploy. |
|
|
@@ -130,8 +130,8 @@ If the envelope's `code` is not in this table, follow the envelope's `fix` field
|
|
|
130
130
|
1. **Reading only `summary`, not the rest of the envelope.** `code`, `severity`, `why`, `fix`, `meta`/`details`, and (for CLI errors) `where` all carry information the recovery depends on. The agent routes on `code`; the user sees `summary`.
|
|
131
131
|
2. **Ignoring `severity`.** `migration status` emits warn-level diagnostics and **exits 0**. An agent that only checks exit code misses every concurrent-migration warning.
|
|
132
132
|
3. **Matching `MIGRATION.RUNNER_FAILED`.** That code no longer exists: an apply failure carries the runner's own code, and its facts are in typed `meta` keys.
|
|
133
|
-
4. **Treating drift as something to silence with `db sign`.** `db sign` writes the
|
|
134
|
-
5. **Re-running `db migrate` after a partial failure without inspecting state.** `db schema --db <url>` shows the live shape; `migration status --db <url> --json` shows where the
|
|
133
|
+
4. **Treating drift as something to silence with `db sign`.** `db sign` writes the contract signature from the current contract hash and, by default, advances the `db` ref to it (`--no-advance-ref` skips the ref), but it requires schema verification to pass first. Run `db verify` before reaching for `db sign`.
|
|
134
|
+
5. **Re-running `db migrate` after a partial failure without inspecting state.** `db schema --db <url>` shows the live shape; `migration status --db <url> --json` shows where the signature actually is.
|
|
135
135
|
|
|
136
136
|
## What Prisma 8 doesn't do yet
|
|
137
137
|
|
|
@@ -28,12 +28,12 @@ The on-disk migrations under `migrations/<space>/` form a directed graph. **Each
|
|
|
28
28
|
Consequences worth internalising:
|
|
29
29
|
|
|
30
30
|
- **No node is privileged.** There is no "current" node, no HEAD, no special tip the planner chains from. Multiple branch tips are legal (two migrations planned off the same node). Cycles are legal (a rollback edge back to an earlier hash creates one).
|
|
31
|
-
- **The graph does not know where your database is.** "Where is my database" is answered by the database's **
|
|
31
|
+
- **The graph does not know where your database is.** "Where is my database" is answered by the database's **contract signature** (a live-DB record of "this database is at hash X") and, offline, by **refs**. Never by the graph.
|
|
32
32
|
- **The graph does not know where your next migration should start.** The planner has to be told an origin. That is the entire job of refs and `--from`.
|
|
33
33
|
|
|
34
34
|
### What a migration may contain
|
|
35
35
|
|
|
36
|
-
Because a migration is an edge, `db migrate` can run it on any database whose
|
|
36
|
+
Because a migration is an edge, `db migrate` can run it on any database whose contract signature is at its `from` hash, however that database got there: created by `db init`, adopted with `db sign`, restored from a backup, or brought along a different path through the graph. Those databases share a schema but not their rows, so every operation must be correct on any of them. A schema change tests the live schema before and after it runs. Most operation factories do this for you, but not all: on Postgres, `createNativeEnumType` and `dropNativeEnumType` emit no checks. A `rawSql` DDL step you write must carry its own precheck and postcheck. A data change is a data transform; on Postgres and Mongo its `check` decides on each database whether there is work to do. `references/migrations.md` § *Data changes go in a data transform* gives the rule, the reason, and what each target checks.
|
|
37
37
|
|
|
38
38
|
### Refs — version-controlled pointers
|
|
39
39
|
|
|
@@ -60,21 +60,21 @@ A ref's `policies` are read and written with `migration ref policy show`, `set`
|
|
|
60
60
|
|
|
61
61
|
| Command | Ref advancement |
|
|
62
62
|
|---|---|
|
|
63
|
-
| `db init` / `db update`
|
|
64
|
-
| `db sign` | Advances `db` after a successful signature (override the name with `--advance-ref <name>`; `--no-advance-ref` skips it, writing no ref and no snapshot); an existing ref is overwritten and the previous hash is reported in the human output (the JSON `advancedRefs` lists `{ space, name, hash }` for each contract space it advanced). `--db`
|
|
63
|
+
| `db init` / `db update` | Advance `db` when the connection comes from `prisma.config.ts` and the CLI does not detect CI, by the same rule as `db migrate` below: never when `--db` is passed without `--advance-ref`, regardless of the URL (even `--db $DATABASE_URL` pointing at the default database), and never in CI (the run then reports `MIGRATION.REF_NOT_ADVANCED_IN_CI`). `--advance-ref <name>` advances that ref instead, in every case; `--no-advance-ref` advances none. A ref that cannot be written is a warning (`MIGRATION.REF_NOT_WRITTEN`), not a failure; its next action is the command the warning prints: `migration ref set` when a migration ends at that contract, otherwise the run's command with `--advance-ref <name>` and without its statements (`--rename`, `--delete`, `--allow`), which applies nothing if the contract has not changed since. Without a ref they also store no snapshot, which a later `db update --rename` needs |
|
|
64
|
+
| `db sign` | Advances `db` after a successful signature (override the name with `--advance-ref <name>`; `--no-advance-ref` skips it, writing no ref and no snapshot); an existing ref is overwritten and the previous hash is reported in the human output (the JSON `advancedRefs` lists `{ space, name, hash }` for each contract space it advanced). `--db` and CI do **not** suppress it, unlike init/update/migrate: sign never mutates the schema, and adoption is normally done via `--db` |
|
|
65
65
|
| `db migrate` | Advances `db` after a successful apply when the connection comes from `prisma.config.ts` and the CLI does not detect CI. Never with `--db`, and never in CI (unless the `CI` environment variable is `false`, which turns detection off whatever else is set, the CLI detects CI when `CI` is set or when a variable that CI services set is present, such as `BUILD_NUMBER`, `BUILD_ID` or `GITHUB_ACTIONS`; the run then reports `MIGRATION.REF_NOT_ADVANCED_IN_CI`), so deploys and pipelines write no ref. `--advance-ref <name>` advances that ref instead, in every case; `--no-advance-ref` advances none. A run that ends at the empty contract, which a ref cannot name, leaves `db` unchanged and, when `db` exists and the run passes neither `--db` nor `--no-advance-ref`, warns (`MIGRATION.REF_NOT_ADVANCED_TO_EMPTY`; when that database is your development database, remove the stale ref with `migration ref delete db`), and refuses an explicit `--advance-ref` before applying. A ref that cannot be written is a warning (`MIGRATION.REF_NOT_WRITTEN`), not a failure: the migrations have already applied |
|
|
66
66
|
| `migration plan` | Never advances anything — chaining discipline is yours |
|
|
67
|
-
| deploys (Composer / CD) | Write the database's
|
|
67
|
+
| deploys (Composer / CD) | Write the database's contract signature; structurally cannot and do not touch repo refs |
|
|
68
68
|
|
|
69
69
|
### How `migration plan` picks its origin
|
|
70
70
|
|
|
71
71
|
`migration plan` resolves its origin in exactly this order:
|
|
72
72
|
|
|
73
|
-
1. Explicit `--from <ref-name | hash | hash-prefix | migration-dir | migration-dir^ | @empty>` — `@empty` names the empty database deliberately. The reserved forms `@db` and `@contract` exist in the shared ref grammar but do not resolve here: `migration plan` is offline, so `@db` (the live
|
|
73
|
+
1. Explicit `--from <ref-name | hash | hash-prefix | migration-dir | migration-dir^ | @empty>` — `@empty` names the empty database deliberately. The reserved forms `@db` and `@contract` exist in the shared ref grammar but do not resolve here: `migration plan` is offline, so `@db` (the live contract signature) has nothing to read, and `@contract` needs a contract hash the plan resolver does not pass. Use them with `db migrate --show` / `migration status`, not with `plan`.
|
|
74
74
|
2. No `--from` → the `db` ref (`migrations/app/refs/db.json`).
|
|
75
75
|
3. No `db` ref → **greenfield: the plan starts from the empty database.** On an empty graph the human output adds a muted notice beneath the summary — `No db ref set — planning from an empty database. Run db init, db update, or db sign if a database already exists.` — and the JSON document carries `fromDefaulted: true`, so this case is distinguishable from an explicit `--from @empty`.
|
|
76
76
|
|
|
77
|
-
It is **offline** — it never consults a database, never reads a
|
|
77
|
+
It is **offline** — it never consults a database, never reads a signature (which is why `--from @db` is not an option here). Whatever the refs on disk say is what it believes. The destination defaults to the emitted `contract.json` (`--to` overrides).
|
|
78
78
|
|
|
79
79
|
When the origin came from the `db` ref by default and that node **already has an outgoing migration**, the plan still succeeds but warns: planning from there forks the graph. Pass `--from` to name the origin deliberately if that is what you want.
|
|
80
80
|
|
|
@@ -86,7 +86,7 @@ The human output names the resolved origin on its `from:` line. **`from: (baseli
|
|
|
86
86
|
|
|
87
87
|
## The trap — a greenfield plan over existing migrations
|
|
88
88
|
|
|
89
|
-
**A plan whose origin is the empty contract while migrations already exist on disk is almost always a mistake.** A full-create migration cannot do what you meant: a database that has the prior migrations applied refuses it (`MIGRATION.PATH_UNREACHABLE` — no path from its
|
|
89
|
+
**A plan whose origin is the empty contract while migrations already exist on disk is almost always a mistake.** A full-create migration cannot do what you meant: a database that has the prior migrations applied refuses it (`MIGRATION.PATH_UNREACHABLE` — no path from its contract signature to the new plan's destination), and running its create statements against any populated schema fails outright. The CLI refuses this at plan time: when origin resolution falls all the way through (no `--from`, no `db` ref) and migrations exist, `migration plan` stops with `MIGRATION.PLAN_ORIGIN_UNKNOWN` instead of writing the package — the error's suggestions are the three exits below; do not reflexively take the `--from @empty` one, pick by intent.
|
|
90
90
|
|
|
91
91
|
How the fall-through happens: a project whose only commands run in CI or deploys (the deploy-first path below) never acquires a `db` ref, so *every* default plan resolves to the empty origin. Running the dev loop with an explicit `--db` has the same effect: `db init`, `db update` and `db migrate` with that flag never advance the ref, whatever URL it carries (`db sign` is the exception — it advances the ref with or without `--db`). The first time that is correct (it is the baseline; an empty migration graph plans with only the muted notice); every later time it is the trap the refusal catches.
|
|
92
92
|
|
|
@@ -117,7 +117,7 @@ Full mechanics, refusals, and recovery: `references/migrations.md` § *Dev → s
|
|
|
117
117
|
|
|
118
118
|
## Workflow — the deploy-first loop (Composer / CD-managed databases)
|
|
119
119
|
|
|
120
|
-
The concept: the deploy pipeline owns the databases, so `db init` / `db update` never run, `db migrate` runs only in CI or with `--db`, and nothing ever advances a `db` ref for you. Deploys replay each database from its
|
|
120
|
+
The concept: the deploy pipeline owns the databases, so `db init` / `db update` never run, `db migrate` runs only in CI or with `--db`, and nothing ever advances a `db` ref for you. Deploys replay each database from its contract signature to the contract emitted at build time; they never write to `migrations/app/refs/`. Two disciplines keep this loop safe:
|
|
121
121
|
|
|
122
122
|
**Author the baseline before the first deploy.** Before anything is deployed:
|
|
123
123
|
|
|
@@ -127,7 +127,7 @@ pnpm prisma migration plan --name init # from: (baseline) — intended, thi
|
|
|
127
127
|
git add migrations/ && git commit
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
This is the one intended greenfield plan. With the baseline committed, the deployed database's
|
|
130
|
+
This is the one intended greenfield plan. With the baseline committed, the deployed database's signature always corresponds to a graph node, and every later state is reachable by planned migrations.
|
|
131
131
|
|
|
132
132
|
**Chain every later plan from the last shipped contract.** Nothing advances refs in this loop, so either keep the `db` ref current yourself — after each plan, `migration ref set db <new-migration-to-hash>` (the hash is a graph node as soon as the plan is written; `migration list` shows it) — or pass `--from <last-migration-dir>` on every plan. Committing the ref together with the migration keeps teammates' default plans chaining correctly too.
|
|
133
133
|
|
|
@@ -135,7 +135,7 @@ If you skip the chaining, the next default plan resolves to greenfield: the trap
|
|
|
135
135
|
|
|
136
136
|
## Workflow — adopt a pre-existing database
|
|
137
137
|
|
|
138
|
-
The concept: a database that predates Prisma 8 enters the system by describing it, not migrating it — `contract infer` derives the contract from the live schema, and after review + `contract emit`, `db sign` records the
|
|
138
|
+
The concept: a database that predates Prisma 8 enters the system by describing it, not migrating it — `contract infer` derives the contract from the live schema, and after review + `contract emit`, `db sign` records the contract signature. Full recipe: `references/quickstart.md` § *Brownfield-DB*.
|
|
139
139
|
|
|
140
140
|
```bash
|
|
141
141
|
pnpm prisma contract infer --db "$DATABASE_URL" --output src/prisma/contract.prisma
|
|
@@ -148,9 +148,9 @@ By default `db sign` sets the `db` ref to the signed contract's hash and stores
|
|
|
148
148
|
|
|
149
149
|
## Workflow — retrofit a database that has no on-disk migrations
|
|
150
150
|
|
|
151
|
-
The concept: the database exists and its
|
|
151
|
+
The concept: the database exists and its contract signature is accurate (hash **M**) — it was built by `db update` or signed with `db sign` in another checkout, or built by a deploy pipeline — but the migration graph doesn't reach M. (A database adopted with `db sign` in *this* checkout already has its ref set; retrofit is for the case where the ref was never set here.) The goal is to **make the graph reach the signature's hash**: once a baseline `null → M` exists, applying against the marked database is clean by construction — the runner starts at the signature, so the baseline never executes; only real deltas past M run.
|
|
152
152
|
|
|
153
|
-
- **It's your dev database.** Run `db update` (default URL; no-op on the DB when the contract already matches) — it advances the `db` ref and stores the contract snapshot
|
|
153
|
+
- **It's your dev database.** Run `db update` (default URL; no-op on the DB when the contract already matches) — outside CI it advances the `db` ref and stores the contract snapshot; with `--db` or in CI it does neither unless you pass `--advance-ref db`. The next `migration plan` auto-emits the baseline plus your delta. This is just the dev loop's dev → ship transition.
|
|
154
154
|
- **It's a deployed database you must not touch.** Build the baseline offline, at the deployed contract state:
|
|
155
155
|
1. Bring the contract source back to the deployed state (check out the deployed revision of the contract file, or stash your edits), then `contract emit`.
|
|
156
156
|
2. `migration plan --name baseline` — greenfield, intended: one bundle `null → M`. Confirm its `to` matches the database (`db verify --db "$URL"` is clean at this revision).
|
|
@@ -162,8 +162,8 @@ The concept: the database exists and its marker is accurate (hash **M**) — it
|
|
|
162
162
|
## Common Pitfalls
|
|
163
163
|
|
|
164
164
|
1. **Assuming `migration plan` or `migration new` chains from the newest migration on disk.** Neither does. The origin is `--from`, else the `db` ref. With neither, only an empty graph plans from scratch (with the muted `No db ref set` notice); once migrations exist, both commands refuse with `MIGRATION.PLAN_ORIGIN_UNKNOWN`.
|
|
165
|
-
2. **Expecting `migration plan`, or `db migrate` with `--db` or in CI, to keep the `db` ref current.** None of them touches refs. `db init`, `db update` and `db migrate` advance `db` only when the connection comes from `prisma.config.ts`
|
|
166
|
-
3. **Expecting a deploy to update refs.** Deploys write the database's
|
|
165
|
+
2. **Expecting `migration plan`, or `db migrate` with `--db` or in CI, to keep the `db` ref current.** None of them touches refs. `db init`, `db update` and `db migrate` advance `db` only when the connection comes from `prisma.config.ts` and the CLI does not detect CI; `db sign` advances it even with `--db`. Elsewhere, pass `--advance-ref db`.
|
|
166
|
+
3. **Expecting a deploy to update refs.** Deploys write the database's contract signature; the files under `migrations/app/refs/` only change when you change them.
|
|
167
167
|
4. **Reading `from: (baseline)` as informational.** Over a non-empty migrations directory it is the trap announcing itself. Stop and pick an exit before applying or committing.
|
|
168
168
|
5. **`migration ref set` with a hash no on-disk migration produces.** A ref target must be the `to` hash of an on-disk migration bundle. A hash outside the graph is refused (`MIGRATION.HASH_NOT_IN_GRAPH`); a from-only graph node is refused with `MIGRATION.REF_SET_BUNDLE_NOT_FOUND`, whose fix text points at fixtures and is unhelpful here. Either way: plan the edge whose `to` is the hash first (baseline or delta), then set the ref.
|
|
169
169
|
6. **Treating `db` as reserved.** It's a naming default. Setting it yourself is fine and sometimes exactly right (deploy-first chaining, retrofit); just expect dev commands on the config's database (`db init`, `db update`, and `db migrate` outside CI) to overwrite it.
|
|
@@ -179,6 +179,6 @@ The concept: the database exists and its marker is accurate (hash **M**) — it
|
|
|
179
179
|
- [ ] Read the plan output's `from:` line and confirmed it names that origin — not `(baseline)` over an existing graph.
|
|
180
180
|
- [ ] In a deploy-first project: baseline authored and committed before the first deploy; every later plan chained via the `db` ref or `--from`.
|
|
181
181
|
- [ ] After each plan in a loop where nothing advances refs: advanced the `db` ref (`migration ref set db <to-hash>`) or resolved to pass `--from` next time.
|
|
182
|
-
- [ ] For a marked database with no on-disk migrations: made the graph reach the
|
|
183
|
-
- [ ] Expected plain `db migrate` to advance `db` only when
|
|
182
|
+
- [ ] For a marked database with no on-disk migrations: made the graph reach the contract signature's hash (auto-baseline via `db update` or `db sign`, or an offline baseline plan) before planning deltas.
|
|
183
|
+
- [ ] Expected plain `db init`, `db update` and `db migrate` to advance `db` only when the connection comes from `prisma.config.ts`, the CLI does not detect CI and neither `--advance-ref` nor `--no-advance-ref` is passed; expected `--advance-ref <name>` to advance `<name>` with `--db` and in CI too; did NOT expect `migration plan`, or any of them with `--db` or in CI and without `--advance-ref`, to advance any ref.
|
|
184
184
|
- [ ] Did NOT apply or commit a `from: (baseline)` plan without confirming the empty origin was the intent.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
This skill is about *reviewing* migrations, not authoring them. It covers the questions that come up at deploy time and when multiple developers are landing migrations concurrently.
|
|
7
7
|
|
|
8
|
-
The skill teaches *the system's mental model* — what a ref is, what a
|
|
8
|
+
The skill teaches *the system's mental model* — what a ref is, what a contract signature is, what the migration graph is — and shows how to ask the system for its state. It does **not** prescribe rigid step-by-step procedures: most "review" questions are answered by understanding the model and querying the right thing. Rigid procedures are reserved for the rare case where there's literally one safe path.
|
|
9
9
|
|
|
10
10
|
## When to Use
|
|
11
11
|
|
|
@@ -27,9 +27,9 @@ The skill teaches *the system's mental model* — what a ref is, what a marker i
|
|
|
27
27
|
|
|
28
28
|
### Origin
|
|
29
29
|
|
|
30
|
-
The **origin** is the database's *current contract hash*. The database carries a row in Prisma 8's
|
|
30
|
+
The **origin** is the database's *current contract hash*. The database carries a row in Prisma 8's contract signature table that records *"this database is at hash X"*. When the CLI runs online (a `--db <url>` is provided, or `db.connection` is set in `prisma.config.ts`), Prisma 8 reads the signature and that hash is the origin. Offline (no DB connection), the origin is unknown — many commands degrade to listing the on-disk migrations and skip the per-edge applied/pending status.
|
|
31
31
|
|
|
32
|
-
A live DB is therefore the authoritative source of origin. The "recorded
|
|
32
|
+
A live DB is therefore the authoritative source of origin. The "recorded signature" in any other artifact (refs, local cache, your assumptions) is a working copy that can drift; the live DB never does.
|
|
33
33
|
|
|
34
34
|
### Destination
|
|
35
35
|
|
|
@@ -42,9 +42,9 @@ The **destination** is the contract hash you want the database to be at. Two way
|
|
|
42
42
|
|
|
43
43
|
### The migration graph
|
|
44
44
|
|
|
45
|
-
The on-disk migrations form a directed graph: **nodes are contract hashes; edges are migrations.** Each migration declares a `from` hash and a `to` hash. A migration applies only when the database's current
|
|
45
|
+
The on-disk migrations form a directed graph: **nodes are contract hashes; edges are migrations.** Each migration declares a `from` hash and a `to` hash. A migration applies only when the database's current contract signature matches its `from` hash; running it advances the signature to its `to` hash.
|
|
46
46
|
|
|
47
|
-
The graph is a static, committed artifact. Several branch tips may coexist, rollback edges may form cycles, and no node is privileged — "where is my database" is answered by the
|
|
47
|
+
The graph is a static, committed artifact. Several branch tips may coexist, rollback edges may form cycles, and no node is privileged — "where is my database" is answered by the signature and refs, never by the graph itself. `references/migration-model.md` carries the full model, including how `migration plan` chooses its origin.
|
|
48
48
|
|
|
49
49
|
`migration status` queries the graph for the path from origin to destination and reports per-edge status:
|
|
50
50
|
|
|
@@ -54,12 +54,12 @@ The graph is a static, committed artifact. Several branch tips may coexist, roll
|
|
|
54
54
|
|
|
55
55
|
### Diagnostic codes
|
|
56
56
|
|
|
57
|
-
`migration status` answers with a document (`--json`): `spaces[]`, each with `currentContract` (the
|
|
57
|
+
`migration status` answers with a document (`--json`): `spaces[]`, each with `currentContract` (the contract hash in the contract signature, or `null` when the database has no signature for that space), `targetContract`, and `migrations[]` carrying the `applied` / `pending` / `null` status above; a `summary` line; and `diagnostics[]`. The ordinary states — up to date, N pending, no signature yet, signature on another branch, no path to the target — are read from `spaces[]` and the summary, not from diagnostic codes. The three diagnostics it can attach are all `warn`, and each carries a `message` and `hints` — the same hints the CLI prints under the summary line:
|
|
58
58
|
|
|
59
59
|
| Code | Meaning in the navigation model | Next move |
|
|
60
60
|
|---|---|---|
|
|
61
|
-
| `MIGRATION.
|
|
62
|
-
| `MIGRATION.MISSING_INVARIANTS` |
|
|
61
|
+
| `MIGRATION.SIGNATURE_NOT_IN_GRAPH` | Online; signed contract hash is not a node in the graph. The database was changed outside the migration system. | Follow the finding's advice, which depends on the database's change policy. When the policy includes `reconcile`, decide which side is truth: `db sign` (accept DB as truth), `db update` (push contract to DB), `contract infer` (re-derive contract from DB), or `db verify` (inspect first). When it is `migrate` alone, `db sign` and `db update` are refused: author migrations that bring the database back onto the graph. When the policies cannot be read, have them corrected first: on Postgres the `policies` column of `prisma.config`, elsewhere `meta.policies` in the application space's signature. **Not** the same as `MIGRATION.SIGNATURE_NOT_IN_GRAPH`, which `db migrate` (before any DDL) and `db migrate --show` raise as an error when the signed contract hash is not a graph node. |
|
|
62
|
+
| `MIGRATION.MISSING_INVARIANTS` | Signature reached the destination structurally but lacks invariants the target ref declares. | `db migrate --to <name> --db $URL` to take a path that covers them. |
|
|
63
63
|
| `CONTRACT.UNREADABLE` | `contract.json` couldn't be read. | `contract emit` to regenerate it. |
|
|
64
64
|
|
|
65
65
|
Conditions that make the run *refuse* instead (exit `2`) arrive as ordinary errors: `MIGRATION.NO_INVARIANT_PATH` (no path covers the missing invariants), `MIGRATION.UNKNOWN_INVARIANT` (the ref names an invariant no edge provides), and the ref-resolution errors for a bad `--to` / `--from`.
|
|
@@ -81,14 +81,14 @@ These codes surface on `migration plan`, `migration ref set`, and `db migrate`
|
|
|
81
81
|
|---|---|---|---|
|
|
82
82
|
| `MIGRATION.HASH_NOT_IN_GRAPH` | `migration plan` (non-empty graph) or `migration ref set` | Resolved hash is not a node in the on-disk migration graph — typical when the default `db` ref points past the graph tip after `db update` cycles. | `migration plan --from <reachable-ref>` (e.g. `--from production`); or realign the ref with `migration ref set db <graph-node-hash>`. |
|
|
83
83
|
| `MIGRATION.SNAPSHOT_MISSING` | `migration plan` | A named ref has no pointer file (`<name>.json`), and the hash being resolved isn't a node in the migration graph either. | `migration ref set <name> <hash>` to create the ref, `db update --advance-ref <name>` to advance it, or pass a hash that is a graph node. |
|
|
84
|
-
| `MIGRATION.
|
|
85
|
-
| `MIGRATION.PATH_UNREACHABLE` | `db migrate` (path resolution) | No migration path from the current
|
|
84
|
+
| `MIGRATION.SIGNATURE_NOT_IN_GRAPH` | `db migrate` (pre-DDL, before the runner), `db migrate --show` | Live contract hash the database is signed with is not a graph node. Usually a migration the database applied was planned again or deleted. | Follow the error's next actions, and `references/migrations.md` § *A database whose contract signature is not in the migration graph*. Never reset the database. |
|
|
85
|
+
| `MIGRATION.PATH_UNREACHABLE` | `db migrate` (path resolution) | No migration path from the current signature to the resolved target in the on-disk graph. | Read the improved `fix` payload — it names `fromHash` / `targetHash` and prints the `migration plan` and `db migrate` commands to run, with `--to <target>` unless the target is the emitted contract. On an empty database the plan starts from where the migration history ends. When the space named is an extension's, it prints no plan command: install a version of the extension whose migrations start from the contract the database is at; run `migration list` to inspect the graph. |
|
|
86
86
|
|
|
87
87
|
## Workflow — *"What's about to run on deploy?"*
|
|
88
88
|
|
|
89
89
|
The user asks: *"I'm about to merge this PR. What migrations are going to run when I deploy to staging?"*
|
|
90
90
|
|
|
91
|
-
This is the navigation question: **origin** = staging's live
|
|
91
|
+
This is the navigation question: **origin** = staging's live contract signature; **destination** = the ref `staging` (or the contract head if you haven't set one). Ask the system:
|
|
92
92
|
|
|
93
93
|
```bash
|
|
94
94
|
pnpm prisma migration status --to staging --db "$STAGING_DATABASE_URL"
|
|
@@ -96,12 +96,12 @@ pnpm prisma migration status --to staging --db "$STAGING_DATABASE_URL"
|
|
|
96
96
|
|
|
97
97
|
The command:
|
|
98
98
|
|
|
99
|
-
1. Reads the staging DB's
|
|
99
|
+
1. Reads the staging DB's signature (the origin).
|
|
100
100
|
2. Resolves `staging` to a contract hash (the destination).
|
|
101
101
|
3. Renders the path between them as an ordered list of migrations, with per-edge `applied` / `pending` / `null` status, and an explicit summary line of the form *"N migration(s) behind ref 'staging'"*.
|
|
102
102
|
4. Prints a header that names the config, migrations directory, the active ref, and the database connection (masked) — so the framing is visible in the output.
|
|
103
103
|
|
|
104
|
-
If you omit `--db`, the command runs offline: it lists the migrations on disk but cannot tell you what's applied, because it has no origin. That's fine for *"what's on this branch?"*; it's not fine for *"what's about to run on staging?"* — for that you need staging's live
|
|
104
|
+
If you omit `--db`, the command runs offline: it lists the migrations on disk but cannot tell you what's applied, because it has no origin. That's fine for *"what's on this branch?"*; it's not fine for *"what's about to run on staging?"* — for that you need staging's live signature.
|
|
105
105
|
|
|
106
106
|
If you omit `--to`, the destination defaults to the contract head — which answers *"is this branch's contract reachable from the database, and how?"*, not *"what runs on deploy"*. Pass the ref explicitly when the question is about a specific environment.
|
|
107
107
|
|
|
@@ -109,7 +109,7 @@ If you omit `--to`, the destination defaults to the contract head — which answ
|
|
|
109
109
|
|
|
110
110
|
## Workflow — *"What state is each environment at?"*
|
|
111
111
|
|
|
112
|
-
Just `migration status --db $URL` for each environment's DB. The
|
|
112
|
+
Just `migration status --db $URL` for each environment's DB. The contract signature (origin) comes back from the DB itself; the summary line tells you whether the environment is at the contract head, at a named ref, ahead of head, or on a divergent branch.
|
|
113
113
|
|
|
114
114
|
## Concept — concurrent migrations on the same branch point
|
|
115
115
|
|
|
@@ -140,7 +140,7 @@ pnpm prisma migration ref delete production
|
|
|
140
140
|
|
|
141
141
|
`migration ref set` writes a file at `migrations/app/refs/<name>.json` carrying the hash and any required invariants. Refs are commit-friendly artifacts — keep them in git; the team agrees on what `production` points at the same way they agree on what `main` is. The hash being set must be the `to` of an on-disk migration, or the command refuses — see `references/migration-model.md` for the refusal codes.
|
|
142
142
|
|
|
143
|
-
Two ref roles, one mechanism: environment refs like `production` are the contract CD will migrate that environment to (a forward promise), while the `db` ref is a checkpoint of where the project's dev database was last brought to — written by `db init`
|
|
143
|
+
Two ref roles, one mechanism: environment refs like `production` are the contract CD will migrate that environment to (a forward promise), while the `db` ref is a checkpoint of where the project's dev database was last brought to — written by `db init`, `db update` and `db migrate` when the connection comes from the config outside CI, and by `db sign` by default (`--advance-ref <name>` targets another ref, `--no-advance-ref` skips the write), consumed by `migration plan` as its default origin. `references/migration-model.md` covers the `db` ref, advancement rules, and plan-origin resolution.
|
|
144
144
|
|
|
145
145
|
## Workflow — apply a migration against an environment
|
|
146
146
|
|
|
@@ -148,7 +148,7 @@ Two ref roles, one mechanism: environment refs like `production` are the contrac
|
|
|
148
148
|
pnpm prisma db migrate --to production --db "$PRODUCTION_DATABASE_URL"
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
-
The destination is the ref's hash; the origin is the production DB's live
|
|
151
|
+
The destination is the ref's hash; the origin is the production DB's live contract signature. The command computes the path between them and applies each pending migration in order, advancing the signature.
|
|
152
152
|
|
|
153
153
|
`--db` is the environment selection knob. `--to` is the destination-hash knob. They're independent.
|
|
154
154
|
|
|
@@ -158,8 +158,8 @@ CI reports: *"the recorded ref `production` is at hash X; the live DB is at hash
|
|
|
158
158
|
|
|
159
159
|
The mismatch is a fact about *two pieces of state that disagree*. The investigation is the same regardless of which piece is wrong:
|
|
160
160
|
|
|
161
|
-
- **DB ahead of the ref.** Someone applied a migration outside CI without updating the ref in git. Re-record the ref with `prisma migration ref set <ref-name> <db-
|
|
162
|
-
- **DB behind the ref.** A previous deploy was rolled back, or the DB was restored from an older backup. Either re-apply forward with `prisma db migrate --to <ref-name> --db $URL`, or re-route the ref backward to match what's actually deployed with `prisma migration ref set <ref-name> <db-
|
|
161
|
+
- **DB ahead of the ref.** Someone applied a migration outside CI without updating the ref in git. Re-record the ref with `prisma migration ref set <ref-name> <db-signature-hash>` (commit + push); then audit how the out-of-band apply happened.
|
|
162
|
+
- **DB behind the ref.** A previous deploy was rolled back, or the DB was restored from an older backup. Either re-apply forward with `prisma db migrate --to <ref-name> --db $URL`, or re-route the ref backward to match what's actually deployed with `prisma migration ref set <ref-name> <db-signature-hash>`. The choice is the user's — name both options.
|
|
163
163
|
- **DB on a different branch.** An out-of-band schema change (manual SQL, ad-hoc migration) wrote something the migration graph doesn't model. Run `prisma db verify` to inspect the drift, then either `prisma contract infer` to re-derive the contract from the database, or edit the contract and run `prisma migration plan` so the database is the eventual destination.
|
|
164
164
|
|
|
165
165
|
`migration ref set` to silently align the ref with whatever the DB happens to be at is almost never the right move. It papers over drift that you'll pay for later.
|
|
@@ -173,9 +173,9 @@ The whole job is one command:
|
|
|
173
173
|
run: pnpm prisma db migrate --to staging --db "$STAGING_DATABASE_URL"
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
`db migrate` is safe to run unattended, by design. Before any operation runs it reads the live
|
|
176
|
+
`db migrate` is safe to run unattended, by design. Before any operation runs it reads the live contract signature and refuses with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` if that hash is not a node in the on-disk graph, which is what a database changed outside the migration system looks like. Each operation then evaluates its own `precheck[]` and stops if the database is not in the state the operation expects. A successful run writes the destination hash as the new signature. Nothing runs before `db migrate` in the job.
|
|
177
177
|
|
|
178
|
-
`migration status --to staging --db $URL` is what a human or agent runs to answer *"what will run on deploy?"* before merging: it reports the path from the live
|
|
178
|
+
`migration status --to staging --db $URL` is what a human or agent runs to answer *"what will run on deploy?"* before merging: it reports the path from the live signature to the ref without changing anything. `db migrate --show --db $URL` gives the same path as an ordered preview; `migration log --db $URL` gives the applied history after a deploy.
|
|
179
179
|
|
|
180
180
|
`db migrate` is interactive-free and asks nothing — the questions about data loss are asked by `migration plan` when it writes the package, and by `db update` (see the `references/migrations.md` skill). Whatever the planner put in the migration graph is what `db migrate` runs; review happens at `migration plan` and at `migration status` time, before the apply step.
|
|
181
181
|
|
|
@@ -198,7 +198,7 @@ This skill is intentionally body-only; the underlying CLI reference (`prisma mig
|
|
|
198
198
|
|
|
199
199
|
## Checklist
|
|
200
200
|
|
|
201
|
-
- [ ] Named both the **origin** (live
|
|
201
|
+
- [ ] Named both the **origin** (live contract signature) and the **destination** (ref or contract head) for the question the user asked.
|
|
202
202
|
- [ ] Passed `--db $URL` whenever the question involves a specific environment.
|
|
203
203
|
- [ ] Passed `--to <name>` whenever the question is about deploying *to* a named environment, not just *from* the current branch's head.
|
|
204
204
|
- [ ] Read the `migration status` header (it names config, ref, database) and the summary line (it names the origin/destination distance) before reading the per-edge list.
|