@prisma/orm-mongo 8.0.0-rc.25-dev.28 → 8.0.0-rc.26

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 (210) hide show
  1. package/README.md +6 -5
  2. package/dist/bson.d.mts +2 -1
  3. package/dist/components__runtime.d.mts +3 -1
  4. package/dist/config.d.mts +2 -1
  5. package/dist/config.d.mts.map +1 -1
  6. package/dist/contract-builder.d.mts +11 -12
  7. package/dist/contract-builder.d.mts.map +1 -1
  8. package/dist/contract-types.d.mts +5 -3
  9. package/dist/contract__types.d.mts +3 -1
  10. package/dist/control.d.mts +2 -1
  11. package/dist/control.d.mts.map +1 -1
  12. package/dist/family-contract.d.mts +3 -1
  13. package/dist/family-runtime.d.mts +3 -1
  14. package/dist/family.d.mts +2 -1
  15. package/dist/family__control.d.mts +3 -1
  16. package/dist/init-quick-reference.md +1 -1
  17. package/dist/init.d.mts +2 -1
  18. package/dist/init.d.mts.map +1 -1
  19. package/dist/migration-tools__aggregate.d.mts +3 -1
  20. package/dist/migration-tools__hash.d.mts +3 -1
  21. package/dist/migration-tools__io.d.mts +3 -1
  22. package/dist/migration-tools__spaces.d.mts +3 -1
  23. package/dist/migration.d.mts +3 -1
  24. package/dist/{mongo-static-DVyRmsYP-yCJ9Q75S.mjs → mongo-static-DnxWWp96-D-vo6-SA.mjs} +4 -4
  25. package/dist/mongo-static-DnxWWp96-D-vo6-SA.mjs.map +1 -0
  26. package/dist/orm.d.mts +3 -1
  27. package/dist/query-ast__execution.d.mts +3 -1
  28. package/dist/query-builder.d.mts +3 -1
  29. package/dist/runtime.d.mts +3 -1
  30. package/dist/runtime.d.mts.map +1 -1
  31. package/dist/runtime.mjs +6 -6
  32. package/dist/runtime.mjs.map +1 -1
  33. package/dist/static.d.mts +2 -1
  34. package/dist/static.d.mts.map +1 -1
  35. package/dist/static.mjs +1 -1
  36. package/dist/target.d.mts +2 -1
  37. package/dist/target__codec-ids.d.mts +3 -1
  38. package/dist/target__codec-types.d.mts +3 -1
  39. package/dist/target__migration.d.mts +3 -1
  40. package/dist/target__runtime.d.mts +2 -1
  41. package/dist/value.d.mts +3 -1
  42. package/dist/vite-plugin-contract-emit.d.mts +3 -1
  43. package/package.json +12 -81
  44. package/skills/prisma-8/SKILL.md +8 -8
  45. package/skills/prisma-8/references/contract.md +8 -8
  46. package/skills/prisma-8/references/debug.md +11 -11
  47. package/skills/prisma-8/references/migration-model.md +17 -17
  48. package/skills/prisma-8/references/migration-review.md +21 -21
  49. package/skills/prisma-8/references/migrations.md +58 -42
  50. package/skills/prisma-8/references/queries-postgres.md +51 -8
  51. package/skills/prisma-8/references/queries.md +2 -2
  52. package/skills/prisma-8/references/quickstart.md +11 -11
  53. package/skills/prisma-8/references/runtime.md +3 -3
  54. package/skills/prisma-8/references/supabase.md +2 -2
  55. package/skills/prisma-8/references/upgrade-app.md +56 -23
  56. package/skills/prisma-8/references/upgrade-extension.md +35 -14
  57. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +2385 -0
  58. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +2048 -0
  59. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +667 -0
  60. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +667 -0
  61. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +1996 -0
  62. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +586 -0
  63. package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +1 -1
  64. package/skills/prisma-8/upgrading/extension/upgrades/0.8-to-0.9/instructions.md +1 -1
  65. package/skills/prisma-8/upgrading/extension/upgrades/0.9-to-0.10/instructions.md +1 -1
  66. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +2043 -0
  67. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +2048 -0
  68. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +667 -0
  69. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +667 -0
  70. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +1996 -0
  71. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +586 -0
  72. package/dist/adapter.d.mts +0 -1
  73. package/dist/adapter.mjs +0 -2
  74. package/dist/adapter__control.d.mts +0 -3
  75. package/dist/adapter__control.mjs +0 -3
  76. package/dist/adapter__runtime.d.mts +0 -3
  77. package/dist/adapter__runtime.mjs +0 -3
  78. package/dist/components.d.mts +0 -1
  79. package/dist/components.mjs +0 -2
  80. package/dist/components__authoring.d.mts +0 -1
  81. package/dist/components__authoring.mjs +0 -2
  82. package/dist/components__codec.d.mts +0 -1
  83. package/dist/components__codec.mjs +0 -2
  84. package/dist/components__components.d.mts +0 -1
  85. package/dist/components__components.mjs +0 -2
  86. package/dist/components__control.d.mts +0 -1
  87. package/dist/components__control.mjs +0 -2
  88. package/dist/components__emission.d.mts +0 -1
  89. package/dist/components__emission.mjs +0 -2
  90. package/dist/components__execution.d.mts +0 -1
  91. package/dist/components__execution.mjs +0 -2
  92. package/dist/components__ir.d.mts +0 -1
  93. package/dist/components__ir.mjs +0 -2
  94. package/dist/components__psl-ast.d.mts +0 -1
  95. package/dist/components__psl-ast.mjs +0 -2
  96. package/dist/components__utils.d.mts +0 -1
  97. package/dist/components__utils.mjs +0 -2
  98. package/dist/contract.d.mts +0 -1
  99. package/dist/contract.mjs +0 -2
  100. package/dist/contract__apply-specifier-default-control-policy.d.mts +0 -1
  101. package/dist/contract__apply-specifier-default-control-policy.mjs +0 -2
  102. package/dist/contract__contract-validation-error.d.mts +0 -1
  103. package/dist/contract__contract-validation-error.mjs +0 -2
  104. package/dist/contract__default-namespace.d.mts +0 -1
  105. package/dist/contract__default-namespace.mjs +0 -2
  106. package/dist/contract__enum-accessor.d.mts +0 -1
  107. package/dist/contract__enum-accessor.mjs +0 -2
  108. package/dist/contract__format-version.d.mts +0 -1
  109. package/dist/contract__format-version.mjs +0 -2
  110. package/dist/contract__hashing-utils.d.mts +0 -1
  111. package/dist/contract__hashing-utils.mjs +0 -2
  112. package/dist/contract__hashing.d.mts +0 -1
  113. package/dist/contract__hashing.mjs +0 -2
  114. package/dist/contract__internal__format-version.d.mts +0 -1
  115. package/dist/contract__internal__format-version.mjs +0 -2
  116. package/dist/contract__is-plain-record.d.mts +0 -1
  117. package/dist/contract__is-plain-record.mjs +0 -2
  118. package/dist/contract__resolve-domain-model.d.mts +0 -1
  119. package/dist/contract__resolve-domain-model.mjs +0 -2
  120. package/dist/contract__validate-domain.d.mts +0 -1
  121. package/dist/contract__validate-domain.mjs +0 -2
  122. package/dist/contract__validate-once.d.mts +0 -1
  123. package/dist/contract__validate-once.mjs +0 -2
  124. package/dist/contract__validate-storage.d.mts +0 -1
  125. package/dist/contract__validate-storage.mjs +0 -2
  126. package/dist/driver.d.mts +0 -1
  127. package/dist/driver.mjs +0 -2
  128. package/dist/driver__control.d.mts +0 -3
  129. package/dist/driver__control.mjs +0 -3
  130. package/dist/driver__runtime.d.mts +0 -3
  131. package/dist/driver__runtime.mjs +0 -3
  132. package/dist/family-contract__canonicalization-hooks.d.mts +0 -1
  133. package/dist/family-contract__canonicalization-hooks.mjs +0 -2
  134. package/dist/family-contract__data-type.d.mts +0 -1
  135. package/dist/family-contract__data-type.mjs +0 -2
  136. package/dist/family-contract__entity-kinds.d.mts +0 -1
  137. package/dist/family-contract__entity-kinds.mjs +0 -2
  138. package/dist/family__control-adapter.d.mts +0 -1
  139. package/dist/family__control-adapter.mjs +0 -2
  140. package/dist/family__ir.d.mts +0 -1
  141. package/dist/family__ir.mjs +0 -2
  142. package/dist/family__migration.d.mts +0 -1
  143. package/dist/family__migration.mjs +0 -2
  144. package/dist/family__pack.d.mts +0 -3
  145. package/dist/family__pack.mjs +0 -3
  146. package/dist/family__runtime.d.mts +0 -1
  147. package/dist/family__runtime.mjs +0 -2
  148. package/dist/family__schema-verify.d.mts +0 -1
  149. package/dist/family__schema-verify.mjs +0 -2
  150. package/dist/migration-tools__contract-snapshot-store.d.mts +0 -1
  151. package/dist/migration-tools__contract-snapshot-store.mjs +0 -2
  152. package/dist/mongo-static-DVyRmsYP-yCJ9Q75S.mjs.map +0 -1
  153. package/dist/query-ast.d.mts +0 -1
  154. package/dist/query-ast.mjs +0 -2
  155. package/dist/query-ast__control.d.mts +0 -1
  156. package/dist/query-ast__control.mjs +0 -2
  157. package/dist/query-builder__contract-free.d.mts +0 -1
  158. package/dist/query-builder__contract-free.mjs +0 -2
  159. package/dist/target__codecs.d.mts +0 -1
  160. package/dist/target__codecs.mjs +0 -2
  161. package/dist/target__control.d.mts +0 -1
  162. package/dist/target__control.mjs +0 -2
  163. package/dist/target__data-types.d.mts +0 -1
  164. package/dist/target__data-types.mjs +0 -2
  165. package/dist/target__pack.d.mts +0 -3
  166. package/dist/target__pack.mjs +0 -3
  167. package/dist/target__server-version.d.mts +0 -1
  168. package/dist/target__server-version.mjs +0 -2
  169. package/dist/utils.d.mts +0 -1
  170. package/dist/utils.mjs +0 -2
  171. package/dist/utils__abortable.d.mts +0 -1
  172. package/dist/utils__abortable.mjs +0 -2
  173. package/dist/utils__array-equal.d.mts +0 -1
  174. package/dist/utils__array-equal.mjs +0 -2
  175. package/dist/utils__assertions.d.mts +0 -1
  176. package/dist/utils__assertions.mjs +0 -2
  177. package/dist/utils__canonical-stringify.d.mts +0 -1
  178. package/dist/utils__canonical-stringify.mjs +0 -2
  179. package/dist/utils__casts.d.mts +0 -1
  180. package/dist/utils__casts.mjs +0 -2
  181. package/dist/utils__defined.d.mts +0 -1
  182. package/dist/utils__defined.mjs +0 -2
  183. package/dist/utils__guards.d.mts +0 -1
  184. package/dist/utils__guards.mjs +0 -2
  185. package/dist/utils__hash-content.d.mts +0 -1
  186. package/dist/utils__hash-content.mjs +0 -2
  187. package/dist/utils__internal-error.d.mts +0 -1
  188. package/dist/utils__internal-error.mjs +0 -2
  189. package/dist/utils__json.d.mts +0 -1
  190. package/dist/utils__json.mjs +0 -2
  191. package/dist/utils__promise.d.mts +0 -1
  192. package/dist/utils__promise.mjs +0 -2
  193. package/dist/utils__redact-db-url.d.mts +0 -1
  194. package/dist/utils__redact-db-url.mjs +0 -2
  195. package/dist/utils__result.d.mts +0 -1
  196. package/dist/utils__result.mjs +0 -2
  197. package/dist/utils__simplify-deep.d.mts +0 -1
  198. package/dist/utils__simplify-deep.mjs +0 -2
  199. package/dist/utils__structured-error.d.mts +0 -1
  200. package/dist/utils__structured-error.mjs +0 -2
  201. package/dist/utils__suppress-idle-connection-errors.d.mts +0 -1
  202. package/dist/utils__suppress-idle-connection-errors.mjs +0 -2
  203. package/dist/utils__text.d.mts +0 -1
  204. package/dist/utils__text.mjs +0 -2
  205. package/dist/utils__types.d.mts +0 -1
  206. package/dist/utils__types.mjs +0 -2
  207. package/dist/utils__upgrade-guides.d.mts +0 -1
  208. package/dist/utils__upgrade-guides.mjs +0 -2
  209. package/dist/value__mongodb-types.d.mts +0 -1
  210. package/dist/value__mongodb-types.mjs +0 -2
