@prisma/orm-mongo 8.0.0-rc.9-dev.13 → 8.0.1-dev.1
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 +48 -8
- package/dist/components-CWskH7lF-Dkc9ysZz.mjs +18 -0
- package/dist/components-CWskH7lF-Dkc9ysZz.mjs.map +1 -0
- package/dist/config.d.mts +14 -5
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +47 -25
- package/dist/config.mjs.map +1 -1
- package/dist/contract-builder.d.mts +33 -91
- package/dist/contract-builder.d.mts.map +1 -1
- package/dist/contract-builder.mjs +23 -7
- package/dist/contract-builder.mjs.map +1 -1
- package/dist/contract-types.d.mts +3 -0
- package/dist/contract-types.mjs +1 -0
- package/dist/contract__format-version.d.mts +1 -0
- package/dist/contract__format-version.mjs +2 -0
- package/dist/contract__internal__format-version.d.mts +1 -0
- package/dist/contract__internal__format-version.mjs +2 -0
- package/dist/contract__validate-once.d.mts +1 -0
- package/dist/contract__validate-once.mjs +2 -0
- package/dist/contract__validate-storage.d.mts +1 -0
- package/dist/contract__validate-storage.mjs +2 -0
- package/dist/control.d.mts +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +3 -9
- package/dist/control.mjs.map +1 -1
- package/dist/driver__runtime.d.mts +3 -0
- package/dist/driver__runtime.mjs +3 -0
- package/dist/family-contract__data-type.d.mts +1 -0
- package/dist/family-contract__data-type.mjs +2 -0
- package/dist/init-quick-reference.md +116 -0
- package/dist/init-readme.md +35 -0
- package/dist/init.d.mts +7 -0
- package/dist/init.d.mts.map +1 -0
- package/dist/init.mjs +245 -0
- package/dist/init.mjs.map +1 -0
- package/dist/migration.d.mts +1 -0
- package/dist/migration.mjs +2 -0
- package/dist/module-base-B70DHaBE-k_c3Klu4.mjs +6 -0
- package/dist/module-base-B70DHaBE-k_c3Klu4.mjs.map +1 -0
- package/dist/mongo-static-CfvV1-qX-DdckMRxc.mjs +74 -0
- package/dist/mongo-static-CfvV1-qX-DdckMRxc.mjs.map +1 -0
- package/dist/{mongo-static-BdSGXYgQ-DSA-2DiK.d.mts → mongo-static-DabeBtmV-DILuhcbE.d.mts} +18 -5
- package/dist/mongo-static-DabeBtmV-DILuhcbE.d.mts.map +1 -0
- package/dist/runtime.d.mts +49 -44
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +104 -42
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.d.mts +24 -2
- package/dist/static.d.mts.map +1 -0
- package/dist/static.mjs +2 -2
- package/dist/target__codec-ids.d.mts +1 -0
- package/dist/target__codec-ids.mjs +2 -0
- package/dist/target__codecs.d.mts +1 -0
- package/dist/target__codecs.mjs +2 -0
- package/dist/target__data-types.d.mts +1 -0
- package/dist/target__data-types.mjs +2 -0
- package/dist/target__server-version.d.mts +1 -0
- package/dist/target__server-version.mjs +2 -0
- package/dist/utils__guards.d.mts +1 -0
- package/dist/utils__guards.mjs +2 -0
- package/dist/utils__text.d.mts +1 -0
- package/dist/utils__text.mjs +2 -0
- package/dist/utils__upgrade-guides.d.mts +1 -0
- package/dist/utils__upgrade-guides.mjs +2 -0
- package/package.json +37 -13
- package/skills/prisma-8/SKILL.md +23 -18
- package/skills/prisma-8/references/build-a-target-package.md +117 -0
- package/skills/prisma-8/references/build.md +12 -16
- package/skills/prisma-8/references/contract.md +181 -75
- package/skills/prisma-8/references/debug.md +35 -24
- package/skills/prisma-8/references/feedback.md +8 -8
- package/skills/prisma-8/references/migration-model.md +23 -14
- package/skills/prisma-8/references/migration-review.md +23 -52
- package/skills/prisma-8/references/migrations.md +294 -80
- package/skills/prisma-8/references/queries-mongo.md +53 -17
- package/skills/prisma-8/references/queries-postgres.md +345 -34
- package/skills/prisma-8/references/queries.md +44 -25
- package/skills/prisma-8/references/quickstart.md +25 -22
- package/skills/prisma-8/references/runtime.md +172 -72
- package/skills/prisma-8/references/supabase.md +22 -19
- package/skills/prisma-8/references/upgrade-app.md +57 -22
- package/skills/prisma-8/references/upgrade-extension.md +72 -23
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/instructions.md +1 -1
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +639 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/multifile-psl/add-use-prisma-8-directive.mjs +60 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/psl-verbatim-table-names/add-model-map.mjs +256 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +332 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts +193 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +489 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +1368 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/scripts/data-type-in-contract/data-type-in-contract.ts +1492 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +108 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +755 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +973 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/scripts/sql-expression-literals-psl/rewrite-sql-strings.mjs +271 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +1862 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +597 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +2462 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +513 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +1206 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +803 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +586 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/scripts/value-objects-in-storage/value-objects-in-storage.ts +1184 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/instructions.md +480 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/scripts/mongo-index-names/mongo-index-names.ts +317 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +336 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.24-to-8.0.0-rc.25/instructions.md +1561 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.9-to-8.0.0-rc.10/instructions.md +13 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +1 -1
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +857 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/psl-verbatim-table-names/add-model-map.mjs +256 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +504 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts +193 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +143 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +2168 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/scripts/data-type-in-contract/data-type-in-contract.ts +1492 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +223 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +583 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +1008 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +2186 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +597 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +2462 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +381 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +1206 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +570 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +464 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/instructions.md +410 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +303 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.24-to-8.0.0-rc.25/instructions.md +1593 -0
- package/dist/adapter__codec-ids.d.mts +0 -1
- package/dist/adapter__codec-ids.mjs +0 -2
- package/dist/adapter__codec-types.d.mts +0 -1
- package/dist/adapter__codec-types.mjs +0 -2
- package/dist/adapter__codecs.d.mts +0 -1
- package/dist/adapter__codecs.mjs +0 -2
- package/dist/mongo-static-BdSGXYgQ-DSA-2DiK.d.mts.map +0 -1
- package/dist/mongo-static-_wy-fC4P-mXlhePy0.mjs +0 -38
- package/dist/mongo-static-_wy-fC4P-mXlhePy0.mjs.map +0 -1
|
@@ -51,11 +51,11 @@ Every code is a dotted `NAMESPACE.SUBCODE`; the namespace is the prefix (`CONFIG
|
|
|
51
51
|
|
|
52
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 either shape programmatically with `isStructuredError` and match on `error.code` — never `instanceof`.
|
|
53
53
|
|
|
54
|
-
**3. SQL driver errors** — surface as `SqlQueryError` / `SqlConnectionError` (see `packages/2-sql/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.
|
|
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
|
|
|
56
|
-
###
|
|
56
|
+
### Migration apply failures
|
|
57
57
|
|
|
58
|
-
`db migrate`, `db init`, and `db update`
|
|
58
|
+
`db migrate`, `db init`, and `db update` report a failure of the migration runner with the runner's own code, such as `MIGRATION.SCHEMA_VERIFY_FAILED`, `MIGRATION.PRECHECK_FAILED`, `MIGRATION.POSTCHECK_FAILED` or `MIGRATION.EXECUTION_FAILED`, and its `meta` unchanged. The facts are typed `meta` keys: `schemaIssues` (the schema check's issues), `failedCheck` (`operationId`, `phase`, `description`), `failedTypeChange`, `rowsWithoutValue`, and `failingSpace`, the contract space whose plan failed. Read `why` for what failed and `nextActions` for the way out.
|
|
59
59
|
|
|
60
60
|
### How to ask for the full envelope
|
|
61
61
|
|
|
@@ -68,7 +68,7 @@ These symptoms are not structured envelopes — route on the message text and ch
|
|
|
68
68
|
| Symptom | Next move |
|
|
69
69
|
|---|---|
|
|
70
70
|
| `TypeError: db.end is not a function` | The runtime client does not expose `db.end()` — that's the `node-postgres` pool API (`pool.end()`). The right call is `await db.close()`. See `references/runtime.md` § *Running as a script (teardown)*. |
|
|
71
|
-
| Script hangs after queries print / process won't exit | On Postgres the
|
|
71
|
+
| Script hangs after queries print / process won't exit | On Postgres the `pg.Pool` that the database package owns keeps the event loop alive. Call `await db.close()` before the script returns, or `await using db = postgres({ contract, ... })` at the top of a script module (do NOT put `await using` inside a request handler — block-scoped, would close per-request). See `references/runtime.md` § *Running as a script (teardown)*. |
|
|
72
72
|
| `Error('Postgres client is closed')` / `Error('SQLite client is closed')` / `Error('Mongo client is closed')` | The client was closed via `db.close()` (terminal state). Remove the early `close()`, reorder so `close()` runs last after all queries, or construct a new `db` if reconnection is intended. See `references/runtime.md` § *Running as a script (teardown)*. |
|
|
73
73
|
|
|
74
74
|
## Routing — symptom and code → next move
|
|
@@ -78,39 +78,50 @@ The single source of truth: read the envelope, find the row by `code`, follow th
|
|
|
78
78
|
| Code | Where it surfaces | Next move |
|
|
79
79
|
|---|---|---|
|
|
80
80
|
| `CONFIG.FILE_NOT_FOUND` | Most `prisma` commands | Run `prisma orm init`, or pass `--config <path>`. |
|
|
81
|
-
| `CONFIG.CONTRACT_MISSING` | `contract emit`, `db *` | Add `contract: './src/prisma/contract.prisma'` to the `ormConfig({...})` section of `prisma.config.ts`. See `references/contract.md`. |
|
|
81
|
+
| `CONFIG.CONTRACT_MISSING` | `contract emit`, `db *` | Add `contract: './src/prisma/contract.prisma'` to the `ormConfig({...})` section of `prisma.config.ts`; on PostgreSQL, `contract: { path: './src/prisma/contract.prisma', requiredCapabilities: [...postgres18, ...postgresDriver] }`. See `references/contract.md`. |
|
|
82
82
|
| `CONFIG.VERSION_MARKER_MISSING` | Any command loading config | The default export was not built by the current `definePrismaConfig` / `ormConfig` pair (plain object, spread copy, or a Prisma 7 config). Rewrite to the envelope form in `references/contract.md`. |
|
|
83
83
|
| `CONFIG.VALIDATION_FAILED` | Any command reading the malformed section | `meta.section` / `meta.field` name the config section. Fix `prisma.config.ts`. |
|
|
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` | Inspect `meta.conflicts`. Recovery is per-conflict — chain to `references/migrations.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 marker. |
|
|
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
|
-
| `MIGRATION.UNFILLED_PLACEHOLDER` | `node
|
|
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
|
-
| `MIGRATION.DATA_TRANSFORM_CONTRACT_MISMATCH` | Building a data-transform query plan | Pass the
|
|
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
|
|
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
|
+
| `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
94
|
| `CONTRACT.MARKER_MISSING` | `db verify` (`error` diagnostic, exit 4), runtime startup (warning) | DB has no marker 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
95
|
| `CONTRACT.MARKER_MISMATCH` | `db verify` (exit 4), runtime startup (warning) | Marker 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
|
-
| `CONTRACT.SCHEMA_VERIFICATION_FAILED` | `db verify`, `db sign` (both exit 4 with the finding) | Live schema does not satisfy the contract; `meta.
|
|
98
|
-
| `MIGRATION.
|
|
99
|
-
| `MIGRATION.
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
| `MIGRATION.
|
|
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 marker 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
|
+
| `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
|
+
| `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
|
+
| `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`. |
|
|
102
|
+
| `MIGRATION.STATEMENT_DID_NOT_RESOLVE_LOSS` | A rename typed at the data-loss prompt | The rename still loses the subject's data. Answer with `delete`, or give a rename whose old name is the subject. |
|
|
103
|
+
| `MIGRATION.NO_INVARIANT_PATH` / `MIGRATION.UNKNOWN_INVARIANT` | `db migrate` | Concurrent-migration and invariant flows — `references/migration-review.md`. |
|
|
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
|
+
| `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.MARKER_MISMATCH` | `db migrate`, `db migrate --show`, a Composer deploy | The database's marker 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 marker is not in the migration graph*. Never reset or drop the database. |
|
|
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
|
+
| `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
|
+
| `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 marker 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 marker ends, so the new migration extends the history instead of forking it; to any other target it is the marker. 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 marker 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
|
+
| `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*. |
|
|
103
112
|
| `MIGRATION.MISSING_INVARIANTS` | `migration status` `warn` diagnostic (exit 0) | The live marker 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`. |
|
|
104
|
-
| `MIGRATION.MARKER_NOT_IN_HISTORY` / `CONTRACT.UNREADABLE` | `migration status` `warn` diagnostics (exit 0
|
|
113
|
+
| `MIGRATION.MARKER_NOT_IN_HISTORY` / `CONTRACT.UNREADABLE` | `migration status` `warn` diagnostics (exit 0) | Read `severity` *and* `code`. Up-to-date / pending / no-marker states are not codes — read `spaces[].currentContract` and `migrations[].status` in the `--json` document. `references/migration-review.md` covers the marker-out-of-history flow. |
|
|
105
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`. |
|
|
106
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`. |
|
|
107
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. |
|
|
108
|
-
| `RUNTIME.TEMPORAL_UNAVAILABLE` | Runtime, first read or write touching a Temporal-backed column (`
|
|
109
|
-
| `ORM.
|
|
110
|
-
| `
|
|
117
|
+
| `RUNTIME.TEMPORAL_UNAVAILABLE` | Runtime, first read or write touching a Temporal-backed column (`DateTemporal`, `TimestampTemporal(p)`, `TimestampInstant(p)`, `TimestamptzTemporal(p)`, `TimeTemporal(p)`, and `DateTime`, `Date` or `Time` with `as: temporal`) | No global `Temporal`. Node.js 26.8.2 and later ship `globalThis.Temporal`; 26.8.1 and earlier — including every 22 and 24 — do not. Either `import 'temporal-polyfill/full/global'` before the first query, or write the field as a convenience type at its default (`DateTime`, `Date`, `Time`), which reads a JavaScript `Date` or a string. |
|
|
118
|
+
| `ORM.OPERATION_UNSUPPORTED` | ORM operation used where it is not supported; `meta.reason` says why | With `reason: 'junction-required-columns'` (nested `create` / `connect` on an N:M relation whose junction has required payload columns): write the junction table directly or use the SQL builder (`meta.junction`). Other reasons: `docs/reference/error-reference.md#ORM.OPERATION_UNSUPPORTED`. |
|
|
119
|
+
| `ORM.OPERATION_UNSUPPORTED` with `reason: 'required-foreign-key'` | ORM nested `disconnect()` on a relation whose foreign key is required, or `delete()` on a relation the record holds a required key for (`meta.model`, `meta.fields`) | For `disconnect`: if `meta.model` is the model being updated, the record holds the key (a many-to-one relation, such as `Post.author`): `connect` it to another row or delete the record. Otherwise the related rows hold it (one-to-many, or one-to-one from the side without the key): connect them to another record or delete them. For `delete` (the record holds the key): `connect` the record to another row, or delete the record, before deleting the related row through its own collection. Or make the key optional. |
|
|
120
|
+
| `ORM.ARGUMENT_INVALID` with `problem: 'missing-where'` | ORM nested `update()` / `delete()` on a to-many relation without a `where` that filters | Add `where(...)` naming the related row to change. |
|
|
121
|
+
| `RUNTIME.ABORTED` (`details.phase` = `encode\|decode\|stream\|beforeEncode\|onRow`) | Runtime, when an `AbortSignal` fires mid-execute | Cancellation, not a bug; surface to the caller. |
|
|
111
122
|
| `SqlQueryError` (no dotted code) | Raw-SQL paths surfacing a driver error | Inspect `sqlState` + `constraint` + `table` + `column`. Postgres `23505` = unique violation, `23503` = foreign-key violation, etc. Fix the data or the schema. |
|
|
112
|
-
| TypeScript error mentioning a capability (e.g. `returning()` not on the type, `include` of a many-relation off a many-load) | Authoring-time, before any envelope fires |
|
|
113
|
-
| TypeScript error mentioning a missing field/method on `db.orm.<ns>.<Model>` or a stale `Contract` shape | Authoring-time | Re-emit (`pnpm prisma contract emit`); confirm `db.ts`
|
|
123
|
+
| TypeScript error mentioning a capability (e.g. `returning()` not on the type, `include` of a many-relation off a many-load) | Authoring-time, before any envelope fires | A method is offered only when the contract requires its capability. On PostgreSQL the contract's `requiredCapabilities` list (in `defineContract`, or beside the path in the config's contract entry) is that list; the error message names the key to add. Route to `references/contract.md` for the list and to `references/queries.md` for which method gates on which capability. Re-emit (`pnpm prisma contract emit`) after adding it. |
|
|
124
|
+
| TypeScript error mentioning a missing field/method on `db.orm.<ns>.<Model>` or a stale `Contract` shape | Authoring-time | Re-emit (`pnpm prisma contract emit`); confirm `db.ts` builds its contract with `contractFromJson<Contract>(contractJson)` and passes it to `postgres({ contract })` (the client infers the contract types from it). See `references/runtime.md` and `references/contract.md`. |
|
|
114
125
|
|
|
115
126
|
If the envelope's `code` is not in this table, follow the envelope's `fix` field literally — it's the framework's first-party next move. If `fix` is empty or unhelpful, escalate via `references/feedback.md`.
|
|
116
127
|
|
|
@@ -118,7 +129,7 @@ If the envelope's `code` is not in this table, follow the envelope's `fix` field
|
|
|
118
129
|
|
|
119
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`.
|
|
120
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.
|
|
121
|
-
3. **
|
|
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.
|
|
122
133
|
4. **Treating drift as something to silence with `db sign`.** `db sign` writes the marker 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`.
|
|
123
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 marker actually is.
|
|
124
135
|
|
|
@@ -127,7 +138,7 @@ If the envelope's `code` is not in this table, follow the envelope's `fix` field
|
|
|
127
138
|
- **Studio / GUI database browser.** No first-party Studio. Workaround: `prisma db schema` for a CLI tree of the live schema, or use a third-party tool (TablePlus, DataGrip, `psql`) against your `DATABASE_URL`. If you need a built-in GUI, file a feature request via `references/feedback.md`.
|
|
128
139
|
- **First-class query logger middleware.** No built-in "log every query" middleware ships with the framework. Workaround: write a small custom middleware that wraps each operation (see `references/runtime.md` for middleware composition). If you need a built-in query log, file a feature request via `references/feedback.md`.
|
|
129
140
|
- **`EXPLAIN` integration.** No first-class `.explain()` on plans. Workaround: write the EXPLAIN as a raw query (``db.raw.sql`EXPLAIN ANALYZE ...` ``; see `references/queries.md`). If you need first-class EXPLAIN, file a feature request via `references/feedback.md`.
|
|
130
|
-
- **Prepared statements are not a gap.** `db.prepare(declaration, (
|
|
141
|
+
- **Prepared statements are not a gap.** `db.prepare(declaration, (params) => plan)` (or `runtime.prepare(...)`, or `tx.prepare(...)` inside a transaction) builds a statement once; a row-returning statement runs with `ps.query(target, params)`, an affected-count one with `ps.execute(target, params)`, where `target` is the runtime, a connection or a transaction's `tx`. See *Prepared statements* in `references/queries.md`. TypedSQL (`.sql` files compiled to callables) is the thing that does not exist.
|
|
131
142
|
|
|
132
143
|
## Asking for help when the envelope doesn't route
|
|
133
144
|
|
|
@@ -138,7 +149,7 @@ If the envelope's `code` is not in this table, follow the envelope's `fix` field
|
|
|
138
149
|
|
|
139
150
|
- [ ] Identified which envelope shape (`CliErrorEnvelope`, `RuntimeErrorEnvelope`, `SqlQueryError`).
|
|
140
151
|
- [ ] Read every field — `code`, `severity`, `why`, `fix`, `meta` (or `details`), `where` if present.
|
|
141
|
-
- [ ]
|
|
152
|
+
- [ ] For an apply failure, read the typed `meta` keys (`schemaIssues`, `failedCheck`, `rowsWithoutValue`, `failedTypeChange`).
|
|
142
153
|
- [ ] Routed on `code` to the next move (and chained to the matching authoring skill where the table says so).
|
|
143
154
|
- [ ] Re-verified with the relevant CLI command (`db verify`, `migration status --json`, `contract emit`, `db migrate`).
|
|
144
155
|
- [ ] Did not confabulate a Studio / EXPLAIN / query-log API — used the documented workaround and routed unmet capability gaps to `references/feedback.md`.
|
|
@@ -15,9 +15,9 @@ Canonical channels:
|
|
|
15
15
|
## When to Use
|
|
16
16
|
|
|
17
17
|
- A capability-gap entry from another `prisma-8` skill fired and the user said *"yes, file the feature request"*.
|
|
18
|
-
- User says *"this is a bug"*, *"file this"*, *"report this"*, *"file an issue against
|
|
18
|
+
- User says *"this is a bug"*, *"file this"*, *"report this"*, *"file an issue against Prisma 8"*, *"send feedback"*, *"this should be a feature"*.
|
|
19
19
|
- User describes an unexpected behaviour — wrong exit code, error message that didn't match what happened, type signature that doesn't match runtime behaviour, planner refused a migration that looked safe — and wants it on the framework team's radar.
|
|
20
|
-
- User asks *"can I ask the Prisma team about this?"*, *"is there somewhere I can talk to the team?"*, *"is this the intended way to do X?"*, *"how should I integrate <my extension / my tool> with
|
|
20
|
+
- User asks *"can I ask the Prisma team about this?"*, *"is there somewhere I can talk to the team?"*, *"is this the intended way to do X?"*, *"how should I integrate <my extension / my tool> with Prisma 8?"*, or any other open-ended Q&A or design-feedback prompt — including extension authors asking integration questions.
|
|
21
21
|
|
|
22
22
|
## When Not to Use
|
|
23
23
|
|
|
@@ -71,7 +71,7 @@ The user is filing a GitHub issue. Is it a bug or a feature request?
|
|
|
71
71
|
|
|
72
72
|
**Feature request** if any of:
|
|
73
73
|
|
|
74
|
-
- The user wants a capability that doesn't exist yet (most of the *What
|
|
74
|
+
- The user wants a capability that doesn't exist yet (most of the *What Prisma 8 doesn't do yet* entries land here).
|
|
75
75
|
- The user wants a better error message, an additional CLI flag, a new middleware, an additional bundler plugin, etc.
|
|
76
76
|
|
|
77
77
|
If both — a bug *and* the user wants a related feature — file two separate issues. Mixing them makes the framework team's triage harder.
|
|
@@ -80,7 +80,7 @@ If both — a bug *and* the user wants a related feature — file two separate i
|
|
|
80
80
|
|
|
81
81
|
For **either** kind:
|
|
82
82
|
|
|
83
|
-
- **Prisma 8 version**: `pnpm ls @
|
|
83
|
+
- **Prisma 8 version**: `pnpm ls @prisma/orm-postgres` (or `@prisma/orm-mongo`). If the project uses a target package, that version is canonical.
|
|
84
84
|
- **Node version**: `node -v`.
|
|
85
85
|
- **Package manager**: `pnpm` / `npm` / `yarn` / `bun` / `deno`.
|
|
86
86
|
- **OS**: `darwin` / `linux` / `win32` and the version string is enough.
|
|
@@ -98,7 +98,7 @@ For **bug reports**, additionally:
|
|
|
98
98
|
For **feature requests**, additionally:
|
|
99
99
|
|
|
100
100
|
- **Desired API or behaviour** — one paragraph. Concrete shape (CLI flag, config field, middleware export, plugin API) where possible.
|
|
101
|
-
- **Where the gap surfaces today** — which skill's *What
|
|
101
|
+
- **Where the gap surfaces today** — which skill's *What Prisma 8 doesn't do yet* entry triggered the request, or the workflow the user was trying to complete.
|
|
102
102
|
- **Current workaround**, if any — one sentence (and the skill body the user is following may already say this).
|
|
103
103
|
|
|
104
104
|
### 4. Render the body
|
|
@@ -110,7 +110,7 @@ Bug-report body shape (fields named to match `.github/ISSUE_TEMPLATE/bug_report.
|
|
|
110
110
|
~~~markdown
|
|
111
111
|
## Package and version
|
|
112
112
|
|
|
113
|
-
<e.g. @
|
|
113
|
+
<e.g. @prisma/orm-postgres@8.0.0-rc.24>
|
|
114
114
|
|
|
115
115
|
## What happened?
|
|
116
116
|
|
|
@@ -209,7 +209,7 @@ When step 1 picked the Discord channel (steps 2–7 do not apply):
|
|
|
209
209
|
- Extension-author / partner-integration / breaking-change-coordination questions → the public extension-authors channel, or the user can ping a maintainer directly once they're in the server.
|
|
210
210
|
2. **Help draft the opening message.** Prisma's Discord is searchable; a well-framed opening message gets a faster, more useful answer. The agent drafts a short message with:
|
|
211
211
|
- One-sentence summary of what the user is trying to do.
|
|
212
|
-
- The Prisma 8 version (`pnpm ls @
|
|
212
|
+
- The Prisma 8 version (`pnpm ls @prisma/orm-postgres` or equivalent).
|
|
213
213
|
- A short code snippet (PSL excerpt, query, config file) where relevant — redacted the same way as a GitHub issue body (no `DATABASE_URL`, no customer schema names).
|
|
214
214
|
- The specific question the user wants answered.
|
|
215
215
|
3. **Do not auto-post.** The agent surfaces the drafted message to the user — *"here's an opening message you can paste into Discord; want to adjust before sending?"* — and lets the user decide whether to paste it as-is, edit it, or pick a different framing.
|
|
@@ -241,7 +241,7 @@ When step 1 picked the Discord channel (steps 2–7 do not apply):
|
|
|
241
241
|
## Checklist
|
|
242
242
|
|
|
243
243
|
- [ ] Classified as bug or feature request (not both in one issue).
|
|
244
|
-
- [ ] Environment block present:
|
|
244
|
+
- [ ] Environment block present: Prisma 8 version, Node, package manager, OS.
|
|
245
245
|
- [ ] Reproduction is minimal, public-safe, secret-free.
|
|
246
246
|
- [ ] Schema fragments use original names where safe; renamed to neutral placeholders only where original names would leak confidential domain detail.
|
|
247
247
|
- [ ] Title in conventional-commit form (`bug(area): …` / `feat(area): …`).
|
|
@@ -31,9 +31,13 @@ Consequences worth internalising:
|
|
|
31
31
|
- **The graph does not know where your database is.** "Where is my database" is answered by the database's **marker** (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
|
+
### What a migration may contain
|
|
35
|
+
|
|
36
|
+
Because a migration is an edge, `db migrate` can run it on any database whose marker 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
|
+
|
|
34
38
|
### Refs — version-controlled pointers
|
|
35
39
|
|
|
36
|
-
A ref is a small committed file, `migrations/<space>/refs/<name>.json` (for your app: `migrations/app/refs/<name>.json`), containing `{ hash, invariants }
|
|
40
|
+
A ref is a small committed file, `migrations/<space>/refs/<name>.json` (for your app: `migrations/app/refs/<name>.json`), containing `{ hash, invariants }` and, optionally, `policies`: the change policy and data protection policy its database should have (`references/migrations.md` § *Policies*). Two roles, by convention:
|
|
37
41
|
|
|
38
42
|
- **The `db` ref** records which contract hash the project's dev database has been brought to. It is a **checkpoint, not a promise**: dev commands write it after the fact so the offline planner knows where dev iteration left off, without opening a database connection.
|
|
39
43
|
- **Environment refs** (`staging`, `production`, …) name **the contract CD will migrate that environment to** — a forward promise the repo makes, consumed at deploy time. See `references/migration-review.md` for the deploy-side workflows.
|
|
@@ -48,6 +52,8 @@ pnpm prisma migration ref list
|
|
|
48
52
|
pnpm prisma migration ref delete <name>
|
|
49
53
|
```
|
|
50
54
|
|
|
55
|
+
A ref's `policies` are read and written with `migration ref policy show`, `set` and `delete`; `references/migrations.md` § *Policies* says what each does.
|
|
56
|
+
|
|
51
57
|
`migration ref set` requires the target to be the `to` hash of an on-disk migration. A hash outside the graph is refused (`MIGRATION.HASH_NOT_IN_GRAPH`); a hash that appears in the graph only as a `from` — no bundle produces it — is refused too (`MIGRATION.REF_SET_BUNDLE_NOT_FOUND`). Find node hashes with `migration list`.
|
|
52
58
|
|
|
53
59
|
### Who advances refs
|
|
@@ -55,9 +61,8 @@ pnpm prisma migration ref delete <name>
|
|
|
55
61
|
| Command | Ref advancement |
|
|
56
62
|
|---|---|
|
|
57
63
|
| `db init` / `db update` (default URL) | Implicitly advance `db` (override the name with `--advance-ref <name>`; suppressed whenever `--db` is passed without `--advance-ref`, regardless of the URL — even `--db $DATABASE_URL` pointing at the default database) |
|
|
58
|
-
| `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 `
|
|
59
|
-
| `db migrate
|
|
60
|
-
| plain `db migrate` | **Never advances anything** — deliberate: deploy and CI applies must not infer dev intent |
|
|
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` does **not** suppress it, unlike init/update: sign never mutates the schema, and adoption is normally done via `--db` |
|
|
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 |
|
|
61
66
|
| `migration plan` | Never advances anything — chaining discipline is yours |
|
|
62
67
|
| deploys (Composer / CD) | Write the database's marker; structurally cannot and do not touch repo refs |
|
|
63
68
|
|
|
@@ -65,12 +70,16 @@ pnpm prisma migration ref delete <name>
|
|
|
65
70
|
|
|
66
71
|
`migration plan` resolves its origin in exactly this order:
|
|
67
72
|
|
|
68
|
-
1. Explicit `--from <ref-name | hash | hash-prefix | migration-dir | migration-dir^ |
|
|
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 marker) 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`.
|
|
69
74
|
2. No `--from` → the `db` ref (`migrations/app/refs/db.json`).
|
|
70
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`.
|
|
71
76
|
|
|
72
77
|
It is **offline** — it never consults a database, never reads a marker (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).
|
|
73
78
|
|
|
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
|
+
|
|
81
|
+
**`migration new` picks its origin the same way, with one difference.** With `--from <hash-or-prefix>` it uses that migration's `to` hash. Without `--from`: the `db` ref (which must be a graph node), else greenfield on an empty graph, else `MIGRATION.PLAN_ORIGIN_UNKNOWN`. The difference: on an empty graph that has a `db` ref, `migration plan` writes the baseline (auto-baseline above) while `migration new` refuses with `MIGRATION.HASH_NOT_IN_GRAPH` and tells you to run `migration plan` first. Neither command ever chains from "the newest migration on disk" — there is no such node.
|
|
82
|
+
|
|
74
83
|
The human output names the resolved origin on its `from:` line. **`from: (baseline)` means the origin resolved to nothing — the plan starts from an empty database** and will contain a create for every object in the contract.
|
|
75
84
|
|
|
76
85
|
**Auto-baseline.** When the graph is *empty* and the origin resolved through a ref to a real hash (the typical first plan after `db update` cycles), the planner emits **two** bundles in one invocation — a baseline `null → ref-hash` plus the delta `ref-hash → contract` — so the ref's hash becomes a graph node and the plan can be applied. Expect two new directories in `git status`. Details and the related refusals (`MIGRATION.HASH_NOT_IN_GRAPH`, `MIGRATION.SNAPSHOT_MISSING`) are in `references/migrations.md` § *Dev → ship transition*.
|
|
@@ -79,7 +88,7 @@ The human output names the resolved origin on its `from:` line. **`from: (baseli
|
|
|
79
88
|
|
|
80
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 marker 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.
|
|
81
90
|
|
|
82
|
-
How the fall-through happens: a project
|
|
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.
|
|
83
92
|
|
|
84
93
|
**Recognize a from-empty plan** that was produced anyway (an explicit `--from @empty`, or an older CLI without the refusal), at either layer:
|
|
85
94
|
|
|
@@ -95,20 +104,20 @@ How the fall-through happens: a project that never runs `db init` / `db update`
|
|
|
95
104
|
|
|
96
105
|
## Workflow — the dev loop
|
|
97
106
|
|
|
98
|
-
The concept: while the schema is in flux, iterate the dev database with `db init` / `db update` — they apply the contract *and* keep the `db` ref current. When the shape settles, plan: the plan chains from the ref,
|
|
107
|
+
The concept: while the schema is in flux, iterate the dev database with `db init` / `db update` — they apply the contract *and* keep the `db` ref current. When the shape settles, plan and apply: the plan chains from the ref, the auto-baseline covers the case where the graph is still empty, and `db migrate` on the config's database moves the ref to what it applied.
|
|
99
108
|
|
|
100
109
|
```bash
|
|
101
110
|
pnpm prisma db init # once; advances the db ref
|
|
102
111
|
pnpm prisma contract emit && pnpm prisma db update # iterate; each advances the db ref
|
|
103
112
|
pnpm prisma contract emit && pnpm prisma migration plan --name <slug>
|
|
104
|
-
pnpm prisma db migrate
|
|
113
|
+
pnpm prisma db migrate # applies it; advances the db ref
|
|
105
114
|
```
|
|
106
115
|
|
|
107
|
-
|
|
116
|
+
Full mechanics, refusals, and recovery: `references/migrations.md` § *Dev → ship transition*.
|
|
108
117
|
|
|
109
118
|
## Workflow — the deploy-first loop (Composer / CD-managed databases)
|
|
110
119
|
|
|
111
|
-
The concept: the deploy pipeline owns the databases, so `db init` / `db update` never run and nothing ever advances a `db` ref for you. Deploys replay each database from its marker to the contract emitted at build time; they never write to `migrations/app/refs/`. Two disciplines keep this loop safe:
|
|
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 marker to the contract emitted at build time; they never write to `migrations/app/refs/`. Two disciplines keep this loop safe:
|
|
112
121
|
|
|
113
122
|
**Author the baseline before the first deploy.** Before anything is deployed:
|
|
114
123
|
|
|
@@ -152,12 +161,12 @@ The concept: the database exists and its marker is accurate (hash **M**) — it
|
|
|
152
161
|
|
|
153
162
|
## Common Pitfalls
|
|
154
163
|
|
|
155
|
-
1. **Assuming `migration plan` chains from the newest migration on disk.**
|
|
156
|
-
2. **Expecting `migration plan
|
|
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` (and, for `db migrate`, outside CI); `db sign` advances it even with `--db`. Elsewhere, pass `--advance-ref db`.
|
|
157
166
|
3. **Expecting a deploy to update refs.** Deploys write the database's marker; the files under `migrations/app/refs/` only change when you change them.
|
|
158
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.
|
|
159
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.
|
|
160
|
-
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
|
|
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.
|
|
161
170
|
7. **Authoring the first migration after the first deploy.** Then no graph node corresponds to what shipped, and every incremental path needs the retrofit. Baseline before the first deploy — it's one command.
|
|
162
171
|
|
|
163
172
|
## What Prisma 8 doesn't do yet
|
|
@@ -171,5 +180,5 @@ The concept: the database exists and its marker is accurate (hash **M**) — it
|
|
|
171
180
|
- [ ] In a deploy-first project: baseline authored and committed before the first deploy; every later plan chained via the `db` ref or `--from`.
|
|
172
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.
|
|
173
182
|
- [ ] For a marked database with no on-disk migrations: made the graph reach the marker's hash (auto-baseline via `db update` or `db sign`, or an offline baseline plan) before planning deltas.
|
|
174
|
-
- [ ]
|
|
183
|
+
- [ ] Expected plain `db migrate` to advance `db` only when its connection comes from `prisma.config.ts`, the CLI does not detect CI and neither `--advance-ref` nor `--no-advance-ref` is passed; did NOT expect `migration plan`, `db migrate --db`, or a deploy in CI to advance any ref.
|
|
175
184
|
- [ ] Did NOT apply or commit a `from: (baseline)` plan without confirming the empty origin was the intent.
|
|
@@ -12,7 +12,7 @@ The skill teaches *the system's mental model* — what a ref is, what a marker i
|
|
|
12
12
|
- User asks *"what migrations will run when I merge this?"* or *"what's about to run on deploy?"*.
|
|
13
13
|
- User hit a concurrent-migration conflict (`main` advanced while their branch was open).
|
|
14
14
|
- User wants to wire up a `staging` / `production` ref so CI can deploy against it.
|
|
15
|
-
- User wants to run a migration against
|
|
15
|
+
- User wants to run a migration against a deployed environment.
|
|
16
16
|
- User asks about CI integration for migrations.
|
|
17
17
|
|
|
18
18
|
## When Not to Use
|
|
@@ -27,7 +27,7 @@ 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
|
|
30
|
+
The **origin** is the database's *current contract hash*. The database carries a row in Prisma 8's marker 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 marker 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
32
|
A live DB is therefore the authoritative source of origin. The "recorded marker" in any other artifact (refs, local cache, your assumptions) is a working copy that can drift; the live DB never does.
|
|
33
33
|
|
|
@@ -48,17 +48,17 @@ The graph is a static, committed artifact. Several branch tips may coexist, roll
|
|
|
48
48
|
|
|
49
49
|
`migration status` queries the graph for the path from origin to destination and reports per-edge status:
|
|
50
50
|
|
|
51
|
-
- **applied** —
|
|
52
|
-
- **pending** — on the path from the
|
|
53
|
-
-
|
|
51
|
+
- **applied** — the database's ledger records the migration as applied. Only a run connected to a database reports this.
|
|
52
|
+
- **pending** — on the path from the origin to the destination and not yet applied (what would run).
|
|
53
|
+
- **`null`** — neither: the migration is off the path to the destination, or the run is offline and cannot see what the database applied. In data lines this is an empty field.
|
|
54
54
|
|
|
55
55
|
### Diagnostic codes
|
|
56
56
|
|
|
57
|
-
`migration status` answers with a document (`--json`): `spaces[]`, each with `currentContract` (the marker hash, or `null` when the database has no marker for that space), `targetContract`, and `migrations[]` carrying the `applied` / `pending` / `
|
|
57
|
+
`migration status` answers with a document (`--json`): `spaces[]`, each with `currentContract` (the marker hash, or `null` when the database has no marker 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 marker yet, marker 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.MARKER_NOT_IN_HISTORY` | Online; marker hash is not a node in the graph. The database was changed outside the migration system. |
|
|
61
|
+
| `MIGRATION.MARKER_NOT_IN_HISTORY` | Online; marker 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 `meta.policies` corrected first. **Not** the same as `MIGRATION.MARKER_MISMATCH`, which `db migrate` (before any DDL) and `db migrate --show` raise as an error when the marker hash is not a graph node. |
|
|
62
62
|
| `MIGRATION.MISSING_INVARIANTS` | Marker 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
|
|
|
@@ -79,12 +79,10 @@ These codes surface on `migration plan`, `migration ref set`, and `db migrate`
|
|
|
79
79
|
|
|
80
80
|
| Code | When | Meaning | Next move |
|
|
81
81
|
|---|---|---|---|
|
|
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
|
|
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.MARKER_MISMATCH` | `db migrate` (pre-DDL, before the runner) | Live DB marker hash is not a graph node
|
|
85
|
-
| `MIGRATION.PATH_UNREACHABLE` | `db migrate` (path resolution) | No migration path from the current marker to the resolved target in the on-disk graph. | Read the improved `fix` payload — it names `fromHash` / `targetHash` and
|
|
86
|
-
|
|
87
|
-
A CI gate should read `diagnostics` from `--json` output and decide based on `severity` plus `code`; see *Workflow — CI* below for the structure.
|
|
84
|
+
| `MIGRATION.MARKER_MISMATCH` | `db migrate` (pre-DDL, before the runner), `db migrate --show` | Live DB marker hash 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 marker is not in the migration graph*. Never reset the database. |
|
|
85
|
+
| `MIGRATION.PATH_UNREACHABLE` | `db migrate` (path resolution) | No migration path from the current marker 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. |
|
|
88
86
|
|
|
89
87
|
## Workflow — *"What's about to run on deploy?"*
|
|
90
88
|
|
|
@@ -100,14 +98,14 @@ The command:
|
|
|
100
98
|
|
|
101
99
|
1. Reads the staging DB's marker (the origin).
|
|
102
100
|
2. Resolves `staging` to a contract hash (the destination).
|
|
103
|
-
3. Renders the path between them as an ordered list of migrations, with per-edge `applied` / `pending` / `
|
|
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'"*.
|
|
104
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.
|
|
105
103
|
|
|
106
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 marker.
|
|
107
105
|
|
|
108
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.
|
|
109
107
|
|
|
110
|
-
`migration status` summarises each pending migration's operations by class (`additive`, `widening`, `data`, `destructive`) and reports a destructive-op count when destructive operations are present. Surface that count to the user before they merge or deploy
|
|
108
|
+
`migration status` summarises each pending migration's operations by class (`additive`, `widening`, `data`, `destructive`) and reports a destructive-op count when destructive operations are present. Surface that count to the user before they merge or deploy. Review `destructive` and `data` operations before deploy: both can change stored data. Then read each pending `migration.ts` against `references/migrations.md` § *Data changes go in a data transform*. These are findings: an insert, update or delete outside a data transform; a Postgres data transform whose query comes from `db.raw.sql` or contains `fns.raw`; a Postgres or Mongo data transform without `check`; and a hand-written `rawSql` step, unless it is DDL that no operation factory expresses and has both a precheck and a postcheck that test the live schema. `rawSql` steps the planner rendered itself are not findings; if you cannot tell who wrote a step, ask the author.
|
|
111
109
|
|
|
112
110
|
## Workflow — *"What state is each environment at?"*
|
|
113
111
|
|
|
@@ -115,7 +113,7 @@ Just `migration status --db $URL` for each environment's DB. The marker (origin)
|
|
|
115
113
|
|
|
116
114
|
## Concept — concurrent migrations on the same branch point
|
|
117
115
|
|
|
118
|
-
This used to be called *diamond convergence* in some
|
|
116
|
+
This used to be called *diamond convergence* in some Prisma 8 docs; the situation is the same regardless of the label.
|
|
119
117
|
|
|
120
118
|
**What's happening.** Two topic branches each authored a migration off the same parent contract hash. The first branch merges to `main`; the destination ref (e.g. `production`) advances to that branch's `to` hash. Your branch's migration still has its `from` hash pointing at the *old* parent. The migration graph, after rebase, no longer has a clean path through your migration:
|
|
121
119
|
|
|
@@ -166,48 +164,20 @@ The mismatch is a fact about *two pieces of state that disagree*. The investigat
|
|
|
166
164
|
|
|
167
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.
|
|
168
166
|
|
|
169
|
-
## Workflow — CI:
|
|
170
|
-
|
|
171
|
-
The gate is `migration status --to <env> --db $URL`: it computes the path from the live marker to the ref and reports it, without mutating anything. There is no `--dry-run` flag on `db migrate`; the inspect / gate step is `migration status`.
|
|
167
|
+
## Workflow — CI: deploy to an environment
|
|
172
168
|
|
|
173
|
-
|
|
169
|
+
The whole job is one command:
|
|
174
170
|
|
|
175
171
|
```yaml
|
|
176
|
-
- name:
|
|
177
|
-
run: |
|
|
178
|
-
pnpm prisma migration status \
|
|
179
|
-
--to staging --db "$STAGING_DATABASE_URL" --json > status.json
|
|
180
|
-
node -e '
|
|
181
|
-
const s = JSON.parse(require("fs").readFileSync("status.json", "utf8"));
|
|
182
|
-
const problems = [];
|
|
183
|
-
for (const d of s.diagnostics ?? []) {
|
|
184
|
-
if (d.severity === "warn") problems.push(`${d.code}: ${d.message}`);
|
|
185
|
-
}
|
|
186
|
-
for (const space of s.spaces ?? []) {
|
|
187
|
-
if (space.currentContract === null) problems.push(`${space.space}: database has no marker`);
|
|
188
|
-
const unreachable = space.migrations.filter(m => m.status === "unreachable");
|
|
189
|
-
if (unreachable.length) problems.push(`${space.space}: ${unreachable.length} unreachable migration(s)`);
|
|
190
|
-
}
|
|
191
|
-
// Pending migrations are the normal case before Apply; block on them
|
|
192
|
-
// only if this job is a verify-only gate (set EXPECT_UP_TO_DATE=1).
|
|
193
|
-
if (process.env.EXPECT_UP_TO_DATE === "1") {
|
|
194
|
-
for (const space of s.spaces ?? []) {
|
|
195
|
-
const pending = space.migrations.filter(m => m.status === "pending");
|
|
196
|
-
if (pending.length) problems.push(`${space.space}: ${pending.length} pending migration(s)`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (problems.length) {
|
|
200
|
-
console.error("Blocking:\n" + problems.join("\n"));
|
|
201
|
-
process.exit(1);
|
|
202
|
-
}
|
|
203
|
-
'
|
|
204
|
-
- name: Apply
|
|
172
|
+
- name: Migrate staging
|
|
205
173
|
run: pnpm prisma db migrate --to staging --db "$STAGING_DATABASE_URL"
|
|
206
174
|
```
|
|
207
175
|
|
|
208
|
-
`
|
|
176
|
+
`db migrate` is safe to run unattended, by design. Before any operation runs it reads the live marker and refuses with `MIGRATION.MARKER_MISMATCH` 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 marker. Nothing runs before `db migrate` in the job.
|
|
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 marker 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.
|
|
209
179
|
|
|
210
|
-
`db migrate` is interactive-free and
|
|
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.
|
|
211
181
|
|
|
212
182
|
## Common Pitfalls
|
|
213
183
|
|
|
@@ -234,8 +204,9 @@ This skill is intentionally body-only; the underlying CLI reference (`prisma mig
|
|
|
234
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.
|
|
235
205
|
- [ ] For concurrent-migration conflicts: re-applied the *core* workflow (edit → plan → apply) rather than following a memorised "diamond convergence" procedure. Ported any data-transform logic from the abandoned `migration.ts` over.
|
|
236
206
|
- [ ] For a ref-mismatch: investigated *which* piece of state is wrong (DB ahead, DB behind, DB on a divergent branch). Did NOT `migration ref set` to silence the mismatch.
|
|
237
|
-
- [ ] Surfaced the destructive-op count from `migration status`
|
|
238
|
-
- [ ]
|
|
207
|
+
- [ ] Surfaced the destructive-op count from `migration status` before the user merges or deploys, and reviewed every `destructive` and `data` operation.
|
|
208
|
+
- [ ] Flagged inserts, updates and deletes outside a data transform, Postgres transforms that use `db.raw.sql` or `fns.raw`, Postgres and Mongo transforms without `check`, and hand-written `rawSql` steps, unless they are DDL that no operation factory expresses and have both a precheck and a postcheck that test the live schema. Did NOT flag `rawSql` steps the planner rendered.
|
|
209
|
+
- [ ] In CI: the deploy job is `prisma db migrate --to <ref> --db $URL` and nothing else. Did NOT rely on a `--dry-run` flag on `db migrate` (no such flag exists).
|
|
239
210
|
- [ ] Did NOT confuse `--to` with database selection (`--to` picks the destination hash; `--db` picks the database).
|
|
240
211
|
- [ ] Did NOT use `--ref` (removed; use `--to`).
|
|
241
212
|
- [ ] Did NOT confabulate a "branch diff" CLI subcommand, a `migration revalidate` step, or any other API the skill above doesn't reference.
|