@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.
Files changed (165) hide show
  1. package/README.md +6 -5
  2. package/dist/contract-builder.d.mts +10 -12
  3. package/dist/contract-builder.d.mts.map +1 -1
  4. package/dist/contract-types.d.mts +3 -3
  5. package/dist/{mongo-static-BV3j1fN5-TbRr6qQe.mjs → mongo-static-mpUQsCV6-Djox0d1n.mjs} +4 -4
  6. package/dist/mongo-static-mpUQsCV6-Djox0d1n.mjs.map +1 -0
  7. package/dist/runtime.d.mts +2 -1
  8. package/dist/runtime.d.mts.map +1 -1
  9. package/dist/runtime.mjs +6 -6
  10. package/dist/runtime.mjs.map +1 -1
  11. package/dist/static.mjs +1 -1
  12. package/package.json +12 -81
  13. package/skills/prisma-8/SKILL.md +7 -7
  14. package/skills/prisma-8/references/contract.md +1 -1
  15. package/skills/prisma-8/references/debug.md +11 -11
  16. package/skills/prisma-8/references/migration-model.md +17 -17
  17. package/skills/prisma-8/references/migration-review.md +21 -21
  18. package/skills/prisma-8/references/migrations.md +58 -42
  19. package/skills/prisma-8/references/queries-postgres.md +7 -7
  20. package/skills/prisma-8/references/quickstart.md +11 -11
  21. package/skills/prisma-8/references/runtime.md +3 -3
  22. package/skills/prisma-8/references/upgrade-app.md +55 -17
  23. package/skills/prisma-8/references/upgrade-extension.md +34 -11
  24. package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +1 -1
  25. package/skills/prisma-8/upgrading/extension/upgrades/0.8-to-0.9/instructions.md +1 -1
  26. package/skills/prisma-8/upgrading/extension/upgrades/0.9-to-0.10/instructions.md +1 -1
  27. package/dist/adapter.d.mts +0 -1
  28. package/dist/adapter.mjs +0 -2
  29. package/dist/adapter__control.d.mts +0 -3
  30. package/dist/adapter__control.mjs +0 -3
  31. package/dist/adapter__runtime.d.mts +0 -3
  32. package/dist/adapter__runtime.mjs +0 -3
  33. package/dist/components.d.mts +0 -1
  34. package/dist/components.mjs +0 -2
  35. package/dist/components__authoring.d.mts +0 -1
  36. package/dist/components__authoring.mjs +0 -2
  37. package/dist/components__codec.d.mts +0 -1
  38. package/dist/components__codec.mjs +0 -2
  39. package/dist/components__components.d.mts +0 -1
  40. package/dist/components__components.mjs +0 -2
  41. package/dist/components__control.d.mts +0 -1
  42. package/dist/components__control.mjs +0 -2
  43. package/dist/components__emission.d.mts +0 -1
  44. package/dist/components__emission.mjs +0 -2
  45. package/dist/components__execution.d.mts +0 -1
  46. package/dist/components__execution.mjs +0 -2
  47. package/dist/components__ir.d.mts +0 -1
  48. package/dist/components__ir.mjs +0 -2
  49. package/dist/components__psl-ast.d.mts +0 -1
  50. package/dist/components__psl-ast.mjs +0 -2
  51. package/dist/components__utils.d.mts +0 -1
  52. package/dist/components__utils.mjs +0 -2
  53. package/dist/contract.d.mts +0 -1
  54. package/dist/contract.mjs +0 -2
  55. package/dist/contract__apply-specifier-default-control-policy.d.mts +0 -1
  56. package/dist/contract__apply-specifier-default-control-policy.mjs +0 -2
  57. package/dist/contract__contract-validation-error.d.mts +0 -1
  58. package/dist/contract__contract-validation-error.mjs +0 -2
  59. package/dist/contract__default-namespace.d.mts +0 -1
  60. package/dist/contract__default-namespace.mjs +0 -2
  61. package/dist/contract__enum-accessor.d.mts +0 -1
  62. package/dist/contract__enum-accessor.mjs +0 -2
  63. package/dist/contract__format-version.d.mts +0 -1
  64. package/dist/contract__format-version.mjs +0 -2
  65. package/dist/contract__hashing-utils.d.mts +0 -1
  66. package/dist/contract__hashing-utils.mjs +0 -2
  67. package/dist/contract__hashing.d.mts +0 -1
  68. package/dist/contract__hashing.mjs +0 -2
  69. package/dist/contract__internal__format-version.d.mts +0 -1
  70. package/dist/contract__internal__format-version.mjs +0 -2
  71. package/dist/contract__is-plain-record.d.mts +0 -1
  72. package/dist/contract__is-plain-record.mjs +0 -2
  73. package/dist/contract__resolve-domain-model.d.mts +0 -1
  74. package/dist/contract__resolve-domain-model.mjs +0 -2
  75. package/dist/contract__validate-domain.d.mts +0 -1
  76. package/dist/contract__validate-domain.mjs +0 -2
  77. package/dist/contract__validate-once.d.mts +0 -1
  78. package/dist/contract__validate-once.mjs +0 -2
  79. package/dist/contract__validate-storage.d.mts +0 -1
  80. package/dist/contract__validate-storage.mjs +0 -2
  81. package/dist/driver.d.mts +0 -1
  82. package/dist/driver.mjs +0 -2
  83. package/dist/driver__control.d.mts +0 -3
  84. package/dist/driver__control.mjs +0 -3
  85. package/dist/driver__runtime.d.mts +0 -3
  86. package/dist/driver__runtime.mjs +0 -3
  87. package/dist/family-contract__canonicalization-hooks.d.mts +0 -1
  88. package/dist/family-contract__canonicalization-hooks.mjs +0 -2
  89. package/dist/family-contract__data-type.d.mts +0 -1
  90. package/dist/family-contract__data-type.mjs +0 -2
  91. package/dist/family-contract__entity-kinds.d.mts +0 -1
  92. package/dist/family-contract__entity-kinds.mjs +0 -2
  93. package/dist/family__control-adapter.d.mts +0 -1
  94. package/dist/family__control-adapter.mjs +0 -2
  95. package/dist/family__ir.d.mts +0 -1
  96. package/dist/family__ir.mjs +0 -2
  97. package/dist/family__migration.d.mts +0 -1
  98. package/dist/family__migration.mjs +0 -2
  99. package/dist/family__pack.d.mts +0 -3
  100. package/dist/family__pack.mjs +0 -3
  101. package/dist/family__runtime.d.mts +0 -1
  102. package/dist/family__runtime.mjs +0 -2
  103. package/dist/family__schema-verify.d.mts +0 -1
  104. package/dist/family__schema-verify.mjs +0 -2
  105. package/dist/migration-tools__contract-snapshot-store.d.mts +0 -1
  106. package/dist/migration-tools__contract-snapshot-store.mjs +0 -2
  107. package/dist/mongo-static-BV3j1fN5-TbRr6qQe.mjs.map +0 -1
  108. package/dist/query-ast.d.mts +0 -1
  109. package/dist/query-ast.mjs +0 -2
  110. package/dist/query-ast__control.d.mts +0 -1
  111. package/dist/query-ast__control.mjs +0 -2
  112. package/dist/query-builder__contract-free.d.mts +0 -1
  113. package/dist/query-builder__contract-free.mjs +0 -2
  114. package/dist/target__codecs.d.mts +0 -1
  115. package/dist/target__codecs.mjs +0 -2
  116. package/dist/target__control.d.mts +0 -1
  117. package/dist/target__control.mjs +0 -2
  118. package/dist/target__data-types.d.mts +0 -1
  119. package/dist/target__data-types.mjs +0 -2
  120. package/dist/target__pack.d.mts +0 -3
  121. package/dist/target__pack.mjs +0 -3
  122. package/dist/target__server-version.d.mts +0 -1
  123. package/dist/target__server-version.mjs +0 -2
  124. package/dist/utils.d.mts +0 -1
  125. package/dist/utils.mjs +0 -2
  126. package/dist/utils__abortable.d.mts +0 -1
  127. package/dist/utils__abortable.mjs +0 -2
  128. package/dist/utils__array-equal.d.mts +0 -1
  129. package/dist/utils__array-equal.mjs +0 -2
  130. package/dist/utils__assertions.d.mts +0 -1
  131. package/dist/utils__assertions.mjs +0 -2
  132. package/dist/utils__canonical-stringify.d.mts +0 -1
  133. package/dist/utils__canonical-stringify.mjs +0 -2
  134. package/dist/utils__casts.d.mts +0 -1
  135. package/dist/utils__casts.mjs +0 -2
  136. package/dist/utils__defined.d.mts +0 -1
  137. package/dist/utils__defined.mjs +0 -2
  138. package/dist/utils__guards.d.mts +0 -1
  139. package/dist/utils__guards.mjs +0 -2
  140. package/dist/utils__hash-content.d.mts +0 -1
  141. package/dist/utils__hash-content.mjs +0 -2
  142. package/dist/utils__internal-error.d.mts +0 -1
  143. package/dist/utils__internal-error.mjs +0 -2
  144. package/dist/utils__json.d.mts +0 -1
  145. package/dist/utils__json.mjs +0 -2
  146. package/dist/utils__promise.d.mts +0 -1
  147. package/dist/utils__promise.mjs +0 -2
  148. package/dist/utils__redact-db-url.d.mts +0 -1
  149. package/dist/utils__redact-db-url.mjs +0 -2
  150. package/dist/utils__result.d.mts +0 -1
  151. package/dist/utils__result.mjs +0 -2
  152. package/dist/utils__simplify-deep.d.mts +0 -1
  153. package/dist/utils__simplify-deep.mjs +0 -2
  154. package/dist/utils__structured-error.d.mts +0 -1
  155. package/dist/utils__structured-error.mjs +0 -2
  156. package/dist/utils__suppress-idle-connection-errors.d.mts +0 -1
  157. package/dist/utils__suppress-idle-connection-errors.mjs +0 -2
  158. package/dist/utils__text.d.mts +0 -1
  159. package/dist/utils__text.mjs +0 -2
  160. package/dist/utils__types.d.mts +0 -1
  161. package/dist/utils__types.mjs +0 -2
  162. package/dist/utils__upgrade-guides.d.mts +0 -1
  163. package/dist/utils__upgrade-guides.mjs +0 -2
  164. package/dist/value__mongodb-types.d.mts +0 -1
  165. package/dist/value__mongodb-types.mjs +0 -2
@@ -11,7 +11,7 @@ The three-step user model:
11
11
 
12
12
  Once the contract changes, you choose how the change reaches the database. This skill covers the two paths (`db update` and `migration plan` + `db migrate`), the migration-package contract, the `migration.ts` authoring API, and the failure modes you recover from without leaving the loop.
13
13
 
14
- **Targets.** This reference covers migration authoring for **Postgres** and **Mongo**. The CLI reads the target from `prisma.config.ts` (set during `prisma orm init --target …`). Migration commands do not accept a `--target` flag — use a config scoped to the target you need. Examples below call out target-specific imports, markers, factories, and transaction behavior where they diverge.
14
+ **Targets.** This reference covers migration authoring for **Postgres** and **Mongo**. The CLI reads the target from `prisma.config.ts` (set during `prisma orm init --target …`). Migration commands do not accept a `--target` flag — use a config scoped to the target you need. Where the targets differ, the examples below say so: in imports, factories, transaction behavior, and where each target keeps its contract signatures.
15
15
 
16
16
  ## When to Use
17
17
 
@@ -20,7 +20,7 @@ Once the contract changes, you choose how the change reaches the database. This
20
20
  - User wants to run pending migrations against a local DB.
21
21
  - User hit `MIGRATION.HASH_MISMATCH`, `MIGRATION.UNFILLED_PLACEHOLDER`, or a partially-applied migration.
22
22
  - User mentions: *migrate, migration, db push, db update, `prisma migrate dev`, `prisma migrate deploy`, drift, hash mismatch, data backfill*.