@@ -5,7 +5,7 @@
5
5
 
6
6
  This skill is about *reviewing* migrations, not authoring them. It covers the questions that come up at deploy time and when multiple developers are landing migrations concurrently.
7
7
 
8
- The skill teaches *the system's mental model* — what a ref is, what a marker is, what the migration graph is — and shows how to ask the system for its state. It does **not** prescribe rigid step-by-step procedures: most "review" questions are answered by understanding the model and querying the right thing. Rigid procedures are reserved for the rare case where there's literally one safe path.
8
+ The skill teaches *the system's mental model* — what a ref is, what a contract signature is, what the migration graph is — and shows how to ask the system for its state. It does **not** prescribe rigid step-by-step procedures: most "review" questions are answered by understanding the model and querying the right thing. Rigid procedures are reserved for the rare case where there's literally one safe path.
9
9
 
10
10
  ## When to Use
11
11
 
@@ -27,9 +27,9 @@ The skill teaches *the system's mental model* — what a ref is, what a marker i
27
27
 
28
28
  ### Origin
29
29
 
30
- The **origin** is the database's *current contract hash*. The database carries a row in Prisma 8's marker table that records *"this database is at hash X"*. When the CLI runs online (a `--db <url>` is provided, or `db.connection` is set in `prisma.config.ts`), Prisma 8 reads the marker and that hash is the origin. Offline (no DB connection), the origin is unknown — many commands degrade to listing the on-disk migrations and skip the per-edge applied/pending status.
30
+ The **origin** is the database's *current contract hash*. The database carries a row in Prisma 8's contract signature table that records *"this database is at hash X"*. When the CLI runs online (a `--db <url>` is provided, or `db.connection` is set in `prisma.config.ts`), Prisma 8 reads the signature and that hash is the origin. Offline (no DB connection), the origin is unknown — many commands degrade to listing the on-disk migrations and skip the per-edge applied/pending status.
31
31
 
32
- A live DB is therefore the authoritative source of origin. The "recorded marker" in any other artifact (refs, local cache, your assumptions) is a working copy that can drift; the live DB never does.
32
+ A live DB is therefore the authoritative source of origin. The "recorded signature" in any other artifact (refs, local cache, your assumptions) is a working copy that can drift; the live DB never does.
33
33
 
34
34
  ### Destination
35
35
 
@@ -42,9 +42,9 @@ The **destination** is the contract hash you want the database to be at. Two way
42
42
 
43
43
  ### The migration graph
44
44
 
45
- The on-disk migrations form a directed graph: **nodes are contract hashes; edges are migrations.** Each migration declares a `from` hash and a `to` hash. A migration applies only when the database's current marker matches its `from` hash; running it advances the marker to its `to` hash.
45
+ The on-disk migrations form a directed graph: **nodes are contract hashes; edges are migrations.** Each migration declares a `from` hash and a `to` hash. A migration applies only when the database's current contract signature matches its `from` hash; running it advances the signature to its `to` hash.
46
46
 
47
- The graph is a static, committed artifact. Several branch tips may coexist, rollback edges may form cycles, and no node is privileged — "where is my database" is answered by the marker and refs, never by the graph itself. `references/migration-model.md` carries the full model, including how `migration plan` chooses its origin.
47
+ The graph is a static, committed artifact. Several branch tips may coexist, rollback edges may form cycles, and no node is privileged — "where is my database" is answered by the signature and refs, never by the graph itself. `references/migration-model.md` carries the full model, including how `migration plan` chooses its origin.
48
48
 