23
- - A deploy or `db migrate` fails with `MIGRATION.MARKER_MISMATCH` (older Composer releases: "no authored path"), or someone proposes resetting a database → *A database whose marker is not in the migration graph* below. For `MIGRATION.PATH_UNREACHABLE`, where the marker is in the graph but no migration reaches the target, plan from the marker to the target instead (`references/debug.md`).
23
+ - A deploy or `db migrate` fails with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` (older Composer releases: "no authored path"), or someone proposes resetting a database → *A database whose contract signature is not in the migration graph* below. For `MIGRATION.PATH_UNREACHABLE`, where the signature is in the graph but no migration reaches the target, plan from the signature to the target instead (`references/debug.md`).
24
24
 
25
25
  ## When Not to Use
26
26
 
@@ -45,10 +45,10 @@ Once the contract changes, you choose how the change reaches the database. This
45
45
  - **`this.dataTransform(contract, name, { check, run })`.** The Postgres data-transform factory. `check` is a rowset query whose presence-of-any-row signals "work remains"; `run` is one or more mutation queries that perform the backfill. Both are lazy closures returning query plans built with the SQL query builder over the end contract. `contract` is the `contract` that `postgres({ contract: contractFromJson<End>(endContract) })` returns, not the imported `endContract` JSON the planner renders (see *Fill a placeholder*). The runner wraps `check` as `EXISTS(...)` for precheck and `NOT EXISTS(...)` for postcheck, so the same closure asserts both "there is work" and "the work is done".
46
46
  - **`pendingPlaceholders`.** A boolean field on the JSON result of `migration plan`. `true` means the package was written but contains unfilled placeholders — `db migrate` will throw `MIGRATION.UNFILLED_PLACEHOLDER` until you edit `migration.ts` and self-emit.
47
47
  - **`migrationHash`.** Content-addressed identity of a migration package. `MIGRATION.HASH_MISMATCH` fires when the stored hash in `migration.json` disagrees with the hash recomputed from the on-disk files (almost always: someone edited `migration.ts` without self-emitting).
48
- - **Marker.** Records "this database is at contract hash X for space Y". **Postgres:** a row in `prisma_contract.marker`. **Mongo:** a document in the `_prisma_migrations` collection (keyed by space). Each successful migration advances the marker once schema verification passes for that space. `db sign` writes the marker from the current contract hash, but only after a schema-verification pass succeeds (it will not sign a database whose live schema disagrees with the contract).
49
- - **Apply atomicity.** **Postgres:** one `db migrate` run is one transaction — the runner issues a single `BEGIN`, applies every pending migration for every contract space, then one `COMMIT`; any failure issues `ROLLBACK` for the whole run, so the marker stays where it was before the command. **Mongo:** DDL ops (`createCollection`, `createIndex`, `collMod`, `setValidation`, …) are not wrapped in a multi-document transaction; the runner applies ops, verifies the live schema against the destination contract, and advances the marker only on verify-pass (resumable across spaces — see the MongoDB family doc). Ordinary DDL + `dataTransform` flows stay consistent; partial state from failed mid-migration runs is diagnosed with `db verify` / `db schema`, not assumed away.
48
+ - **Contract signature.** Records "this database is at contract hash X for space Y". **Postgres:** a row in `prisma.signatures`. **Mongo:** a document in the `_prisma_migrations` collection (keyed by space). Each successful migration advances the signature once schema verification passes for that space. `db sign` writes the signature from the current contract hash, but only after a schema-verification pass succeeds (it will not sign a database whose live schema disagrees with the contract).
49
+ - **Apply atomicity.** **Postgres:** one `db migrate` run is one transaction — the runner issues a single `BEGIN`, applies every pending migration for every contract space, then one `COMMIT`; any failure issues `ROLLBACK` for the whole run, so the signature stays where it was before the command. **Mongo:** DDL ops (`createCollection`, `createIndex`, `collMod`, `setValidation`, …) are not wrapped in a multi-document transaction; the runner applies ops, verifies the live schema against the destination contract, and advances the signature only on verify-pass (resumable across spaces — see the MongoDB family doc). Ordinary DDL + `dataTransform` flows stay consistent; partial state from failed mid-migration runs is diagnosed with `db verify` / `db schema`, not assumed away.
50
50
  - **Changed foreign key actions and primary keys (Postgres).** A changed `onDelete`/`onUpdate` plans a drop and an add of the foreign key. A moved or removed primary key plans a drop (and an add), and the foreign keys that reference the old key are dropped first and added back after it. These ask no data-loss question.
51
- - **Policies.** A database records in its marker how it may be changed: its *change policy* (`migrate`, `reconcile` or both; `reconcile` is what `db update` and `db sign` do) and its *data protection policy* (`dataLoss` and `accessWidening`, each `forbidden`, `with-consent` or `permitted`). Every command that changes a database obeys both. A ref declares the policies its database should have in a `policies` field. See *Policies: what a database says about how it may change* below.
51
+ - **Policies.** A database records how it may be changed (**Postgres:** in the one row of `prisma.config`; **Mongo** and the other SQL targets: in the application space's signature, under `meta.policies`): its *change policy* (`migrate`, `reconcile` or both; `reconcile` is what `db update` and `db sign` do) and its *data protection policy* (`dataLoss` and `accessWidening`, each `forbidden`, `with-consent` or `permitted`). Every command that changes a database obeys both. A ref declares the policies its database should have in a `policies` field. See *Policies: what a database says about how it may change* below.
52
52
  - **Operation classes.** Every operation declares an `operationClass`: `additive`, `widening`, `data`, or `destructive`. `additive` adds structure and leaves existing structure and data as they are. `widening` changes existing structure without losing data; an operation that cannot keep every value fails instead, so a tightened constraint such as `SET NOT NULL` is widening. `destructive` can lose rows or values: dropping a table or column, or a type change that can change values. `data` reads and writes rows as its author wrote them, such as a backfill or a type conversion; a `dataTransform` is always `data`. Each operation factory sets its own class (`this.alterColumnType` is `data` with `using` and `destructive` without it, unless you pass `operationClass`). A `rawSql` step you write takes the class of the factory that would express it, or the class the definitions above give. The CLI surfaces these in the plan preview and in JSON output. There is no `long-running` class and the framework does not emit `CREATE INDEX CONCURRENTLY` — operations stay transactional.
53
53
 
54
54
  ## `migration.ts` is framework-rendered, not hand-authored
@@ -77,8 +77,10 @@ Treat the rendered import lines as framework-managed on both targets:
77
77
  | `CLI.CONSENT_REQUIRED` | `migration plan` / `db update` run with nobody to answer (`--no-interactive`, CI, `--yes`) | The plan would lose data or (on `db update`) widen access. `meta.unanswered` and `nextActions` list each question with the flags that answer it: `--delete <subject>`, `--rename <subject>:<new name>`, `--allow <Model>`. Re-run with the ones you mean. `--confirm` and `--yes` answer none of them. |
78
78
  | `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`. |
79
79
  | `MIGRATION.STATEMENT_DID_NOT_RESOLVE_LOSS` | A rename typed at the data-loss prompt | The plan was made again with the rename and still loses the subject's data. Answer with `delete`, or give a rename whose old name is the subject. |
80
- | `CONTRACT.MARKER_MISMATCH` | `db verify` (finding, exit 4) | The marker disagrees with the contract hash (**Postgres:** `prisma_contract.marker`; **Mongo:** `_prisma_migrations`). The DB is at a different contract version than the code thinks. Either run a migration forward, or — if the DB is correct and the marker is stale after a manual fix-up — run `db sign`. |
81
- | `CONTRACT.MARKER_MISSING` | `db verify` (finding, exit 4), runtime startup (warning) | The DB has no marker yet. Run `prisma db init --db <url>` to baseline an empty database, `db update --db <url>` to apply the current contract directly, or `db sign --db <url>` if the schema already matches the contract. |
80
+ | `CONTRACT.SIGNATURE_MISMATCH` | `db verify` (finding, exit 4) | The contract signature disagrees with the contract hash (**Postgres:** `prisma.signatures`; **Mongo:** `_prisma_migrations`). The DB is at a different contract version than the code thinks. Either run a migration forward, or — if the DB is correct and the signature is stale after a manual fix-up — run `db sign`. |
81
+ | `CONTRACT.PRISMA_SPACE_BEHIND` | `db verify`, `migration status`, `migration log`, dry runs; the client's first query (a warning, only when the client is given a `log`) | The records Prisma keeps for itself in the database are not up to date with the installed release, for example a database a release candidate set up, whose tables are in `prisma_contract`. Run the command the project already uses to change its database: `prisma db migrate` with migrations, `prisma db update` with `db update`, or `prisma db sign` if it only signs. Each brings the records up to date before its usual work. Then run the read again. |
82
+ | `MIGRATION.INSTALLED_SPACE_UNREACHABLE` | `db init`, `db update`, `db migrate`, `db sign`, `db verify` | The records Prisma keeps for itself were changed by a release this one cannot follow: `meta.reason` is `laterMajor` when a later major version of Prisma changed them, `unknownContract` otherwise. Use the release that last changed the database, or a newer one. Do not edit them by hand. |
83
+ | `CONTRACT.SIGNATURE_MISSING` | `db verify` (finding, exit 4), runtime startup (warning) | The DB has no signature yet. Run `prisma db init --db <url>` to baseline an empty database, `db update --db <url>` to apply the current contract directly, or `db sign --db <url>` if the schema already matches the contract. |
82
84
  | `MIGRATION.STATEMENT_INVALID` | `migration plan` / `db update` with `--rename` | The statement is malformed, mixes a model and a field, renames something to itself, swaps two names, or repeats a name. The error's next step is the statement to type instead; use it. |
83
85
  | `MIGRATION.STATEMENT_UNRESOLVED` | `migration plan` / `db update` with `--rename` | A name is not where a rename needs it. The error lists the names it found and says what to type: the statement the right way round, the order that works, or to leave out a rename that has already happened. |
84
86
  | `MIGRATION.CHANGE_POLICY_FORBIDS` | `db update`, `db sign`, `db migrate` | The database's change policy does not include what the command does (`meta.change` lists what it permits). When `db update` or `db sign` is refused, the database changes only through migrations: follow its advice, which says to apply the migrations on disk that already lead to the target with `db migrate`, or to 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`. Do not look for a way round the policy. |
@@ -92,7 +94,7 @@ Treat the rendered import lines as framework-managed on both targets:
92
94
  | Moving a database whose history does not need to be kept (local, development, staging, preview) to the contract | `db update` | Fast, no migration files. Works whether or not the database is shared. |
93
95
  | A change other developers or environments will receive | `migration plan` + `db migrate` | Replayable, reviewable, content-hashed. |
94
96
  | A database that changes only through migrations, such as production | `migration plan` + `db migrate` | It must run a reviewed, hashed migration. |
95
- | A deploy says there is no migration path, or `MIGRATION.MARKER_MISMATCH` | See *A database whose marker is not in the migration graph* | Never reset the database. |
97
+ | A deploy says there is no migration path, or `MIGRATION.SIGNATURE_NOT_IN_GRAPH` | See *A database whose contract signature is not in the migration graph* | Never reset the database. |
96
98
  | Adding a column that needs a backfill | `migration plan --backfill Model.field` (writes `placeholder`), edit `migration.ts`, self-emit, then `db migrate` | `db update` does not author data transforms; the formal path does. Without `--backfill`, existing rows get a temporary value. |
97
99
  | Changing a field's type so values may not survive | `migration plan --convert Model.field`, fill `using`, self-emit, `db migrate` | Or `--delete Model.field` to let the database cast; the cast may cut or round values (Postgres cuts a longer text to a shorter `varchar`), and a value it cannot cast fails the apply. |
98
100
  | Recovering from drift (DB diverged from contract) | `db sign` after manual fix, *or* `migration plan` if Prisma 8 can plan the fix | Depends on which side is right. See *Recover from drift* below. |