49
49
  `migration status` queries the graph for the path from origin to destination and reports per-edge status:
50
50
 
@@ -54,12 +54,12 @@ The graph is a static, committed artifact. Several branch tips may coexist, roll
54
54
 
55
55
  ### Diagnostic codes
56
56
 
57
- `migration status` answers with a document (`--json`): `spaces[]`, each with `currentContract` (the marker hash, or `null` when the database has no marker for that space), `targetContract`, and `migrations[]` carrying the `applied` / `pending` / `null` status above; a `summary` line; and `diagnostics[]`. The ordinary states — up to date, N pending, no marker yet, marker on another branch, no path to the target — are read from `spaces[]` and the summary, not from diagnostic codes. The three diagnostics it can attach are all `warn`, and each carries a `message` and `hints` — the same hints the CLI prints under the summary line:
57
+ `migration status` answers with a document (`--json`): `spaces[]`, each with `currentContract` (the contract hash in the contract signature, or `null` when the database has no signature for that space), `targetContract`, and `migrations[]` carrying the `applied` / `pending` / `null` status above; a `summary` line; and `diagnostics[]`. The ordinary states — up to date, N pending, no signature yet, signature on another branch, no path to the target — are read from `spaces[]` and the summary, not from diagnostic codes. The three diagnostics it can attach are all `warn`, and each carries a `message` and `hints` — the same hints the CLI prints under the summary line:
58
58
 
59
59
  | Code | Meaning in the navigation model | Next move |
60
60
  |---|---|---|
61
- | `MIGRATION.MARKER_NOT_IN_HISTORY` | Online; marker hash is not a node in the graph. The database was changed outside the migration system. | Follow the finding's advice, which depends on the database's change policy. When the policy includes `reconcile`, decide which side is truth: `db sign` (accept DB as truth), `db update` (push contract to DB), `contract infer` (re-derive contract from DB), or `db verify` (inspect first). When it is `migrate` alone, `db sign` and `db update` are refused: author migrations that bring the database back onto the graph. When the policies cannot be read, have `meta.policies` corrected first. **Not** the same as `MIGRATION.MARKER_MISMATCH`, which `db migrate` (before any DDL) and `db migrate --show` raise as an error when the marker hash is not a graph node. |
62
- | `MIGRATION.MISSING_INVARIANTS` | Marker reached the destination structurally but lacks invariants the target ref declares. | `db migrate --to <name> --db $URL` to take a path that covers them. |
61
+ | `MIGRATION.SIGNATURE_NOT_IN_GRAPH` | Online; signed contract hash is not a node in the graph. The database was changed outside the migration system. | Follow the finding's advice, which depends on the database's change policy. When the policy includes `reconcile`, decide which side is truth: `db sign` (accept DB as truth), `db update` (push contract to DB), `contract infer` (re-derive contract from DB), or `db verify` (inspect first). When it is `migrate` alone, `db sign` and `db update` are refused: author migrations that bring the database back onto the graph. When the policies cannot be read, have them corrected first: on Postgres the `policies` column of `prisma.config`, elsewhere `meta.policies` in the application space's signature. **Not** the same as `MIGRATION.SIGNATURE_NOT_IN_GRAPH`, which `db migrate` (before any DDL) and `db migrate --show` raise as an error when the signed contract hash is not a graph node. |
62
+ | `MIGRATION.MISSING_INVARIANTS` | Signature reached the destination structurally but lacks invariants the target ref declares. | `db migrate --to <name> --db $URL` to take a path that covers them. |
63
63
  | `CONTRACT.UNREADABLE` | `contract.json` couldn't be read. | `contract emit` to regenerate it. |
64
64
 
65
65
  Conditions that make the run *refuse* instead (exit `2`) arrive as ordinary errors: `MIGRATION.NO_INVARIANT_PATH` (no path covers the missing invariants), `MIGRATION.UNKNOWN_INVARIANT` (the ref names an invariant no edge provides), and the ref-resolution errors for a bad `--to` / `--from`.