@@ -113,7 +115,21 @@ Every command here reaches the database through `db.connection` in `prisma.confi
113
115
 
114
116
  The `db` ref is a named pointer at `migrations/app/refs/db.json` — just `{ hash, invariants }`. It records which contract hash the project's dev database has been brought up to — the offline planner's stand-in for "where is my local DB?" without opening a connection at plan time. The contract it names resolves through the shared content-addressed store at `migrations/snapshots/<hex>/contract.json` by that hash, the same store every migration graph node resolves through.
115
117
 
116
- **What `db init` / `db update` / `db migrate` / `db sign` write.** When run against the project's default `--db` URL (no explicit `--db` flag), `db init` and `db update` implicitly advance the `db` ref: they write-if-absent the post-command contract IR into the snapshot store, then write the ref's pointer. Override the ref name with `--advance-ref <name>`. When you pass `--db <non-default-url>`, ref advancement is suppressed unless `--advance-ref` is explicit — reconciling a different database is not the same as checkpointing this project's dev state. `db migrate` follows the same rule after a successful apply, with one addition: it advances nothing when the CLI detects CI, so pipelines that read their URL through the config write no ref. 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`, and the run then reports `MIGRATION.REF_NOT_ADVANCED_IN_CI`. On a developer's machine, a variable in the shell, or in a `.env` file that `prisma.config.ts` loads (for example with `import 'dotenv/config'`), can turn advancement off; that notice says so, and a pipeline silences it with `--no-advance-ref`. A run that brings the database to the empty contract leaves `db` unchanged, because a ref cannot name it; when a `db` ref exists and the run passes neither `--db` nor `--no-advance-ref`, it warns with `MIGRATION.REF_NOT_ADVANCED_TO_EMPTY`, naming the hash `db` still holds (with either flag the ref is left unchanged and there is no warning); when that database is your development database, remove the stale ref with `migration ref delete db`. `--advance-ref <name>` advances that ref instead in every case except a run that ends at the empty contract, which it refuses before applying with `MIGRATION.REF_TARGET_EMPTY`, and `--no-advance-ref` advances none. A ref `db migrate` cannot write, for example on a read-only filesystem, is a warning (`MIGRATION.REF_NOT_WRITTEN`) and the command still exits 0, since the migrations have already applied; its next action is the command that writes it later: `migration ref set` when the snapshot store holds the contract for that hash, and otherwise the same `db migrate` with `--advance-ref <name>`, which applies nothing and writes both. `db sign` also advances the `db` ref after a successful signature, writing the signed contract into the snapshot store first; `--advance-ref <name>` overrides the name, and `--db` does **not** suppress it — sign never mutates the schema, and adoption is normally done against the real database via `--db`. The only opt-out is `--no-advance-ref`, which signs without writing any ref or snapshot — what a CI or deployment pipeline, or a dev checkout re-signing a production database, usually wants.
118
+ **What `db init` / `db update` / `db migrate` / `db sign` write.** After a successful run, `db init`, `db update` and `db migrate` write-if-absent the contract the database is now at into the snapshot store, then write a ref's pointer:
119
+
120
+ | Situation | Ref written |
121
+ | --- | --- |
122
+ | Connection from `prisma.config.ts` (no `--db`), CI not detected | `db` |
123
+ | Connection from the config, CI detected | None; the run reports `MIGRATION.REF_NOT_ADVANCED_IN_CI` |
124
+ | `--db <url>` | None: reconciling a different database is not checkpointing this project's dev state |
125
+ | `--advance-ref <name>` | `<name>`, also with `--db` and in CI, except for a `db migrate` that ends at the empty contract, which is refused before applying with `MIGRATION.REF_TARGET_EMPTY` |
126
+ | `--no-advance-ref` | None, and no notice |
127
+
128
+ - **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`. Pipelines that read their URL through the config therefore write no ref. On a developer's machine, a variable in the shell, or in a `.env` file that `prisma.config.ts` loads (for example with `import 'dotenv/config'`), can turn advancement off. When CI is the only reason, the run prints one line, `Ref db not advanced because CI was detected. Silence this warning with --no-advance-ref.`; a pipeline silences it with `--no-advance-ref`, and on a development machine you unset the variable or set `CI=false`, or run the command again with `--advance-ref db` (for `db update`, without its statements).
129
+ - **The empty contract.** A `db migrate` that brings the database to the empty contract leaves `db` unchanged, because a ref cannot name it. When a `db` ref exists and the run passes neither `--db` nor `--no-advance-ref`, it warns with `MIGRATION.REF_NOT_ADVANCED_TO_EMPTY`, naming the hash `db` still holds (with either flag the ref is left unchanged and there is no warning); when that database is your development database, remove the stale ref with `migration ref delete db`.
130
+ - **A ref that cannot be written**, for example on a read-only filesystem, is a warning (`MIGRATION.REF_NOT_WRITTEN`) and the command still exits 0, since the database has already changed. Its next action is the command the warning prints: `migration ref set` when the snapshot store holds the contract for that hash and a migration on disk ends at it, and 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, and which writes both.
131
+ - **Snapshots in CI.** In CI, `db init` and `db update` also store no snapshot of the contract they applied, so a pipeline that later runs `db update --rename` passes `--advance-ref <name>` on the earlier run.
132
+ - **`db sign`** also advances the `db` ref after a successful signature, writing the signed contract into the snapshot store first. `--advance-ref <name>` overrides the name, and `--db` does **not** suppress it — sign never mutates the schema, and adoption is normally done against the real database via `--db`. The only opt-out is `--no-advance-ref`, which signs without writing any ref or snapshot — what a CI or deployment pipeline, or a dev checkout re-signing a production database, usually wants.
117
133
 
118
134
  The on-disk layout is just the pointer:
119
135
 
@@ -144,15 +160,15 @@ pnpm prisma migration plan --name my_change
144
160
 
145
161
  If the `db` ref's pointer is itself missing and the hash isn't a graph node either (`MIGRATION.SNAPSHOT_MISSING`), create it with `migration ref set db <hash>` or advance it with `db update --advance-ref db`.
146
162
 
147
- **After `db migrate` with `--db`, with `--no-advance-ref` or in CI.** The live marker advances and the `db` ref does not. The `db` ref records where development plans start, so move it only for your development database, never for a deployment database. On the development database, run the same `db migrate` again with `--advance-ref db`, without `--no-advance-ref`: it applies nothing and moves the ref to the contract the database is at. If that run ended at the empty contract (`--to @empty`, or a rollback of the first migration with `--to <first-migration-dir>^`), no ref can name it and `--advance-ref db` is refused with `MIGRATION.REF_TARGET_EMPTY`; remove the stale ref with `migration ref delete db` instead.
163
+ **After `db init`, `db update` or `db migrate` with `--db`, with `--no-advance-ref` or in CI.** The live contract signature advances and the `db` ref does not. The `db` ref records where development plans start, so move it only for your development database, never for a deployment database. On the development database, run it again with `--advance-ref db`, without `--no-advance-ref` and without the statements of a `db update` (`--rename`, `--delete`, `--allow`), which would fail now that they are applied: it applies nothing if the contract has not changed since, and moves the ref to the contract the database is at. If that run ended at the empty contract (`--to @empty`, or a rollback of the first migration with `--to <first-migration-dir>^`), no ref can name it and `--advance-ref db` is refused with `MIGRATION.REF_TARGET_EMPTY`; remove the stale ref with `migration ref delete db` instead.
148
164
 
149
165
  **When to switch paths.** Use `db update` while the schema is in flux, on a database whose migration history does not need to be kept (a local, development, staging or preview database). Switch to `migration plan` + `db migrate` when the change needs a reviewable, replayable migration — typically before opening a PR, and always for a database that changes only through migrations, such as production. The `db` ref bridges the two: it captures dev iteration state on disk so the first formal plan knows where you left off.
150
166
 
151
167
  **Graph-node rule (plan time).** Any hash used as a `from` end — explicit `--from`, default `db` ref, or ref name — must already be a node in the on-disk migration graph once the graph is non-empty. The auto-baseline two-bundle emission is the one exception: it applies only on an **empty** graph with a non-null ref-resolved `from` and an available store entry. If the ref's pointer is missing and the hash isn't a graph node either, plan refuses with `MIGRATION.SNAPSHOT_MISSING` instead.
152
168
 
153
- **Apply-time complement.** `db migrate` reads the live marker before DDL. If the marker hash is not a graph node, the command refuses with `MIGRATION.MARKER_MISMATCH` — catching drift the offline planner cannot see. This is separate from `MIGRATION.MARKER_NOT_IN_HISTORY`, which fires later during the runner's graph walk when the marker is off the path being traversed. See `references/migration-review.md` for the full diagnostic catalog.
169
+ **Apply-time complement.** `db migrate` reads the live signature before DDL. If the signed contract hash is not a graph node, the command refuses with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` — catching drift the offline planner cannot see. This is separate from `MIGRATION.SIGNATURE_NOT_IN_GRAPH`, a warning `migration status` gives when the database's contract signature names no contract in the migration graph. See `references/migration-review.md` for the full diagnostic catalog.
154
170
 
155
- `db` is a **default ref name**, not a reserved one. The framework overwrites it on the next dev cycle; you may `migration ref set db <hash>` explicitly and accept that a subsequent `db update` replaces it when run against the default URL.
171
+ `db` is a **default ref name**, not a reserved one. The framework overwrites it on the next dev cycle; you may `migration ref set db <hash>` explicitly and accept that a subsequent `db init`, `db update` or `db migrate` replaces it when its connection comes from the config outside CI.
156
172
 