@@ -81,14 +81,14 @@ These codes surface on `migration plan`, `migration ref set`, and `db migrate`
81
81
  |---|---|---|---|
82
82
  | `MIGRATION.HASH_NOT_IN_GRAPH` | `migration plan` (non-empty graph) or `migration ref set` | Resolved hash is not a node in the on-disk migration graph — typical when the default `db` ref points past the graph tip after `db update` cycles. | `migration plan --from <reachable-ref>` (e.g. `--from production`); or realign the ref with `migration ref set db <graph-node-hash>`. |
83
83
  | `MIGRATION.SNAPSHOT_MISSING` | `migration plan` | A named ref has no pointer file (`<name>.json`), and the hash being resolved isn't a node in the migration graph either. | `migration ref set <name> <hash>` to create the ref, `db update --advance-ref <name>` to advance it, or pass a hash that is a graph node. |
84
- | `MIGRATION.MARKER_MISMATCH` | `db migrate` (pre-DDL, before the runner), `db migrate --show` | Live DB marker hash is not a graph node. Usually a migration the database applied was planned again or deleted. | Follow the error's next actions, and `references/migrations.md` § *A database whose marker is not in the migration graph*. Never reset the database. |
85
- | `MIGRATION.PATH_UNREACHABLE` | `db migrate` (path resolution) | No migration path from the current marker to the resolved target in the on-disk graph. | Read the improved `fix` payload — it names `fromHash` / `targetHash` and prints the `migration plan` and `db migrate` commands to run, with `--to <target>` unless the target is the emitted contract. On an empty database the plan starts from where the migration history ends. When the space named is an extension's, it prints no plan command: install a version of the extension whose migrations start from the contract the database is at; run `migration list` to inspect the graph. |
84
+ | `MIGRATION.SIGNATURE_NOT_IN_GRAPH` | `db migrate` (pre-DDL, before the runner), `db migrate --show` | Live contract hash the database is signed with is not a graph node. Usually a migration the database applied was planned again or deleted. | Follow the error's next actions, and `references/migrations.md` § *A database whose contract signature is not in the migration graph*. Never reset the database. |
85
+ | `MIGRATION.PATH_UNREACHABLE` | `db migrate` (path resolution) | No migration path from the current signature to the resolved target in the on-disk graph. | Read the improved `fix` payload — it names `fromHash` / `targetHash` and prints the `migration plan` and `db migrate` commands to run, with `--to <target>` unless the target is the emitted contract. On an empty database the plan starts from where the migration history ends. When the space named is an extension's, it prints no plan command: install a version of the extension whose migrations start from the contract the database is at; run `migration list` to inspect the graph. |
86
86
 
87
87
  ## Workflow — *"What's about to run on deploy?"*
88
88
 
89
89
  The user asks: *"I'm about to merge this PR. What migrations are going to run when I deploy to staging?"*
90
90
 
91
- This is the navigation question: **origin** = staging's live marker; **destination** = the ref `staging` (or the contract head if you haven't set one). Ask the system:
91
+ This is the navigation question: **origin** = staging's live contract signature; **destination** = the ref `staging` (or the contract head if you haven't set one). Ask the system:
92
92
 
93
93
  ```bash
94
94
  pnpm prisma migration status --to staging --db "$STAGING_DATABASE_URL"
@@ -96,12 +96,12 @@ pnpm prisma migration status --to staging --db "$STAGING_DATABASE_URL"
96
96
 
97
97
  The command:
98
98
 
99
- 1. Reads the staging DB's marker (the origin).
99
+ 1. Reads the staging DB's signature (the origin).
100
100
  2. Resolves `staging` to a contract hash (the destination).
101
101
  3. Renders the path between them as an ordered list of migrations, with per-edge `applied` / `pending` / `null` status, and an explicit summary line of the form *"N migration(s) behind ref 'staging'"*.
102
102
  4. Prints a header that names the config, migrations directory, the active ref, and the database connection (masked) — so the framing is visible in the output.
103
103
 
104
- If you omit `--db`, the command runs offline: it lists the migrations on disk but cannot tell you what's applied, because it has no origin. That's fine for *"what's on this branch?"*; it's not fine for *"what's about to run on staging?"* — for that you need staging's live marker.
104
+ If you omit `--db`, the command runs offline: it lists the migrations on disk but cannot tell you what's applied, because it has no origin. That's fine for *"what's on this branch?"*; it's not fine for *"what's about to run on staging?"* — for that you need staging's live signature.
105
105
 
106
106
  If you omit `--to`, the destination defaults to the contract head — which answers *"is this branch's contract reachable from the database, and how?"*, not *"what runs on deploy"*. Pass the ref explicitly when the question is about a specific environment.
107
107
 
@@ -109,7 +109,7 @@ If you omit `--to`, the destination defaults to the contract head — which answ
109
109
 
110
110
  ## Workflow — *"What state is each environment at?"*
111
111
 
112
- Just `migration status --db $URL` for each environment's DB. The marker (origin) comes back from the DB itself; the summary line tells you whether the environment is at the contract head, at a named ref, ahead of head, or on a divergent branch.
112
+ Just `migration status --db $URL` for each environment's DB. The contract signature (origin) comes back from the DB itself; the summary line tells you whether the environment is at the contract head, at a named ref, ahead of head, or on a divergent branch.
113
113
 
114
114
  ## Concept — concurrent migrations on the same branch point
115
115
 
@@ -140,7 +140,7 @@ pnpm prisma migration ref delete production
140
140
 
141
141
  `migration ref set` writes a file at `migrations/app/refs/<name>.json` carrying the hash and any required invariants. Refs are commit-friendly artifacts — keep them in git; the team agrees on what `production` points at the same way they agree on what `main` is. The hash being set must be the `to` of an on-disk migration, or the command refuses — see `references/migration-model.md` for the refusal codes.
142
142
 
143
- Two ref roles, one mechanism: environment refs like `production` are the contract CD will migrate that environment to (a forward promise), while the `db` ref is a checkpoint of where the project's dev database was last brought to — written by `db init` / `db update` on the default URL and by `db sign` by default (`--advance-ref <name>` targets another ref, `--no-advance-ref` skips the write), consumed by `migration plan` as its default origin. `references/migration-model.md` covers the `db` ref, advancement rules, and plan-origin resolution.
143
+ Two ref roles, one mechanism: environment refs like `production` are the contract CD will migrate that environment to (a forward promise), while the `db` ref is a checkpoint of where the project's dev database was last brought to — written by `db init`, `db update` and `db migrate` when the connection comes from the config outside CI, and by `db sign` by default (`--advance-ref <name>` targets another ref, `--no-advance-ref` skips the write), consumed by `migration plan` as its default origin. `references/migration-model.md` covers the `db` ref, advancement rules, and plan-origin resolution.
144
144
 
145
145
  ## Workflow — apply a migration against an environment
146
146
 
@@ -148,7 +148,7 @@ Two ref roles, one mechanism: environment refs like `production` are the contrac
148
148
  pnpm prisma db migrate --to production --db "$PRODUCTION_DATABASE_URL"
149
149
  ```
150
150
 
151
- The destination is the ref's hash; the origin is the production DB's live marker. The command computes the path between them and applies each pending migration in order, advancing the marker.
151
+ The destination is the ref's hash; the origin is the production DB's live contract signature. The command computes the path between them and applies each pending migration in order, advancing the signature.
152
152
 
153
153
  `--db` is the environment selection knob. `--to` is the destination-hash knob. They're independent.
154
154
 
@@ -158,8 +158,8 @@ CI reports: *"the recorded ref `production` is at hash X; the live DB is at hash
158
158
 
159
159
  The mismatch is a fact about *two pieces of state that disagree*. The investigation is the same regardless of which piece is wrong:
160
160
 