157
173
  Canonical detail: [Migration System § Contract resolution through the snapshot store](https://github.com/prisma/orm/blob/main/docs/architecture%20docs/subsystems/7.%20Migration%20System.md#contract-resolution-through-the-snapshot-store), [§ `migration plan`](https://github.com/prisma/orm/blob/main/docs/architecture%20docs/subsystems/7.%20Migration%20System.md#migration-plan), [§ Recovery affordances](https://github.com/prisma/orm/blob/main/docs/architecture%20docs/subsystems/7.%20Migration%20System.md#recovery-affordances), [ADR 218 — Refs with paired contract snapshots and universal graph-node invariant](https://github.com/prisma/orm/blob/main/docs/architecture%20docs/adrs/ADR%20218%20-%20Refs%20with%20paired%20contract%20snapshots%20and%20universal%20graph-node%20invariant.md) (TML-2629, its paired-snapshot part superseded — see the ADR's Status note), and [ADR 240 — Contract snapshots live in a content-addressed store](https://github.com/prisma/orm/blob/main/docs/architecture%20docs/adrs/ADR%20240%20-%20Contract%20snapshots%20live%20in%20a%20content-addressed%20store.md).
158
174
 
@@ -170,7 +186,7 @@ pnpm prisma db update --db $DATABASE_URL --dry-run
170
186
  pnpm prisma db update --db $DATABASE_URL
171
187
  ```
172
188
 
173
- `db update` already verifies schema and advances the marker on success — a follow-up `db verify` is redundant on the happy path. Use `db verify` only when you need a standalone diagnostic (see *Verify contract vs DB*).
189
+ `db update` already verifies schema and advances the contract signature on success — a follow-up `db verify` is redundant on the happy path. Use `db verify` only when you need a standalone diagnostic (see *Verify contract vs DB*).
174
190
 
175
191
  Inspect the JSON output to drive the next move:
176
192
 
@@ -178,11 +194,11 @@ Inspect the JSON output to drive the next move:
178
194
  pnpm prisma db update --db $DATABASE_URL --json
179
195
  ```
180
196
 
181
- The JSON contains `plan.operations[]` with each `operationClass`, plus (in apply mode) `execution.operationsExecuted` and the post-apply `marker.storageHash`. If the command was refused because nobody answered its questions, the error is `CLI.CONSENT_REQUIRED`, and its `meta.unanswered[]` lists each subject with the flags that answer it.
197
+ The JSON contains `plan.operations[]` with each `operationClass`, plus (in apply mode) `execution.operationsExecuted` and the post-apply `signature.storageHash`. If the command was refused because nobody answered its questions, the error is `CLI.CONSENT_REQUIRED`, and its `meta.unanswered[]` lists each subject with the flags that answer it.
182
198
 
183
199
  ## Workflow — `migration plan` + `db migrate` (formal path)
184
200
 
185
- The concept: `migration plan` writes a new migration package on disk. If the planner needed any data transforms, the package is *pending* — `migration.ts` holds `placeholder(...)` calls until you fill them in. `db migrate` runs every pending package in graph order — on Postgres inside one transaction for the whole run; on Mongo op by op with verify-gated marker advancement (see *Apply atomicity* above).
201
+ The concept: `migration plan` writes a new migration package on disk. If the planner needed any data transforms, the package is *pending* — `migration.ts` holds `placeholder(...)` calls until you fill them in. `db migrate` runs every pending package in graph order — on Postgres inside one transaction for the whole run; on Mongo op by op with verify-gated contract signature advancement (see *Apply atomicity* above).
186
202
 
187
203
  Plan a change:
188
204
 
@@ -208,7 +224,7 @@ pnpm prisma migration show migrations/app/20260515T1200_add_user_email
208
224
  `migration show` displays a single migration package. To see the ordered list of migrations that would run — across all contract spaces — use `db migrate --show`:
209
225
 
210
226
  ```bash
211
- # Online: reads the live DB marker as the origin.
227
+ # Online: reads the database's contract signature as the origin.
212
228
  pnpm prisma db migrate --show --db $DATABASE_URL
213
229
 
214
230
  # Offline: hypothetical path from any ref or hash.
@@ -389,7 +405,7 @@ Self-emit the same way: `node <package dir>/migration.ts`.
389
405
 
390
406
  **The rule.** A statement that inserts, updates or deletes rows, or selects rows to decide what to write, goes in a data transform (`dataTransform`), never in a `rawSql` step. `rawSql` is for DDL that no operation factory expresses. DDL includes statements that convert stored values as part of a schema change, such as `ALTER COLUMN … TYPE … USING` and SQLite's table recreation: use the operation factory (`this.alterColumnType`, `this.recreateTable`). A `rawSql` step you write carries a precheck and a postcheck that test the live schema, and the class *Operation classes* under *Key Concepts* describes.
391
407
 
392
- **Why.** Migrations form a graph (`references/migration-model.md`), and a migration is an edge. `db migrate` can run a migration on any database whose marker is at its `from` hash, however that database got there. Those databases share a schema but not their rows: on one the work is already done, on another it was never needed. A data transform stays correct on all of them for two reasons:
408
+ **Why.** Migrations form a graph (`references/migration-model.md`), and a migration is an edge. `db migrate` can run a migration on any database whose contract signature is at its `from` hash, however that database got there. Those databases share a schema but not their rows: on one the work is already done, on another it was never needed. A data transform stays correct on all of them for two reasons:
393
409
 
394
410
  - **`check` is the guard.** The runner skips the transform when `check` finds no rows (the work is done or was never needed), runs `run` otherwise, and fails the migration if `check` still finds rows afterwards. `check` is optional in the type, but a transform without it runs `run` on every database and can never refuse, so always write it.
395
411
  - **On Postgres, the queries are checked against a contract.** Self-emit checks each query plan against the contract passed to `this.dataTransform` and refuses a mismatch with `MIGRATION.DATA_TRANSFORM_CONTRACT_MISMATCH`.
@@ -413,7 +429,7 @@ For any other gap, offer to report it through `references/feedback.md`. Then let
413
429
 
414
430
  ### How a transform refuses bad data
415
431
 
416
- Write `check` to find the rows the transform must fix. If `run` leaves any of them behind, for example rows whose values have no valid mapping, the postcheck fails and the migration stops with `MIGRATION.POSTCHECK_FAILED`. On Postgres `meta.failedCheck.operationId` names the transform. On Mongo `meta.operationId` and `meta.name` do. On Postgres the whole run rolls back. On Mongo nothing is undone: the documents `run` already changed stay changed, and operations that ran earlier stay applied; only the marker does not advance. So on Mongo, write `run` so it is safe to run again, for example by filtering on the documents that still need the change. A SQLite transform has no `check`, so it cannot refuse this way. Do not add a raw step that raises an error. If the user wants the offending rows named, run a read-only query that selects them before migrating.
432
+ Write `check` to find the rows the transform must fix. If `run` leaves any of them behind, for example rows whose values have no valid mapping, the postcheck fails and the migration stops with `MIGRATION.POSTCHECK_FAILED`. On Postgres `meta.failedCheck.operationId` names the transform. On Mongo `meta.operationId` and `meta.name` do. On Postgres the whole run rolls back. On Mongo nothing is undone: the documents `run` already changed stay changed, and operations that ran earlier stay applied; only the contract signature does not advance. So on Mongo, write `run` so it is safe to run again, for example by filtering on the documents that still need the change. A SQLite transform has no `check`, so it cannot refuse this way. Do not add a raw step that raises an error. If the user wants the offending rows named, run a read-only query that selects them before migrating.
417
433
 
418
434
  ## Type changes and new required fields
419
435
 
@@ -424,7 +440,7 @@ Postgres and SQLite first; MongoDB below. `migration plan` cannot see rows, so t
424
440
  - **An optional field made required** is tightened directly. If rows hold NULL, the apply fails and counts them (`3 rows of "Item" hold NULL in "note", so it cannot become required.`); set the values and re-run, or plan with `--backfill`.
425
441
  - **On MongoDB** the same questions are asked about the documents. A validator change (`collMod(..., { ..., checkDocuments: true })`) checks the documents as its own precheck, after the plan's rewrites, and stops while one does not fit; operations that ran before it stay applied, and a re-run skips them. To apply a validator over documents that do not fit, set `checkDocuments: false` on its `collMod` in `migration.ts`. `--delete User.age` casts with `$convert` (`castField`), only where the result keeps what the values mean: `String` to `Boolean` or `DateTime` to `Int` offer `--convert` only; a cast that keeps every value, such as `Int` to `BigInt`, asks nothing. `--convert User.age` and `--backfill User.plan` write `dataTransform('User.age', { check, run })` with the filter written and the update as `placeholder('User.age:update')`, which you replace with an update document (`{ $set: { … } }`) or an aggregation pipeline (`[{ $set: { age: { $toInt: '$age' } } }]`); the `run` uses `rawUpdateMany(..., { bypassDocumentValidation: true })`, and a hand-written one must skip validation too. A new required field gets a temporary value (`fillField`), unless it has a unique index or its type has none, such as a date, or it is a variant's discriminator, since no temporary value names a variant. A discriminator renamed without `--rename` is refused, and the refusal gives the `--rename` to pass; a model's first discriminator is left to the document check. On a collection with documents, such a field stops the apply: a unique one at its index build, where the documents that lack it all hold `null`, and any other at the validator change's document check. Both errors name `--backfill`, so use it. A required field of a variant new to the collection, such as `Bug.severity` when `Task` gains its first discriminator, has no documents to backfill yet: set it in the update you write for `--backfill Task.type`, or keep it optional until a later change. A field that gains an enum or changes type inside a value object is not a statement: the plan warns, and you add a `dataTransform` before the validator change.
426
442
  - **Adopting a Prisma 6 MongoDB database.** A Prisma 6 database has no validator, and the first Prisma 8 plan adds one, which checks the documents first. If documents do not fit, the apply stops and names what the change touches, one `_id`, and the `mongosh` query that finds the rest. The error says why the document it shows does not fit, such as a field the new validator does not name. Fix those documents and run the command again; a plain update works, since the collection has no validator yet. Or, under `db migrate`, apply the validator over them: set `checkDocuments: false` on that `collMod` in `migration.ts`, run the file with `node`, and run `db migrate` again; they then fail their next update until they fit.
427
- - **Following failure advice under `db migrate`:** the migration is already written, so the error says to copy any code you wrote in its `migration.ts`, delete its directory, and run the printed `migration plan --from <hash> --name <name> …` command, which keeps the migration's name, together with the other statements you planned it with. Paths in the advice are relative to the directory the command ran from, and the commands it prints repeat the `--config` it was given, so each runs as printed from there.
443
+ - **Following failure advice under `db migrate`:** the migration is already written, so the error says to copy any code you wrote in its `migration.ts`, delete its directory, and run the printed `migration plan --from <hash> --name <name> …` command, which keeps the migration's name, together with the other statements you planned it with. Paths in the advice are relative to the directory the command ran from, and the commands it prints repeat the `--config` it was given, so each runs as printed from there. A printed command that connects to a database carries `--db <url>` when the run was given `--db`, or when `db.connection` in `prisma.config.ts` has no value (for example, its environment variable is not set): replace `<url>` with the database's URL.
428
444
 
429
445
  ## Workflow — Author a migration by hand
430
446
 
@@ -471,29 +487,29 @@ There is no built-in filter flag — pipe the JSON through `jq` (or your favouri
471
487
 
472
488
  ## Workflow — Verify contract vs DB (diagnostic)
473
489
 
474
- The concept: `db verify` is a **standalone diagnostic** — not a routine step after `db update` or `db migrate` on the happy path (those commands already verify and advance the marker when they succeed). Reach for `db verify` when you suspect drift or need to prove the DB matches the contract:
490
+ The concept: `db verify` is a **standalone diagnostic** — not a routine step after `db update` or `db migrate` on the happy path (those commands already verify and advance the contract signature when they succeed). Reach for `db verify` when you suspect drift or need to prove the DB matches the contract:
475
491
 
476
492
  - Following manual SQL or ad-hoc edits outside Prisma 8.
477
493
  - When restoring a database from backup.
478
494
  - If a `db migrate` fails or partially applies (especially on Mongo, where DDL is resumable rather than transaction-wrapped).
479
- - When `CONTRACT.MARKER_MISMATCH` / `CONTRACT.MARKER_MISSING` surfaces at runtime or from another command.
495
+ - When `CONTRACT.SIGNATURE_MISMATCH` / `CONTRACT.SIGNATURE_MISSING` surfaces at runtime or from another command.
480
496
 
481
497
  Modes:
482
498
 
483
- - Default — full verification (schema + marker).
484
- - `--marker-only` — skip schema verification, only check the marker.
485
- - `--schema-only` — skip marker verification, only check schema satisfies contract.
499
+ - Default — full verification (schema + signature).
500
+ - `--signature-only` — skip schema verification, only check the signature.
501
+ - `--schema-only` — skip signature verification, only check schema satisfies contract.
486
502
  - `--strict` adds: schema elements not present in the contract are an error (default is "DB may have extras").
487
503
 
488
504
  ```bash
489
505
  pnpm prisma db verify --db $DATABASE_URL
490
506
  ```
491
507
 
492
- `db verify` exits `0` when everything matches, `4` when it ran and found something, and `2` only when it could not run. Findings ride the completed envelope as `error` diagnostics: `CONTRACT.MARKER_MISMATCH`, `CONTRACT.MARKER_MISSING`, `CONTRACT.TARGET_MISMATCH`, `CONTRACT.SCHEMA_VERIFICATION_FAILED` (with `meta.schemaIssues` listing the schema diff issues).
508
+ `db verify` exits `0` when everything matches, `4` when it ran and found something, and `2` only when it could not run. Findings ride the completed envelope as `error` diagnostics: `CONTRACT.SIGNATURE_MISMATCH`, `CONTRACT.SIGNATURE_MISSING`, `CONTRACT.TARGET_MISMATCH`, `CONTRACT.SCHEMA_VERIFICATION_FAILED` (with `meta.schemaIssues` listing the schema diff issues).
493
509
 
494
510
  ## Policies: what a database says about how it may change
495
511
 
496
- Every database records two policies in its marker, and every command obeys them. Read them from the error that refuses you, or with `prisma migration status --to <ref> --db <url>`, which reports where the ref's declared policies differ from the database's.
512
+ Every database records two policies, and every command obeys them. On Postgres they are in `prisma.config`; on the other targets they are in the application space's contract signature. Read them from the error that refuses you, or with `prisma migration status --to <ref> --db <url>`, which reports where the ref's declared policies differ from the database's.
497
513
 
498
514
  **Change policy.** The strategies the database may be changed by:
499
515
 
@@ -502,7 +518,7 @@ Every database records two policies in its marker, and every command obeys them.
502
518
  | `migrate` | Walk the migration graph, running recorded migrations | `db migrate`, a Composer deploy |
503
519
  | `reconcile` | Plan and apply the difference to a contract, then sign | `db update`, `db sign` |
504
520
 
505
- A database that records nothing permits both. Production records `["migrate"]`, so `db update` and `db sign` refuse it with `MIGRATION.CHANGE_POLICY_FORBIDS`. The off-graph error (`MIGRATION.MARKER_MISMATCH`) reads the policy and gives only the recovery it permits.
521
+ A database that records nothing permits both. Production records `["migrate"]`, so `db update` and `db sign` refuse it with `MIGRATION.CHANGE_POLICY_FORBIDS`. The off-graph error (`MIGRATION.SIGNATURE_NOT_IN_GRAPH`) reads the policy and gives only the recovery it permits.
506
522
 
507
523
  **Data protection policy.** `dataLoss` and `accessWidening`, each `data-loss-forbidden` / `data-loss-with-consent` / `data-loss-permitted` (and the `access-widening-` forms). `with-consent` is the default and is today's behaviour: `db update` asks, and a migration carries the consent given when it was planned. Every command enforces them before it runs anything:
508
524
 
@@ -552,21 +568,21 @@ Write the field by hand, or with the `migration ref policy` commands, which chan
552
568
 
553
569
  No other command changes a ref's policies. Commands that rewrite a ref (`migration ref set`, `db update`, `db sign`, `db migrate`, and the `migration ref policy` commands) keep the `hash`, `invariants` and `policies` they do not change, and write `formatVersion` themselves. A ref file with any other field is refused with `MIGRATION.INVALID_REF_FILE`, and the file is left as it was: remove the field by hand.
554
570
 
555
- **Applying a declared policy.** `db migrate --to <ref>` and `db update --to <ref>` compare the ref's declarations with the database before running anything. If they differ, the command fails with `MIGRATION.POLICY_MISMATCH` and nothing runs. The database's policy changes only when the deploy is told it may: `prisma db migrate --to production --permit-policy-change --db <url>`. The run is checked against the ref's policies, runs, and writes them into the marker when it succeeds, so a failed run leaves the old policy. With nothing pending, the run writes only the policies. A pipeline that should apply reviewed policy changes passes the flag on every deploy; a cautious team leaves it out and applies policy changes by hand. The flag needs `--to <ref>`: with a hash, `@db`, `@empty` or no `--to`, the command fails with `CLI.INVALID_ARGUMENTS` before it connects. A ref that declares no policies is accepted and changes nothing, so a pipeline can pass the flag on every deploy.
571
+ **Applying a declared policy.** `db migrate --to <ref>` and `db update --to <ref>` compare the ref's declarations with the database before running anything. If they differ, the command fails with `MIGRATION.POLICY_MISMATCH` and nothing runs. The database's policy changes only when the deploy is told it may: `prisma db migrate --to production --permit-policy-change --db <url>`. The run is checked against the ref's policies, runs, and records them in the database (on Postgres in `prisma.config`, elsewhere in the signature) when it succeeds, so a failed run leaves the old policy. With nothing pending, the run writes only the policies. A pipeline that should apply reviewed policy changes passes the flag on every deploy; a cautious team leaves it out and applies policy changes by hand. The flag needs `--to <ref>`: with a hash, `@db`, `@empty` or no `--to`, the command fails with `CLI.INVALID_ARGUMENTS` before it connects. A ref that declares no policies is accepted and changes nothing, so a pipeline can pass the flag on every deploy.
556
572
 
557
573
  The flag is consent, like `--delete`. It is for the person who owns the database and reviewed the ref change. Never add it to make your own deploy pass, and never change a database's or a ref's policies, by hand or with `migration ref policy set` or `delete`, to get a deploy, a plan or `db update` past a refusal or a mismatch: the policy is there to stop exactly that.
558
574
 
559
- ## Workflow — Re-sign the marker
575
+ ## Workflow — Sign the database again
560
576
 
561
- The concept: `db sign` rewrites the marker to the current contract hash and moves the `db` ref to it (`--advance-ref <name>` overrides the ref name; `--db` does not suppress the ref write; `--no-advance-ref` skips it). Use after a manual repair where the DB is the source of truth and the marker is stale. `db sign` performs a schema-verify first and refuses to sign a DB whose schema disagrees with the contract — so a successful sign always means the schema matches and the marker is now correct.
577
+ The concept: `db sign` rewrites the signature to the current contract hash and moves the `db` ref to it (`--advance-ref <name>` overrides the ref name; `--db` does not suppress the ref write; `--no-advance-ref` skips it). Use after a manual repair where the DB is the source of truth and the signature is stale. `db sign` performs a schema-verify first and refuses to sign a DB whose schema disagrees with the contract — so a successful sign always means the schema matches and the signature is now correct.
562
578
 
563
579
  ```bash
564
580
  pnpm prisma db sign --db $DATABASE_URL
565
581
  ```
566
582
 
567
- ## Workflow — A database whose marker is not in the migration graph
583
+ ## Workflow — A database whose contract signature is not in the migration graph
568
584
 
569
- **The symptom.** `db migrate` or a deploy fails with `MIGRATION.MARKER_MISMATCH`: the database's marker names a contract that no migration in `migrations/` starts or ends at. (Composer releases older than this skill print it as `MIGRATION_PATH_NOT_FOUND`, "no authored path from the database's current schema".)
585
+ **The symptom.** `db migrate` or a deploy fails with `MIGRATION.SIGNATURE_NOT_IN_GRAPH`: the database's signature names a contract that no migration in `migrations/` starts or ends at. (Composer releases older than this skill print it as `MIGRATION_PATH_NOT_FOUND`, "no authored path from the database's current schema".)
570
586
 
571
587
  **The usual cause.** The database applied a migration that was later planned again or deleted. The common case is a branch deployed to a shared environment, then rebased: each new plan of its migration has a new target hash, and the version the database applied is gone. The error's `why` names the last contract in the graph the database applied (`meta.lastGraphHash`) and the applied migrations that are no longer on disk (`meta.missingMigrations`).
572
588
 
@@ -589,25 +605,25 @@ Reconcile it to the target with `db update`:
589
605
 
590
606
  ### When the database changes only through migrations (production)
591
607
 
592
- Author migrations that bring it back onto the graph, and deploy them. The marker's contract is `<marker hash>`; the last graph contract is `meta.lastGraphHash`. When the error has no `lastGraphHash`, the ledger shows no contract the database applied that is still in the graph, or could not be read: check with `prisma migration log`, and if no applied contract is in the graph, stop and ask a person.
608
+ Author migrations that bring it back onto the graph, and deploy them. The contract signature's contract is `<signed contract hash>`; the last graph contract is `meta.lastGraphHash`. When the error has no `lastGraphHash`, the ledger shows no contract the database applied that is still in the graph, or could not be read: check with `prisma migration log`, and if no applied contract is in the graph, stop and ask a person.
593
609
 
594
610
  `migration plan --to` accepts only contracts already in the graph, so the database's contract goes through the contract source:
595
611
 
596
- 1. Commit or copy aside any uncommitted edits to the contract source; step 4 restores it from `HEAD`. Then put the contract the database is at into the contract source. Prefer the contract source as it was when the deleted migration was planned: find the commit with `git log --all --oneline -- migrations/snapshots/<marker hash>` and check out the contract source file from it. If git no longer has it, infer it from the database into a separate file, `prisma contract infer --db $DATABASE_URL --output ./inferred.prisma` (without `--output` it overwrites the contract source), then copy that file over the contract source.
597
- 2. `prisma contract emit`, and check that the emitted storage hash is `<marker hash>`. If it is not, stop and ask a person.
612
+ 1. Commit or copy aside any uncommitted edits to the contract source; step 4 restores it from `HEAD`. Then put the contract the database is at into the contract source. Prefer the contract source as it was when the deleted migration was planned: find the commit with `git log --all --oneline -- migrations/snapshots/<signed contract hash>` and check out the contract source file from it. If git no longer has it, infer it from the database into a separate file, `prisma contract infer --db $DATABASE_URL --output ./inferred.prisma` (without `--output` it overwrites the contract source), then copy that file over the contract source.
613
+ 2. `prisma contract emit`, and check that the emitted storage hash is `<signed contract hash>`. If it is not, stop and ask a person.
598
614
  3. Plan a migration from the last graph contract to the database's contract: `prisma migration plan --from <lastGraphHash> --name rejoin_<database>`. Nothing will run it against this database; it only puts the database's contract in the graph. A fresh database could still run it, so copy the data transforms of every migration in `meta.missingMigrations` into it, in ledger order (`prisma migration log`), from the git commits that held them, and review them.
599
- 4. Restore the contract source (`git checkout HEAD -- <contract source>`; without `HEAD` git restores the version step 1 staged), run `prisma contract emit`, then plan from the database's contract to the target: `prisma migration plan --from <marker hash> --name <slug>`. A plan that loses data needs `--delete` or `--rename` (see *Answer the data-loss questions*). Review it like any migration, and add data transforms for any data the deleted migration's replacement would have moved.
615
+ 4. Restore the contract source (`git checkout HEAD -- <contract source>`; without `HEAD` git restores the version step 1 staged), run `prisma contract emit`, then plan from the database's contract to the target: `prisma migration plan --from <signed contract hash> --name <slug>`. A plan that loses data needs `--delete` or `--rename` (see *Answer the data-loss questions*). Review it like any migration, and add data transforms for any data the deleted migration's replacement would have moved.
600
616
  5. Check how a fresh database reaches the target: `prisma migration status --from @empty --to <target>` lists the migrations it would run. Path finding takes the shortest route, so if these two migrations make a shorter route from the last graph contract to the target than the main line, a new database would take it. When they do, ask a person how to proceed.
601
617
  6. Commit both migrations and deploy.
602
618
 
603
- Do not `db sign` the database to a contract you inferred: that rewrites its marker without a migration, and a database whose change policy permits only migrations refuses it.
619
+ Do not `db sign` the database to a contract you inferred: that rewrites its signature without a migration, and a database whose change policy permits only migrations refuses it.
604
620
 
605
621
  ## Workflow — Recover from drift
606
622
 
607
- The concept: drift means `db verify` reports the live DB schema doesn't match what the marker says it should be. Two valid moves, picked by which side is correct:
623
+ The concept: drift means `db verify` reports the live DB schema doesn't match what the contract signature says it should be. Two valid moves, picked by which side is correct:
608
624
 
609
625
  - **The contract is right; the DB is wrong** → run a migration. Either `db update`, on a database whose migration history does not need to be kept (a local, development, staging or preview database), or `migration plan` + `db migrate`, which every database accepts and a database that changes only through migrations, such as production requires.
610
- - **The DB is right; the contract or marker is wrong** → edit the contract to match the DB (see `references/contract.md`), emit, then `db sign` to refresh the marker. The sign also moves the `db` ref to the signed hash; when the migration graph is non-empty and that hash is not a graph node, the next default `migration plan` refuses with `MIGRATION.HASH_NOT_IN_GRAPH` (see *The forgot-the-flag pitfall* above for the recovery).
626
+ - **The DB is right; the contract or signature is wrong** → edit the contract to match the DB (see `references/contract.md`), emit, then `db sign` to refresh the signature. The sign also moves the `db` ref to the signed hash; when the migration graph is non-empty and that hash is not a graph node, the next default `migration plan` refuses with `MIGRATION.HASH_NOT_IN_GRAPH` (see *The forgot-the-flag pitfall* above for the recovery).
611
627
 
612
628
  The diagnostic that reveals which side is right:
613
629
 
@@ -620,7 +636,7 @@ Use `db verify` to confirm which side is wrong, then re-run it after either bran
620
636
 
621
637
  ## Workflow — Recover from a partially-applied migration
622
638
 
623
- The concept: on **Postgres**, the whole `db migrate` run is one transaction — a failure anywhere rolls back every migration the run had applied, and the marker stays where it was before the command. On **Mongo**, DDL is resumable with verify-gated marker advancement; diagnose with `db verify` / `db schema`, fix the failed package's `migration.ts`, self-emit, and re-run `db migrate`.
639
+ The concept: on **Postgres**, the whole `db migrate` run is one transaction — a failure anywhere rolls back every migration the run had applied, and the contract signature stays where it was before the command. On **Mongo**, DDL is resumable with verify-gated signature advancement; diagnose with `db verify` / `db schema`, fix the failed package's `migration.ts`, self-emit, and re-run `db migrate`.
624
640
 
625
641
  Failures that *can* leak partial state: Mongo DDL that partially applied before verify failed, and external side-effects (calls out to other systems from a `run` closure). On Postgres nothing runs outside the transaction — `rawSql(...)` steps are ordinary steps inside it and roll back with the rest.
626
642
 
@@ -702,8 +718,8 @@ In a terminal the command asks each question in turn; type `delete`, `allow`, or
702
718
  8. **Renaming a model or field without a statement.** The planner cannot tell a rename from a drop and a create, so without a statement it plans a destructive drop+add. State the rename on the command line: `migration plan --name <slug> --rename User:Person --rename Person.email:Person.emailAddress`, or the same `--rename` flags on `db update`. A field is named through its model as the new contract names it. The planner then renames the table or column and the constraints and indexes named after it; on MongoDB it renames the collection, and the field in every document that holds it (only in that variant's documents for a variant's field). On MongoDB a field is named by its name in the contract, as on SQL: `id @map("_id")` is `User.id`. A statement that keeps the stored name, such as `--rename User.name:User.title` where both are stored as `display_name`, plans nothing; one that changes it renames the field in the documents. A model or field whose name stays and whose `@@map` or `@map` changes needs no statement, on MongoDB as on SQL (see pitfall 16).
703
719
  9. **Planning with no `db` ref and no `--from` in a project that already has migrations.** The origin falls through to the empty database, which would make the plan a full-create migration; `migration plan` refuses with `MIGRATION.PLAN_ORIGIN_UNKNOWN` rather than writing it. Pick the exit that matches your intent — the error lists them, and `references/migration-model.md` § *The trap* explains which to choose.
704
720
  10. **Hand-authoring `migration.ts` from a blank file, or rewriting the rendered import line.** Migration files are framework-rendered — let `prisma migration plan` (or `migration new`) render the package, then edit only the holes the framework leaves for you, and, until [prisma/orm#30504](https://github.com/prisma/orm/issues/30504) is fixed, the first argument of `this.dataTransform` (see pitfall 7). On Postgres leave the rendered `@prisma/orm-postgres/migration` (or `@prisma/orm-sqlite/migration`) import path alone; on Mongo leave `@prisma/orm-mongo/target/migration` as rendered. Add symbols to the existing import line rather than introducing new import paths.
705
- 12. **Replaying migrations onto a database that is already ahead.** `db migrate` on a database with no marker runs every migration, skipping operations already applied. When the database is already past a migration (it has `x int8` where the migration adds `x int4`), the run stops at that migration's precheck with `MIGRATION.PRECHECK_FAILED`. Adopt such a database with `prisma db sign` (after `contract infer` if needed), not by replaying history.
706
- 13. **Running Prisma 7 `migrate` commands against Prisma 8.** Each one answers `CLI.V7_COMMAND` with its Prisma 8 command: `migrate dev` is `contract emit`, `migration status` (which prints the `migration plan` that takes the database to the new contract), running that `migration plan`, then `db migrate`; when migrations on disk already lead to the new contract, `migration status` prints no plan, so skip that step and run `db migrate`; `migrate deploy` is `db migrate`; `migrate reset` has no equivalent, because Prisma 8 has no reset: `db update` brings the database to the contract instead, asking before it loses data, but it keeps existing rows and runs no seed steps or data transforms (a database that changes only through migrations is moved with `db migrate`); `migrate status` is `migration status`; `migrate diff` is `db update --dry-run`, or `migration plan` to write a migration package; `migrate resolve` is `db sign <migration>`, which moves the database marker to that migration after checking its schema, but leaves `migration status` without an applied mark. While Prisma 7 still owns the migrations, install Prisma 7's CLI with `npm install --save-dev @prisma/prisma7@7` and run every one of them except `migrate diff`, whose replacement only reads, as `prisma7 migrate <command>` instead; `migrate resolve` runs as `prisma7 migrate resolve --applied <migration>`.
721
+ 12. **Replaying migrations onto a database that is already ahead.** `db migrate` on a database with no contract signature runs every migration, skipping operations already applied. When the database is already past a migration (it has `x int8` where the migration adds `x int4`), the run stops at that migration's precheck with `MIGRATION.PRECHECK_FAILED`. Adopt such a database with `prisma db sign` (after `contract infer` if needed), not by replaying history.
722
+ 13. **Running Prisma 7 `migrate` commands against Prisma 8.** Each one answers `CLI.V7_COMMAND` with its Prisma 8 command: `migrate dev` is `contract emit`, `migration status` (which prints the `migration plan` that takes the database to the new contract), running that `migration plan`, then `db migrate`; when migrations on disk already lead to the new contract, `migration status` prints no plan, so skip that step and run `db migrate`; `migrate deploy` is `db migrate`; `migrate reset` has no equivalent, because Prisma 8 has no reset: `db update` brings the database to the contract instead, asking before it loses data, but it keeps existing rows and runs no seed steps or data transforms (a database that changes only through migrations is moved with `db migrate`); `migrate status` is `migration status`; `migrate diff` is `db update --dry-run`, or `migration plan` to write a migration package; `migrate resolve` is `db sign <migration>`, which moves the database's contract signature to that migration after checking its schema, but leaves `migration status` without an applied mark. While Prisma 7 still owns the migrations, install Prisma 7's CLI with `npm install --save-dev @prisma/prisma7@7` and run every one of them except `migrate diff`, whose replacement only reads, as `prisma7 migrate <command>` instead; `migrate resolve` runs as `prisma7 migrate resolve --applied <migration>`.
707
723
  14. **Changing rows outside a data transform.** A `rawSql` step that inserts, updates or deletes rows, or a Postgres transform whose query comes from `db.raw.sql` or contains `fns.raw`. Write it in a `dataTransform` (with a `check` on Postgres and Mongo); on Postgres, build its queries with the SQL query builder. *Data changes go in a data transform* explains why. If the builder cannot express it, stop (see *When the SQL query builder cannot express the transform*).
708
724
  15. **A data transform without `check` (Postgres, Mongo).** It runs `run` on every database, including those where the work is already done, and can never refuse bad data. Always write `check`.
709
725
  16. **Passing a statement for a changed `@@map` or `@map`.** A model or field that keeps its name is the same model or field, so when only `@@map` or `@map` changes, `migration plan` and `db update` rename the table or column, and its constraints and indexes, with no question and no statement. This needs a snapshot of the contract the database is at, and a table whose control policy is `managed` in both contracts. Without a snapshot, the change is planned as a drop and a create and asked about, as before, except a table name whose only change is a capital first letter (`users` to `Users`): that is refused with `MIGRATION.TABLE_NAME_CASE_CHANGED`, whose message gives the steps to rename the table; for a table that is not `managed`, nothing is renamed, and the plan is what that control policy allows. `--rename User:User` is refused with `MIGRATION.STATEMENT_INVALID`, and a `--delete User` left in a script from earlier releases fails with `CLI.CONSENT_UNUSED`. To get an empty table under the new name instead, remove the model in one change and add it back in a second. A rename the planner cannot order is refused with `MIGRATION.PLANNING_FAILED`: two models or fields that swap tables or columns, a chain where one moves to a name another frees, a model that takes the table of a removed one, and a rename statement that moves something into the old name. The message gives two plans through a name nothing uses (`prisma_swap_<name>`), or, for a takeover, a first plan that removes the model or field holding the name; follow it. One swap is not refused by `migration plan`: when two tables or columns of the same shape swap names and nothing else changes, the storage does not change, so `migration plan` reports no change and writes nothing, and the rows are then read as the other model's; `db update` refuses it. Make such a swap through a name nothing uses in the same way. The table is renamed only when everything stored in it moves, so a variant that gains or loses a table of its own is still asked about, as a data migration. MySQL plans no renames, so there a changed `@@map` is still a drop and a create. MongoDB does the same with collections, document keys (in every place an embedded model is stored) and enum stored values. Its operations run one at a time with no transaction, so it also refuses enum values that shift along a chain, and `--rename` of a model whose collection another model shares; each message gives its route.
@@ -151,7 +151,7 @@ const posts = await db.orm.public.Post
151
151
  .all();
152
152
  ```
153
153
 
154
- The same argument reaches the callbacks inside an include refinement, a fragment and a relation filter (`some`, `every`, `none`), where the index's columns follow the alias the ORM gives the related table. A condition from `fns` combines with the ORM's `and`, `or` and `not`. The body of a fragment for any model (`db.orm.fragment(fields, body)`) gets `fns` but no indexes.
154
+ The same argument reaches the callbacks inside an include refinement, a fragment and a relation filter (`some`, `every`, `none`), where the index's columns follow the alias the ORM gives the related table. A condition from `fns` combines with the ORM's `and`, `or` and `not`. The body of a fragment for any model (`db.fragment(fields, body)`) gets `fns` but no indexes.
155
155
 
156
156
  In the SQL builder, a table's `indexes` holds the same references:
157
157
 
@@ -417,13 +417,13 @@ await deleteMatching(Post.byAuthor(userId)).toArray();
417
417
 
418
418
  A piece of a query used in several places is a function. Do not build a filter object and spread it into each query; write a function and pass it to `.where(...)`, `.orderBy(...)` or `.with(...)`. A **row fragment** is a function of the model accessor, and `.where(...)` and `.orderBy(...)` take it. A **query fragment** (a **fragment** for short) is a function from a collection to a collection, and `.with(...)` runs it. A **scope** is a fragment that only imposes conditions on the query, such as `createdSince` below, and is also run with `.with(...)`. When the condition is a function of one row and needs no declared fields, pass a row fragment to `.where(...)`. When the same condition should apply to every model that has some fields, write a scope: it declares the fields, checks them at run time, and returns the collection with the `Filtered` fact. `.with(...)` also runs what `.where(...)` cannot express, such as a shared `select` and `include`, an order, a limit or offset, or a variant.
419
419
 
420
- **The same filter on several models.** Define a scope with `db.orm.fragment(fields, body)`; the method is named `fragment` because it cannot know whether the body only filters. Declare each field the fragment needs with the same builder the schema uses, from the `field` and `type` that `@prisma/orm-postgres/contract-builder` exports, adding `.optional()` for a field that may be null. The body sees only those fields:
420
+ **The same filter on several models.** Define a scope with `db.fragment(fields, body)`, on the client and on `tx`; the method is named `fragment` because it cannot know whether the body only filters. Declare each field the fragment needs with the same builder the schema uses, from the `field` and `type` that `@prisma/orm-postgres/contract-builder` exports, adding `.optional()` for a field that may be null. The body sees only those fields:
421
421
 
422
422
  ```typescript
423
423
  import { field, type } from '@prisma/orm-postgres/contract-builder';
424
424
 
425
425
  const createdSince = (since: Temporal.Instant) =>
426
- db.orm.fragment({ createdAt: field.column(type.TimestamptzTemporal()) }, (rows) =>
426
+ db.fragment({ createdAt: field.column(type.TimestamptzTemporal()) }, (rows) =>
427
427
  rows.where((r) => r.createdAt.gte(since)),
428
428
  );
429
429
 
@@ -460,7 +460,7 @@ await db.orm.public.Post.where({ userId }).with(postSummary).limit(20).all();
460
460
  await db.orm.public.User.include('posts', (posts) => posts.with(postSummary)).all();
461
461
  ```
462
462
 
463
- The body receives the plain collection of the model, without a custom class's methods. Apply the fragment before `.select(...)` or `.variant(...)`: it is refused on a collection they narrowed. Its result is always typed as the plain collection, even when the body keeps the row, so a custom class's methods are gone after it, and a filter or order applied before it is not recorded, although an earlier `.where(...)` still runs. `update` and `delete` are refused after it unless the body itself calls `where`, and `cursor` unless the body calls `orderBy`. For a filter on one model, use a class method or `db.orm.fragment`. A fragment for one model refuses a collection of another model or namespace at run time with `ORM.ARGUMENT_INVALID`. Calling `.fragment(...)` on a collection with chained calls throws `ORM.ARGUMENT_INVALID`, because the fragment is built from the model alone; a filter, an order or an include before it, or a receiver typed by a type parameter such as `this` in a class method, is a compile error. Inside a class method, chain on `this` directly instead.
463
+ The body receives the plain collection of the model, without a custom class's methods. Apply the fragment before `.select(...)` or `.variant(...)`: it is refused on a collection they narrowed. Its result is always typed as the plain collection, even when the body keeps the row, so a custom class's methods are gone after it, and a filter or order applied before it is not recorded, although an earlier `.where(...)` still runs. `update` and `delete` are refused after it unless the body itself calls `where`, and `cursor` unless the body calls `orderBy`. For a filter on one model, use a class method or `db.fragment`. A fragment for one model refuses a collection of another model or namespace at run time with `ORM.ARGUMENT_INVALID`. Calling `.fragment(...)` on a collection with chained calls throws `ORM.ARGUMENT_INVALID`, because the fragment is built from the model alone; a filter, an order or an include before it, or a receiver typed by a type parameter such as `this` in a class method, is a compile error. Inside a class method, chain on `this` directly instead.
464
464
 
465
465
  **A field to order by, from a request.** Pass the request's string to `orderByField` with the fields the endpoint allows. Do not index the field proxy with the raw string:
466
466
 
@@ -586,7 +586,7 @@ const { affectedRows } = await db.execute(deletePlan);
586
586
 
587
587
  Each row must include every column that is not nullable and has no default; leaving one out is a type error that names the column. A value typed `T | undefined` for such a column is also an error, so narrow it first.
588
588
 
589
- `.returning(...)` requires the contract to require `sql.returning`. `postgres15` to `postgres18` list it.
589
+ `.returning(...)` requires the contract to require `db.returning`. `postgres15` to `postgres18` list it.
590
590
 
591
591
  ### Computed projections and joins
592
592
 
@@ -696,7 +696,7 @@ Cross-namespace relations (e.g. `public.Profile` → `auth.User`) follow the sam
696
696
  5. **Importing `and` / `or` / `not` from an internal package.** They are exported from `@prisma/orm-postgres/orm-client`; do not import them from a platform package such as `@prisma/orm-family-sql`.
697
697
  6. **Trying to `db.sql.from(tables.user)`.** That surface does not exist. The builder is table-shaped: `db.sql.<ns>.<tableName>.select(...)`. There is no `db.schema.tables` either.
698
698
  7. **Reading rows with `execute`.** Plans run through the client: `db.query(plan)` for rows, `db.execute(plan)` for a non-returning write (`{ affectedRows }`). Inside a transaction, `tx.query(plan)` / `tx.execute(plan)`. `execute` never yields rows — a `select` or `.returning(...)` plan passed to it gives you statistics, not data.
699
- 8. **Setting `capabilities: { lateral: true }` in `prisma.config.ts`.** The ORM config (`ormConfig({...})`) does not take `capabilities`. The contract lists every capability it requires in `requiredCapabilities`, beside the path in the contract entry or in `defineContract`, usually `[...postgres18, ...postgresDriver]`, which includes `sql.lateral`, `sql.jsonAgg` and `sql.returning`. To require one more, add its key to that list (see `references/contract.md`).
699
+ 8. **Setting `capabilities: { lateral: true }` in `prisma.config.ts`.** The ORM config (`ormConfig({...})`) does not take `capabilities`. The contract lists every capability it requires in `requiredCapabilities`, beside the path in the contract entry or in `defineContract`, usually `[...postgres18, ...postgresDriver]`, which includes `db.lateral`, `db.jsonAgg` and `db.returning`. To require one more, add its key to that list (see `references/contract.md`).
700
700
  9. **Confabulating a TypedSQL or `.stream()` surface.** Neither exists. Raw SQL does: the client's raw lane, ``db.raw.sql`…` ``. Reusable statements do: `db.prepare(...)` (see *Prepared statements* in [`queries.md`](./queries.md)). Streaming: `for await` over a read terminal or `runtime.query(plan)` — with the caveats in *Streaming* in [`queries.md`](./queries.md).
701
701
  10. **Mixing the ORM mutation return with `db.query(plan)` / `db.execute(plan)`.** ORM terminals issue the query themselves and return rows. `query` and `execute` are for plans.
702
702
  11. **Adding a `cursor()` to a relation, count, operation or `nulls` order.** It throws `ORM.ARGUMENT_INVALID`. Use `.limit(n).offset(n)`, or order by plain columns.
@@ -719,7 +719,7 @@ Cross-namespace relations (e.g. `public.Profile` → `auth.User`) follow the sam
719
719
  - [ ] Expressed ranges as chained `.where(...)` clauses or a single `and(...)` clause — did NOT reach for a non-existent `.between(...)` operator.
720
720
  - [ ] For cursor pagination, used `.orderBy(...).cursor({ field: lastValue }).limit(n).all()` — did NOT hand-write a `.where(p => p.field.lt(cursor))` workaround when the `.cursor()` API serves the same purpose.
721
721
  - [ ] For ORM combinators, imported `and` / `or` / `not` from `@prisma/orm-postgres/orm-client`.
722
- - [ ] Wrote a query piece shared between places as a function: a query fragment from `db.orm.fragment(fields, body)` or `collection.fragment(body)` run with `.with(...)`, a `where` callback typed with `CodecField`, or `orderByField` for an order parameter from a request.
722
+ - [ ] Wrote a query piece shared between places as a function: a query fragment from `db.fragment(fields, body)` or `collection.fragment(body)` run with `.with(...)`, a `where` callback typed with `CodecField`, or `orderByField` for an order parameter from a request.
723
723
  - [ ] Ran SQL-builder plans via `db.query(plan)` when they return rows and `db.execute(plan)` only for non-returning writes (`tx.query` / `tx.execute` inside a transaction). Passed `insert()` an array of rows.
724
724
  - [ ] Wrapped multi-statement work in `db.transaction(async (tx) => { ... })` where atomicity matters.
725
725
  - [ ] For top-N grouped aggregates at meaningful scale, dropped to `db.sql.<ns>.<table>` rather than JS-side sort + slice over `groupBy(...).aggregate(...)`.
@@ -7,7 +7,7 @@ This skill takes the user from zero (or near-zero) to a first working query agai
7
7
 
8
8
  - **First-touch orientation** — the user has arrived at a Prisma 8 project for the first time (a scaffold tool like `npx createprisma` dropped them in, they cloned a teammate's repo, or they ran `prisma orm init` themselves and now want to make their first move) and they're asking *"what can I do with Prisma 8?"*, *"where do I start?"*, or *"what's next?"*. The goal is to anchor them on the contract, get them connected to a database, round-trip one row, and let further commands surface organically.
9
9
  - **Greenfield** — new project, fresh database. User runs `prisma orm init` themselves. `init` seeds a starter contract with a sample model, so the path joins the first-touch orientation arc as soon as the database is initialised.
10
- - **Brownfield-DB** — existing database, no contract yet. Infer the contract from the database with `contract infer`, sign the marker with `db sign`, then write queries against one of the existing tables.
10
+ - **Brownfield-DB** — existing database, no contract yet. Infer the contract from the database with `contract infer`, sign the database with `db sign`, then write queries against one of the existing tables.
11
11
 
12
12
  This skill does **not** cover migrating from another ORM (Drizzle, Prisma 6/7, Sequelize, TypeORM, Kysely, Knex, raw drivers). Those are separately-installable skills.
13
13
 
@@ -37,7 +37,7 @@ This skill does **not** cover migrating from another ORM (Drizzle, Prisma 6/7, S
37
37
  - **Why the application lists them.** The application must have exactly one copy of each. Prisma does not accept a value that another copy of its own code created, and a package manager takes a peer dependency only from the application's own list. A monorepo whose applications are on different Prisma releases can still get two copies under npm workspaces and under Bun's hoisted linker; keep such applications on one release, or use pnpm, Yarn or Bun's isolated linker.
38
38
  - **Yarn Plug'n'Play.** `prisma orm init` does not support it. With Yarn, set `nodeLinker: node-modules` in `.yarnrc.yml` first.
39
39
  - **`db.ts`**: the runtime entry point. Lives next to the contract source at `src/prisma/db.ts`. Imports the contract artefacts and exports a `db` value the rest of the app uses.
40
- - **Marker**: a row in the `prisma_contract.marker` table (Postgres) or a document in the `_prisma_migrations` collection (Mongo) that records the contract hash per contract space. Lets Prisma 8 detect drift between contract and live DB. Created by `db init` (greenfield / first-touch orientation) or `db sign` (brownfield).
40
+ - **Contract signature**: a row in the `prisma.signatures` table (Postgres) or a document in the `_prisma_migrations` collection (Mongo) that records the contract hash per contract space. Lets Prisma 8 detect drift between contract and live DB. Created by `db init` (greenfield / first-touch orientation) or `db sign` (brownfield).
41
41
 
42
42
  ### Canonical on-disk layout
43
43
 
@@ -109,7 +109,7 @@ If that prints `[{ id: 1, email: 'alice@example.com' }]`, the project is wired e
109
109
  - The contract source exists at `src/prisma/contract.{prisma,ts}` (a starter model from `init`, or the inferred contract from `contract infer`, or whatever the bootstrap tool generated).
110
110
  - `src/prisma/db.ts` exists and instantiates the runtime with the emitted contract.
111
111
  - `DATABASE_URL` is set in `.env` (or wherever the runtime's config tells it to look).
112
- - The database has been initialised (`db init`) or marker-signed (`db sign`), so the marker row exists and the schema matches the contract.
112
+ - The database has been initialised (`db init`) or signed (`db sign`), so its contract signature exists and the schema matches the contract.
113
113
 
114
114
  The three workflows below each describe how their path gets the user to that state. After that, the arc above is the same.
115
115
 
@@ -135,7 +135,7 @@ Before saying anything specific to the user, read:
135
135
  - The contract source the config declares (canonically `src/prisma/contract.prisma` or `src/prisma/contract.ts`; a project scaffolded by an older init may have it at `prisma/contract.{prisma,ts}` instead — check the `contract` field of the config) — what starter models, if any, exist.
136
136
  - `src/prisma/db.ts` (next to the contract) — the runtime entry point.
137
137
  - `.env` / `.env.example` — is `DATABASE_URL` set, or only the example?
138
- - Optionally `pnpm prisma db verify` — does the live DB match the contract? (Exit `4` with findings means drift or no marker; `2` means it could not run.)
138
+ - Optionally `pnpm prisma db verify` — does the live DB match the contract? (Exit `4` with findings means drift or no contract signature; `2` means it could not run.)
139
139
 
140
140
  Then **say the contract path back to the user, with its role attached**. Something like: *"Your contract is at `src/prisma/contract.prisma`, and it currently declares a `User` model. The contract describes your app — every query type, migration, and runtime type the framework gives you flows from this file. Let's get your app connected to a database next."* The exact wording is up to the agent; what matters is that the user leaves the first response knowing *where the contract is* and *that it is the source of truth*.
141
141
 
@@ -144,8 +144,8 @@ Then **say the contract path back to the user, with its role attached**. Somethi
144
144
  The motivation is *"so your app can actually run against your database"*, not *"so the prerequisite checklist passes"*. The mechanics depend on what's already in place from Step 1:
145
145
 
146
146
  - **Everything already wired.** Go straight to writing and reading a row (see *Your first arc — connect, write, read* above). Adapt the snippet to whatever model the contract declares.
147
- - **`DATABASE_URL` not set.** Have the user set it in `.env` (not in `prisma.config.ts` — see Pitfall 5). Then `pnpm prisma db init` to apply the current contract to that database and write the marker row. Now the app can connect.
148
- - **Database is connectable but not yet aware of the contract** (marker row missing; `db verify` reports drift). Run `pnpm prisma db init`. (`db update` is the alternative for quick dev cycles — it's looser, doesn't write a migration history, and is what users reach for when they want to iterate on the schema fast. Mention it if the user asks how to make schema changes flow to the DB; don't pre-explain it.)
147
+ - **`DATABASE_URL` not set.** Have the user set it in `.env` (not in `prisma.config.ts` — see Pitfall 5). Then `pnpm prisma db init` to apply the current contract to that database and write the contract signature row. Now the app can connect.
148
+ - **Database is connectable but not yet aware of the contract** (signature row missing; `db verify` reports drift). Run `pnpm prisma db init`. (`db update` is the alternative for quick dev cycles — it's looser, doesn't write a migration history, and is what users reach for when they want to iterate on the schema fast. Mention it if the user asks how to make schema changes flow to the DB; don't pre-explain it.)
149
149
  - **Contract is empty** (bootstrap left the source blank). Add **one** model with **two** fields (e.g. `User { id, email }`), `pnpm prisma contract emit`, then `pnpm prisma db init`. Minimal — get the round-trip working, *then* extend.
150
150
 
151
151
  The user encounters `db init` (and optionally `db update`, `contract emit`) here because they're the commands their current move *requires*. They learn what those commands are by using them.
@@ -214,7 +214,7 @@ The flags `init` accepts (run `prisma orm init --help` for the source of truth):
214
214
  After init succeeds, the path converges on *Your first arc — connect, write, read* above. `init` has already seeded a starter contract with `User` and `Post` models (with a relation between them) and run `contract emit` once; the only remaining prerequisites are setting `DATABASE_URL` and initialising the database. Two commands:
215
215
 
216
216
  1. Set `DATABASE_URL` in `.env` (copy from `.env.example`).
217
- 2. Initialise the database: `pnpm prisma db init`. Creates tables, indexes, constraints, and writes the marker row — using the starter contract `init` generated.
217
+ 2. Initialise the database: `pnpm prisma db init`. Creates tables, indexes, constraints, and writes the contract signature row — using the starter contract `init` generated.
218
218
 
219
219
  Then run the snippet from *Your first arc* above against the `User` model. When the user is ready to extend the contract — add more models, change fields, add relations — chain to `references/contract.md`. For more queries, chain to `references/queries.md`.
220
220
 
@@ -222,7 +222,7 @@ Then run the snippet from *Your first arc* above against the `User` model. When
222
222
 
223
223
  ## Workflow — Brownfield-DB (existing database, no contract)
224
224
 
225
- The concept: against an existing database with no Prisma 8 contract, `contract infer` walks the live schema (tables, columns, indexes — including expression and partial ones — constraints, and RLS enablement + policies) and writes a PSL contract that describes it. Where authoring would generate a CHECK constraint the database does not carry (the element-non-null check on a list column), infer writes the list with nullable elements (`String?[]`), which derives no such check, so the contract declares exactly what the database enforces. The reverse gap is closed too: a hand-written CHECK constraint the database enforces that authoring would never have generated comes back as `@@check(expression: <reprint>, map: "<name>")`, so it is a declared object from the first pull instead of an invisible extra a later destructive plan could drop. That inferred check warns (`PN_EXACT_NAME_BODY_COMPARISON`) the next time you run `contract emit` — expected, not a defect: the warning fires on any `map:` body regardless of who wrote it, and the comparison stays sound because both sides are Postgres's own reprint. Columns come back as the convenience types with their defaults, and only the arguments that differ: `int2` as `Int(storage: int2)`, `numeric(10,2)` as `Decimal(precision: 10, scale: 2)`, `varchar(12)` as `String(storage: varchar, length: 12)`, `json` as `Json`, `jsonb` as `Json(storage: jsonb)`, `timestamptz(3)` as `DateTime` (a JavaScript `Date`), a `timestamptz` with no declared precision as `DateTime(precision: 6)`, `timestamp(3)` as `DateTime(storage: timestamp)`, `date` as `Date`, `time` as `Time` and `interval` as `Duration` (ISO strings). A `Date` holds milliseconds, so a timestamp column whose values use microseconds reads with them dropped: change such a field to `DateTime(as: temporal)` or `DateTime(as: string)` to keep them. The result is a *starting point*, not the final contract — review and clean it up, then `db sign` to record the current contract hash as the marker (instead of letting `db init` try to recreate the schema from scratch). By default `db sign` also sets the `db` ref and stores the contract snapshot, so the next `migration plan` chains from the adopted schema — even when the database is named with `--db`. `--advance-ref <name>` writes another ref instead and `--no-advance-ref` writes none; in either case the next plan needs `--from` or a `db` ref you set yourself.
225
+ The concept: against an existing database with no Prisma 8 contract, `contract infer` walks the live schema (tables, columns, indexes — including expression and partial ones — constraints, and RLS enablement + policies) and writes a PSL contract that describes it. Where authoring would generate a CHECK constraint the database does not carry (the element-non-null check on a list column), infer writes the list with nullable elements (`String?[]`), which derives no such check, so the contract declares exactly what the database enforces. The reverse gap is closed too: a hand-written CHECK constraint the database enforces that authoring would never have generated comes back as `@@check(expression: <reprint>, map: "<name>")`, so it is a declared object from the first pull instead of an invisible extra a later destructive plan could drop. That inferred check warns (`PN_EXACT_NAME_BODY_COMPARISON`) the next time you run `contract emit` — expected, not a defect: the warning fires on any `map:` body regardless of who wrote it, and the comparison stays sound because both sides are Postgres's own reprint. Columns come back as the convenience types with their defaults, and only the arguments that differ: `int2` as `Int(storage: int2)`, `numeric(10,2)` as `Decimal(precision: 10, scale: 2)`, `varchar(12)` as `String(storage: varchar, length: 12)`, `json` as `Json`, `jsonb` as `Json(storage: jsonb)`, `timestamptz(3)` as `DateTime` (a JavaScript `Date`), a `timestamptz` with no declared precision as `DateTime(precision: 6)`, `timestamp(3)` as `DateTime(storage: timestamp)`, `date` as `Date`, `time` as `Time` and `interval` as `Duration` (ISO strings). A `Date` holds milliseconds, so a timestamp column whose values use microseconds reads with them dropped: change such a field to `DateTime(as: temporal)` or `DateTime(as: string)` to keep them. The result is a *starting point*, not the final contract — review and clean it up, then `db sign` to record the current contract hash as the contract signature (instead of letting `db init` try to recreate the schema from scratch). By default `db sign` also sets the `db` ref and stores the contract snapshot, so the next `migration plan` chains from the adopted schema — even when the database is named with `--db`. `--advance-ref <name>` writes another ref instead and `--no-advance-ref` writes none; in either case the next plan needs `--from` or a `db` ref you set yourself.
226
226
 
227
227
  ```bash
228
228
  mkdir my-app && cd my-app
@@ -250,7 +250,7 @@ Then re-emit and sign:
250
250
 
251
251
  ```bash
252
252
  pnpm prisma contract emit
253
- pnpm prisma db sign # writes the marker and sets the db ref
253
+ pnpm prisma db sign # writes the contract signature and sets the db ref
254
254
  pnpm prisma db verify # exit 0 immediately after a pull; exit 4 with findings if the DB drifts later
255
255
  ```
256
256
 
@@ -304,7 +304,7 @@ This skill is intentionally body-only; `prisma orm init --help`, `contract infer
304
304
 
305
305
  - [ ] Confirmed which path applies (first-touch orientation / greenfield / brownfield) before proposing commands.
306
306
  - [ ] **First-touch orientation:** named the contract path back to the user and framed its role (*source of truth from which query types, migrations, and runtime types flow*) before proposing any commands.
307
- - [ ] **All paths:** brought the project to the *Your first arc* prerequisites (config, contract source, `db.ts`, `DATABASE_URL`, marker row) *before* writing application code.
307
+ - [ ] **All paths:** brought the project to the *Your first arc* prerequisites (config, contract source, `db.ts`, `DATABASE_URL`, contract signature row) *before* writing application code.
308
308
  - [ ] **All paths:** ran the first arc — one `create` + one `select` against the starter (or inferred) model — and got the round-trip working green.
309
309
  - [ ] **All paths:** did *not* edit the contract source as part of the first arc. Schema extension is the *next* move, not the first.
310
310
  - [ ] **All paths:** did *not* lead with a feature tour, capability inventory, or recital of CLI commands. Commands surfaced as the user's current move required them.
@@ -314,7 +314,7 @@ This skill is intentionally body-only; `prisma orm init --help`, `contract infer
314
314
  - [ ] **All paths (application projects):** the project ended up in the canonical `src/prisma/contract.{prisma,ts}` + `src/prisma/db.ts` + `migrations/app/` layout (what `init` scaffolds by default). An extension or aggregate-root package keeps its own `src/contract.{prisma,ts}` + `migrations/<timestamp>_<slug>/` layout — do not relocate it.
315
315
  - [ ] **Brownfield path:** ran `contract infer --db "$DATABASE_URL" --output src/prisma/contract.prisma`, reviewed the result, then `contract emit` + `db sign` (which by default also sets the `db` ref, so the next `migration plan` chains from the adopted schema; not with `--no-advance-ref` or `--advance-ref <name>`).
316
316
  - [ ] Set `DATABASE_URL` in `.env` and confirmed the value is reachable.
317
- - [ ] Initialised the DB (`db init` greenfield / first-touch orientation) or signed the marker (`db sign` brownfield — by default sets the `db` ref too, with or without `--db`).
317
+ - [ ] Initialised the DB (`db init` greenfield / first-touch orientation) or signed the database (`db sign` brownfield — by default sets the `db` ref too, with or without `--db`).
318
318
  - [ ] Did NOT hand-edit `contract.json` or `contract.d.ts`.
319
319
  - [ ] Did NOT set `DATABASE_URL` in `prisma.config.ts`.
320
320
  - [ ] Confirmed the user understands what the *next* skill is for their workflow (typically `references/queries.md` for more queries, then `references/contract.md` when they're ready to extend the schema).
@@ -309,7 +309,7 @@ Order matters: `beforeEncode` runs in registration order for every middleware be
309
309
 
310
310
  ## Workflow — Configure the connection
311
311
 
312
- The concept: the runtime takes one of three binding shapes — `url`, `pg` (a pre-constructed `pg.Pool` or `pg.Client`), or `binding` (an explicit kind tag). They're mutually exclusive. The `pg` form is for projects that already manage their own pool (e.g. a Lambda layer); `url` is the default. Pool tuning is `poolOptions.connectionTimeoutMillis` / `poolOptions.idleTimeoutMillis` / `poolOptions.max` (pool size, 10 by default) — *not* `driverOptions`. Behind a server-side connection pooler, `poolOptions: { max: 1 }` keeps one connection; queries then take turns on it, so a query waits while a transaction is open. Inside `db.transaction(async (tx) => …)` send every query through `tx`: with one connection, a query through `db` waits for the connection its own transaction holds and fails after `connectionTimeoutMillis`. Reads are buffered by default; setting `cursor` (`{ batchSize: 100 }`; `{}` or `{ batchSize: undefined }` for batches of 100; a `batchSize` that is not a positive integer fails the factory call) makes them stream through a server-side cursor, and there is no flag that turns cursors off (see `references/queries.md` § *Streaming*). `postgresServerless()` takes the same `cursor` option. Pass `log` (an object with `info`, `warn`, `error` and an optional `debug`; `console` works, and the type is `Log` from `@prisma/orm-postgres/family-runtime`) to receive what the runtime logs: the marker-verification warnings `CONTRACT.MARKER_MISSING` and `CONTRACT.MARKER_MISMATCH` from the client's first use of the database (its first query, connection or transaction), the warnings `lints()` emits for rules whose severity is `warn`, and the errors a middleware's `activityEnded` or `activityFinalized` hook throws, which the runtime logs and swallows. If `log` has a `debug` method, it also receives debug events, for example when a middleware intercepts a statement. `budgets()` violations reach `log` only in `mode: 'permissive'` (see *Lints and budgets middleware*). Without `log`, the runtime logs to the console: errors to `console.error` and warnings to `console.warn`, which in Node write to standard error, info events to `console.info`, and debug events nowhere. To silence it, pass a logger that does nothing: `log: { info() {}, warn() {}, error() {} }`. `postgresServerless()`, `sqlite()` and `supabase()` take the same option.
312
+ The concept: the runtime takes one of three binding shapes — `url`, `pg` (a pre-constructed `pg.Pool` or `pg.Client`), or `binding` (an explicit kind tag). They're mutually exclusive. The `pg` form is for projects that already manage their own pool (e.g. a Lambda layer); `url` is the default. Pool tuning is `poolOptions.connectionTimeoutMillis` / `poolOptions.idleTimeoutMillis` / `poolOptions.max` (pool size, 10 by default) — *not* `driverOptions`. Behind a server-side connection pooler, `poolOptions: { max: 1 }` keeps one connection; queries then take turns on it, so a query waits while a transaction is open. Inside `db.transaction(async (tx) => …)` send every query through `tx`: with one connection, a query through `db` waits for the connection its own transaction holds and fails after `connectionTimeoutMillis`. Reads are buffered by default; setting `cursor` (`{ batchSize: 100 }`; `{}` or `{ batchSize: undefined }` for batches of 100; a `batchSize` that is not a positive integer fails the factory call) makes them stream through a server-side cursor, and there is no flag that turns cursors off (see `references/queries.md` § *Streaming*). `postgresServerless()` takes the same `cursor` option. Pass `log` (an object with `info`, `warn`, `error` and an optional `debug`; `console` works, and the type is `Log` from `@prisma/orm-postgres/family-runtime`) to receive what the runtime logs: the contract-signature-verification warnings `CONTRACT.SIGNATURE_MISSING` and `CONTRACT.SIGNATURE_MISMATCH` from the client's first use of the database (its first query, connection or transaction), the warnings `lints()` emits for rules whose severity is `warn`, and the errors a middleware's `activityEnded` or `activityFinalized` hook throws, which the runtime logs and swallows. If `log` has a `debug` method, it also receives debug events, for example when a middleware intercepts a statement. `budgets()` violations reach `log` only in `mode: 'permissive'` (see *Lints and budgets middleware*). Without `log`, the runtime logs to the console: errors to `console.error` and warnings to `console.warn`, which in Node write to standard error, info events to `console.info`, and debug events nowhere. To silence it, pass a logger that does nothing: `log: { info() {}, warn() {}, error() {} }`. `postgresServerless()`, `sqlite()` and `supabase()` take the same option.
313
313
 
314
314
  ```typescript
315
315
  // Default — URL string, factory constructs the pool.
@@ -322,7 +322,7 @@ postgres({
322
322
  // max: 10, // optional: the most connections the pool opens
323
323
  },
324
324
  // cursor: { batchSize: 100 }, // optional — stream reads in batches instead of buffering
325
- // log: logger, // optional — where marker and lints() warnings go; the console by default
325
+ // log: logger, // optional — where contract signature and lints() warnings go; the console by default
326
326
  });
327
327
 
328
328
  // BYO pool — pass a pg.Pool you already created.
@@ -415,7 +415,7 @@ export const contract = contractFromJson<Contract>(contractJson);
415
415
  export const db = sqlite({ contract, path: 'app.db' });
416
416
  ```
417
417
 
418
- `path` is optional at construct time (you can call `db.connect({ path })` later); omit it and the database package still returns a client. The SQLite package exposes the same `db.sql`, `db.orm`, `db.raw`, `db.prepare(...)`, `db.transaction(...)`, `db.close()`, and `[Symbol.asyncDispose]` surfaces as Postgres, with one addressing difference: SQLite has no schemas, so `db.sql` and `db.orm` are the unbound namespace itself (`db.orm.User`, `db.sql.user`) instead of Postgres's `db.orm.public.User` / `db.sql.public.user`. `db.orm` and `tx.orm` also offer `fragment` beside the models, unless a model is named `fragment`: `const titled = db.orm.fragment({ title: { codecId: 'sqlite/text@1', nullable: false } }, (rows) => rows.where((r) => r.title.eq('Hello')));` then `await db.orm.Post.with(titled).all();`. The Mongo package shares `db.orm`, `db.close()`, and `[Symbol.asyncDispose]` but has no `db.sql` and no `db.transaction(...)`.
418
+ `path` is optional at construct time (you can call `db.connect({ path })` later); omit it and the database package still returns a client. The SQLite package exposes the same `db.sql`, `db.orm`, `db.raw`, `db.prepare(...)`, `db.transaction(...)`, `db.close()`, and `[Symbol.asyncDispose]` surfaces as Postgres, with one addressing difference: SQLite has no schemas, so `db.sql` and `db.orm` are the unbound namespace itself (`db.orm.User`, `db.sql.user`) instead of Postgres's `db.orm.public.User` / `db.sql.public.user`. `db.fragment` and `tx.fragment` make a fragment, and `db.orm` holds only the models: `const titled = db.fragment({ title: { codecId: 'sqlite/text@1', nullable: false } }, (rows) => rows.where((r) => r.title.eq('Hello')));` then `await db.orm.Post.with(titled).all();`. The Mongo package shares `db.orm`, `db.close()`, and `[Symbol.asyncDispose]` but has no `db.sql` and no `db.transaction(...)`.
419
419
 
420
420
  The `db.sql` / `db.orm` surfaces stay the same in name; the operators each surface exposes are target-shaped (Mongo has no `JOIN`).
421
421