161
- - **DB ahead of the ref.** Someone applied a migration outside CI without updating the ref in git. Re-record the ref with `prisma migration ref set <ref-name> <db-marker-hash>` (commit + push); then audit how the out-of-band apply happened.
162
- - **DB behind the ref.** A previous deploy was rolled back, or the DB was restored from an older backup. Either re-apply forward with `prisma db migrate --to <ref-name> --db $URL`, or re-route the ref backward to match what's actually deployed with `prisma migration ref set <ref-name> <db-marker-hash>`. The choice is the user's — name both options.
161
+ - **DB ahead of the ref.** Someone applied a migration outside CI without updating the ref in git. Re-record the ref with `prisma migration ref set <ref-name> <db-signature-hash>` (commit + push); then audit how the out-of-band apply happened.
162
+ - **DB behind the ref.** A previous deploy was rolled back, or the DB was restored from an older backup. Either re-apply forward with `prisma db migrate --to <ref-name> --db $URL`, or re-route the ref backward to match what's actually deployed with `prisma migration ref set <ref-name> <db-signature-hash>`. The choice is the user's — name both options.
163
163
  - **DB on a different branch.** An out-of-band schema change (manual SQL, ad-hoc migration) wrote something the migration graph doesn't model. Run `prisma db verify` to inspect the drift, then either `prisma contract infer` to re-derive the contract from the database, or edit the contract and run `prisma migration plan` so the database is the eventual destination.
164
164
 
165
165
  `migration ref set` to silently align the ref with whatever the DB happens to be at is almost never the right move. It papers over drift that you'll pay for later.
@@ -173,9 +173,9 @@ The whole job is one command:
173
173
  run: pnpm prisma db migrate --to staging --db "$STAGING_DATABASE_URL"
174
174
  ```
175
175
 
176
- `db migrate` is safe to run unattended, by design. Before any operation runs it reads the live marker and refuses with `MIGRATION.MARKER_MISMATCH` if that hash is not a node in the on-disk graph, which is what a database changed outside the migration system looks like. Each operation then evaluates its own `precheck[]` and stops if the database is not in the state the operation expects. A successful run writes the destination hash as the new marker. Nothing runs before `db migrate` in the job.
176
+ `db migrate` is safe to run unattended, by design. Before any operation runs it reads the live contract signature and refuses with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` if that hash is not a node in the on-disk graph, which is what a database changed outside the migration system looks like. Each operation then evaluates its own `precheck[]` and stops if the database is not in the state the operation expects. A successful run writes the destination hash as the new signature. Nothing runs before `db migrate` in the job.
177
177
 
178
- `migration status --to staging --db $URL` is what a human or agent runs to answer *"what will run on deploy?"* before merging: it reports the path from the live marker to the ref without changing anything. `db migrate --show --db $URL` gives the same path as an ordered preview; `migration log --db $URL` gives the applied history after a deploy.
178
+ `migration status --to staging --db $URL` is what a human or agent runs to answer *"what will run on deploy?"* before merging: it reports the path from the live signature to the ref without changing anything. `db migrate --show --db $URL` gives the same path as an ordered preview; `migration log --db $URL` gives the applied history after a deploy.
179
179
 
180
180
  `db migrate` is interactive-free and asks nothing — the questions about data loss are asked by `migration plan` when it writes the package, and by `db update` (see the `references/migrations.md` skill). Whatever the planner put in the migration graph is what `db migrate` runs; review happens at `migration plan` and at `migration status` time, before the apply step.
181
181
 
@@ -198,7 +198,7 @@ This skill is intentionally body-only; the underlying CLI reference (`prisma mig
198
198
 
199
199
  ## Checklist
200
200
 
201
- - [ ] Named both the **origin** (live DB marker) and the **destination** (ref or contract head) for the question the user asked.
201
+ - [ ] Named both the **origin** (live contract signature) and the **destination** (ref or contract head) for the question the user asked.
202
202
  - [ ] Passed `--db $URL` whenever the question involves a specific environment.
203
203
  - [ ] Passed `--to <name>` whenever the question is about deploying *to* a named environment, not just *from* the current branch's head.
204
204
  - [ ] Read the `migration status` header (it names config, ref, database) and the summary line (it names the origin/destination distance) before reading the per-edge list.
@@ -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`; **SQLite:** 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` and on SQLite 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`, on SQLite 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.