@prisma/orm-mongo 8.0.0-rc.24-dev.43 → 8.0.0-rc.25

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.
@@ -0,0 +1,1488 @@
1
+ ---
2
+ from: "8.0.0-rc.24"
3
+ to: "8.0.0-rc.25"
4
+ changes:
5
+ - id: postgres-lc-monetary-not-set
6
+ summary: |
7
+ The PostgreSQL driver no longer sets `lc_monetary=C` on its connections, so a pooled Prisma Postgres URL connects. An application with `money` columns (`Money` in PSL, `@db.Money` in a Prisma 7 schema) now needs the database to print `money` in the `C` form itself. Run `SHOW lc_monetary` as the application's role. `C`, `POSIX` and `en_US`, with or without an encoding suffix such as `C.UTF-8`, and Prisma Postgres need no action. Under any other locale a `money` read fails with `RUNTIME.LC_MONETARY_NOT_C`: run `ALTER ROLE <role> SET lc_monetary = 'C'` before deploying the upgrade. `ALTER DATABASE <database> SET lc_monetary = 'C'` also works, but changes `money` for every other client of the database. Raw SQL that selects `money` as text now prints in the database's own locale.
8
+ detection:
9
+ glob: "**/*.{prisma,ts,mts,cts,sql,json}"
10
+ matches:
11
+ - '(?<![\w$])Money(?![\w$])'
12
+ - 'pg/money@1'
13
+ - '::\s*(?:money|MONEY)(?![\w$])'
14
+ - id: pg-is-a-peer-dependency
15
+ summary: |
16
+ `pg` (`^8.22.0`) and `@types/pg` (`^8.20.0`) are now required peer dependencies of `@prisma/orm-postgres`, `@prisma/orm-target-postgres` and `@prisma/orm-extension-supabase`, not dependencies. The application declares the driver itself, so the `pg.Pool` it passes in and the `pg` types Prisma 8 declares come from one copy. A project that depends on one of these packages must declare `pg` in a range inside `^8.22.0`, and `@types/pg` in a range inside `^8.20.0`. Some package managers install a missing required peer automatically, but not all do, and not in every configuration (Yarn, `legacy-peer-deps`, pnpm with `autoInstallPeers: false`), so declare both in every case.
17
+ detection:
18
+ glob: "**/package.json"
19
+ matches:
20
+ - '"@prisma/orm-(?:postgres|target-postgres|extension-supabase)"\s*:'
21
+ - id: temporal-polyfill-peer-range-moves-to-1-0-8
22
+ summary: |
23
+ The required peer range of `temporal-polyfill` moves from `^1.0.4` to `^1.0.8` on every database package: `@prisma/orm-postgres`, `@prisma/orm-sqlite`, `@prisma/orm-mysql`, `@prisma/orm-mariadb`, `@prisma/orm-mongo` and their `@prisma/orm-target-*` packages. A project that declares `temporal-polyfill` itself, as earlier guides told Yarn projects and npm projects with `legacy-peer-deps` to do, changes its range to `^1.0.8` and reinstalls, so the lockfile does not keep a version below 1.0.8.
24
+ detection:
25
+ glob: "**/{package.json,pnpm-workspace.yaml}"
26
+ matches:
27
+ - '"temporal-polyfill"\s*:\s*"[\^~]?1\.0\.[0-7](?![\d])'
28
+ - '[''"]?temporal-polyfill[''"]?:\s*[''"]?[\^~]?1\.0\.[0-7](?![\d])'
29
+ - id: config-type-renamed-to-prisma-config
30
+ summary: |
31
+ The config type that `defineConfig` returns is renamed from `PrismaNextConfig` to `PrismaConfig`, in `@prisma/orm-toolchain/cli/config-types` and every package that re-exports it. The old name is gone. The detection matches TypeScript sources that name the old type.
32
+ detection:
33
+ glob: "**/*.{ts,mts,cts,tsx}"
34
+ matches:
35
+ - '(?<![\w$])PrismaNextConfig(?![\w$])'
36
+ - id: hand-assembled-config-names-generated-file-modules
37
+ summary: |
38
+ A config built with the framework's own `defineConfig`, and not a target package's, must name the module generated contract types import from (`contract.typesModule`) and the module migration files import from (`migrations.module`). Without `contract.typesModule`, every command that writes contract types fails with `CONFIG.CONTRACT_TYPES_MODULE_MISSING`: `prisma contract emit`, `prisma migration plan` and `prisma migration new` always, `prisma db init`, `prisma db update` and `prisma db sign` when they advance a ref, and `prisma db migrate` when it advances a ref to a contract that has no snapshot under `migrations/snapshots/`. `prisma migration plan` and `prisma migration new` write that snapshot for every migration they create, so `prisma db migrate` rarely needs the module. Without `migrations.module`, `prisma migration plan` and `prisma migration new` fail with `CONFIG.MIGRATION_MODULE_MISSING`.
39
+ detection:
40
+ glob: "**/*.{ts,mts,cts}"
41
+ matches:
42
+ - '@prisma/orm-framework/config/config-types'
43
+ - '@prisma/orm-toolchain/cli/config-types'
44
+ - id: control-api-takes-types-module
45
+ summary: |
46
+ The control client's `emit` requires `contractConfig.typesModule`, and `renderContractDts` requires `typesModule`: the module the generated contract types import from. The `projectDir` option of the control API's contract emit, `migration new` and `migration plan` operations is removed.
47
+ detection:
48
+ glob: "**/*.{ts,mts,cts,tsx}"
49
+ matches:
50
+ - 'contractConfig\s*:'
51
+ - '(?<![\w$])renderContractDts\s*\('
52
+ - '@prisma/orm-toolchain/cli/control-api'
53
+ - id: toolchain-publish-surface-entrypoints-removed
54
+ summary: |
55
+ `@prisma/orm-toolchain/publish-surface`, `@prisma/orm-toolchain/publish-surface/import-roots` and `@prisma/orm-toolchain/publish-surface/shells` are removed. Nothing replaces them.
56
+ detection:
57
+ glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
58
+ matches:
59
+ - '@prisma/orm-toolchain/publish-surface'
60
+ - id: typescript-contract-for-another-target-refused
61
+ summary: |
62
+ `prisma contract emit` now refuses a SQL config's TypeScript contract that imports `defineContract` from another target's package, such as a contract that imports `defineContract` from `@prisma/orm-sqlite/contract-builder` in a project whose config comes from `@prisma/orm-postgres/config`. Such a contract used to emit and then fail when the client loaded it. The CLI reports it as `CONTRACT.TARGET_MISMATCH`, with `expected`, `actual` and `contract` in its `meta`, and its fix names the module to import `defineContract` from. A PostgreSQL config whose `contract` is a ready contract config, such as `typescriptContract(contract)`, is refused the same way when its contract was built for another target. The detection matches TypeScript files that import `defineContract` from a SQL target package.
63
+ detection:
64
+ glob: "**/*.{ts,mts,cts,tsx}"
65
+ matches:
66
+ - '@prisma/orm-(?:postgres|sqlite|mysql|mariadb)/contract-builder'
67
+ - id: typescript-contract-from-path-requires-target
68
+ summary: |
69
+ `typescriptContractFromPath` from `@prisma/orm-family-sql/contract-ts/config-types` now takes three arguments: the contract path, the output path (or `undefined`), and an options object that must hold the configured target's pack ref as `target` and that target's `contract-builder` module as `contractBuilderModule`. Calls with one or two arguments, or with only `defaultControlPolicy` and `createNamespace`, no longer compile, and in JavaScript they throw. The detection matches TypeScript and JavaScript files that import it from the SQL family, under any name; the MongoDB family's function of the same name is unchanged.
70
+ detection:
71
+ glob: "**/*.{ts,mts,cts,js,mjs,cjs}"
72
+ matches:
73
+ - '(?<![\s\S])(?=[\s\S]*@(?:prisma/orm-family-sql|internal/sql-contract-ts)/(?:contract-ts/)?config-types)[\s\S]*\btypescriptContractFromPath\b'
74
+ - id: migrate-options-ref
75
+ summary: |
76
+ The control client's `migrate` options (`MigrateOptions`, from `@prisma/orm-toolchain/cli/control-api`) no longer take `refHash`, `refInvariants` and `refName`. Pass the target as `target` (`MigrateTarget`). For a ref, pass it whole with its name: `target: { kind: 'ref', ref: { name, ...entry } }` (`NamedRef`, from `@prisma/orm-toolchain/migration-tools/refs`); the application space walks to its hash by a path that provides its invariants, and its declared policies are checked. For a contract hash, pass `target: { kind: 'hash', hash }`. `dbUpdate` takes the same `ref` for the ref `--to` named: its hash must be the storage hash of the `contract` you pass, or the call returns a failure result with code `CLI.INVALID_ARGUMENTS` before it reads the database. `migrate` and `dbUpdate` return the same code for `permitPolicyChange: true` without a ref. `dbSign` takes a required `invocation`, like `migrate`.
77
+ detection:
78
+ glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
79
+ matches:
80
+ - '(?<![\w$])refHash\s*[:,}]'
81
+ - '(?<![\w$])refInvariants\s*[:,}]'
82
+ - id: db-sign-invocation
83
+ summary: |
84
+ `DbSignOptions` has a required `invocation`, `{ cwd, configPath, dbGiven }`, so the advice of a refusal repeats the `--config` and `--db` the command was given. Pass the same `invocation` you pass to `migrate`.
85
+ detection:
86
+ glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
87
+ matches:
88
+ - '\.dbSign\s*\('
89
+ - id: permit-policy-change
90
+ summary: |
91
+ A ref can declare the policies its database should have, in a `policies` field of its ref file, and the database's marker records the policies in force. `migrate` and `dbUpdate` refuse a ref whose declared policies differ from the database's with `MIGRATION.POLICY_MISMATCH`, unless the new option `permitPolicyChange: true` consents to writing them. Pass `permitPolicyChange` only when the person running the deploy has said the ref's policies should be applied. A database whose change policy does not permit the operation refuses with `MIGRATION.CHANGE_POLICY_FORBIDS`; `db sign` refuses the same way.
92
+ - id: psl-schema-must-be-utf8
93
+ summary: |
94
+ A Prisma schema file that is not valid UTF-8 is now refused with `PSL_SCHEMA_READ_FAILED`, naming the file. Before, each invalid byte was silently replaced with U+FFFD and the file loaded. Reopen each such file in the encoding it was written in, such as Windows-1252, and save it as UTF-8; opening it as UTF-8 and saving keeps the wrong character. If the text is already damaged, restore it from a good copy.
95
+ - id: psl-renamed-sql-string
96
+ summary: |
97
+ The SQL family's `sql.String(n)`, a `varchar(n)` column on PostgreSQL, SQLite and MySQL, is renamed `sql.Varchar(n)`. `sql.String` stays for one release line as a deprecated alias that warns with `PSL_DEPRECATED_SCALAR_NAME`. The contract does not change.
98
+ detection:
99
+ glob: "**/*.prisma"
100
+ matches:
101
+ - '(?<![\w.])sql\s*\.\s*String\s*\('
102
+ - id: ts-renamed-sql-string
103
+ summary: |
104
+ In a TypeScript contract, `type.sql.String(n)` is renamed `type.sql.Varchar(n)`. `type.sql.String` still compiles as a deprecated alias and gives the same type and contract.
105
+ detection:
106
+ glob: "**/*.{ts,mts,cts,tsx}"
107
+ matches:
108
+ - '(?<![\w$])sql\s*\.\s*String\s*\('
109
+ - id: ts-renamed-postgres-json-column-helper
110
+ summary: |
111
+ The PostgreSQL column helper `jsonColumn` is renamed `plainJsonColumn`, after the explicit type it gives (`PlainJson`, a `json` column). The old name is removed. The contract does not change. SQLite's `jsonColumn` has a rename of its own.
112
+ detection:
113
+ glob: "**/*.{ts,mts,cts,tsx}"
114
+ matches:
115
+ - '(?:import|export)[ \t]+(?:type[ \t]+)?\{[^}]*(?<![\w$])jsonColumn(?![\w$])[^}]*\}[ \t]*from[ \t]*[''"](?:@prisma/orm-postgres/adapter/column-types|@prisma/orm-target-postgres/adapter/column-types|@internal/adapter-postgres/column-types)[''"]'
116
+ - 'import[ \t]+(?:type[ \t]+)?\*[ \t]*as[ \t]+([\w$]+)[ \t]+from[ \t]*[''"](?:@prisma/orm-postgres/adapter/column-types|@prisma/orm-target-postgres/adapter/column-types|@internal/adapter-postgres/column-types)[''"][\s\S]*(?<![\w$])\1\s*\.\s*jsonColumn(?![\w$])'
117
+ - id: ts-renamed-sqlite-column-helpers
118
+ summary: |
119
+ The SQLite column helpers are renamed after the explicit type each gives: `integerColumn` is `integerNumberColumn` (`IntegerNumber`), `bigintColumn` is `integerBigIntColumn` (`IntegerBigInt`) and `jsonColumn` is `plainJsonColumn` (`PlainJson`). The old names are removed. The contract does not change.
120
+ detection:
121
+ glob: "**/*.{ts,mts,cts,tsx}"
122
+ matches:
123
+ - '(?:import|export)[ \t]+(?:type[ \t]+)?\{[^}]*(?<![\w$])(?:integerColumn|bigintColumn|jsonColumn)(?![\w$])[^}]*\}[ \t]*from[ \t]*[''"](?:@prisma/orm-sqlite/adapter/column-types|@prisma/orm-target-sqlite/adapter/column-types|@internal/adapter-sqlite/column-types)[''"]'
124
+ - 'import[ \t]+(?:type[ \t]+)?\*[ \t]*as[ \t]+([\w$]+)[ \t]+from[ \t]*[''"](?:@prisma/orm-sqlite/adapter/column-types|@prisma/orm-target-sqlite/adapter/column-types|@internal/adapter-sqlite/column-types)[''"][\s\S]*(?<![\w$])\1\s*\.\s*(?:integerColumn|bigintColumn|jsonColumn)(?![\w$])'
125
+ - id: sqlite-bigintnumber-deprecated
126
+ summary: |
127
+ On SQLite, `BigIntNumber` is a deprecated alias of `IntegerNumber` that warns with `PSL_DEPRECATED_SCALAR_NAME`, and a field written with it now emits codec `sqlite/integer@1` instead of `sqlite/bigintnumber@1`. Write `BigInt(as: number)` (or `type.BigInt({ as: 'number' })`), or `IntegerNumber`, which the warning names; both give the same contract. Re-emit the contract and sign the database. No column changes and no data moves.
128
+ detection:
129
+ glob: "**/*.{prisma,ts,mts,cts,tsx}"
130
+ matches:
131
+ - '(?<![\w.])BigIntNumber(?![\w])'
132
+ - '\.\s*BigIntNumber\s*\('
133
+ - id: sqlite-decimal-codec
134
+ summary: |
135
+ On SQLite, `Decimal` is now a convenience type over the explicit type `DecimalString`, with its own codec `sqlite/decimal@1` on the same `text` column. A field written `Decimal` (or `type.Decimal()`) emitted `sqlite/text@1` before. Re-emit the contract and sign the database; no column changes and no data moves. Stored text that is not a decimal now fails to read, so find and fix such rows.
136
+ detection:
137
+ glob: "**/*.prisma"
138
+ matches:
139
+ - '(?:^|\n)[ \t]*[A-Za-z_]\w*[ \t]+Decimal(?![\w])'
140
+ - '=[ \t]*Decimal(?![\w])'
141
+ - id: ts-sqlite-decimal-codec
142
+ summary: |
143
+ In a SQLite TypeScript contract, `type.Decimal()` now emits codec `sqlite/decimal@1` instead of `sqlite/text@1`, and `type.DecimalString()` is the same type. Re-emit the contract and sign the database; no column changes and no data moves.
144
+ detection:
145
+ glob: "**/*.{ts,mts,cts,tsx}"
146
+ matches:
147
+ - '(?<![\s\S])(?=[\s\S]*[''"](?:@prisma/orm-sqlite|@internal/sqlite)/contract-builder[''"])[\s\S]*\.\s*Decimal\s*\('
148
+ - id: sqlite-integer-safe-range
149
+ summary: |
150
+ On SQLite, an `Int` field, and every field whose codec is `sqlite/integer@1` (`IntegerNumber`, `BigInt(as: number)`, the deprecated `BigIntNumber`), now refuses to write a number that is not an integer within ±(2^53 − 1), such as `1.5`, with `RUNTIME.ENCODE_FAILED`, and reading a stored number that is not an integer, such as a `real`, raises `RUNTIME.DECODE_FAILED` naming the table and column. Before, the codec wrote any number as it was and read such a number as it was. A stored integer outside the range, which failed to read in a row with a `RangeError` from `node:sqlite` before, now raises `RUNTIME.DECODE_FAILED` naming the table and column. `sql/int@1` checks a read the same way. Find rows that hold such values and fix them.
151
+ detection:
152
+ glob: "**/*.{prisma,ts,mts,cts,tsx}"
153
+ matches:
154
+ - '(?:^|\n)[ \t]*[A-Za-z_]\w*[ \t]+(?:Int|IntegerNumber)(?![\w])'
155
+ - '=[ \t]*(?:Int|IntegerNumber)(?![\w])'
156
+ - 'BigInt[ \t]*\([ \t]*as[ \t]*:[ \t]*number'
157
+ - '(?<![\s\S])(?=[\s\S]*[''"](?:@prisma/orm-sqlite|@internal/sqlite)/contract-builder[''"])[\s\S]*\.\s*(?:Int|IntegerNumber)\s*\('
158
+ - '(?<![\s\S])(?=[\s\S]*[''"](?:@prisma/orm-sqlite|@internal/sqlite)/contract-builder[''"])[\s\S]*\.\s*BigInt\s*\(\s*\{[^}]*as\s*:\s*[''"]number[''"]'
159
+ - '(?<![\w$])(?:integerNumberColumn|sqliteIntegerColumn)(?![\w$])'
160
+ - '(?:import|export)[ \t]+(?:type[ \t]+)?\{[^}]*(?<![\w$])integerColumn(?![\w$])[^}]*\}[ \t]*from[ \t]*[''"](?:@prisma/orm-sqlite/adapter/column-types|@prisma/orm-target-sqlite/adapter/column-types|@internal/adapter-sqlite/column-types)[''"]'
161
+ - 'import[ \t]+(?:type[ \t]+)?\*[ \t]*as[ \t]+([\w$]+)[ \t]+from[ \t]*[''"](?:@prisma/orm-sqlite/adapter/column-types|@prisma/orm-target-sqlite/adapter/column-types|@internal/adapter-sqlite/column-types)[''"][\s\S]*(?<![\w$])\1\s*\.\s*integerColumn(?![\w$])'
162
+ - id: psl-renamed-mongo-int64
163
+ summary: |
164
+ On MongoDB, the explicit type `Int64` (a BSON long read as a `bigint`) is renamed `Int64BigInt`. `Int64` stays for one release line as a deprecated alias that warns with `PSL_DEPRECATED_SCALAR_NAME`. The contract does not change.
165
+ detection:
166
+ glob: "**/*.prisma"
167
+ matches:
168
+ - '(?<![\w.])Int64(?![\w])'
169
+ - id: ts-removed-mongo-int64-helper
170
+ summary: |
171
+ In a MongoDB TypeScript contract, `type.Int64()` is removed. Write `type.BigInt()`, the convenience type, or `type.Int64BigInt()`, the explicit type. Both give the same contract.
172
+ detection:
173
+ glob: "**/*.{ts,mts,cts,tsx}"
174
+ matches:
175
+ - '\.\s*Int64(?![\w])'
176
+ - '\{[^{}]*\bInt64\b[^{}]*\}\s*=\s*\w'
177
+ - id: psl-optional-mongo-convenience-names
178
+ summary: |
179
+ Optional: in a MongoDB schema, the explicit types `Int32`, `Double` and `Bool` may be written as the convenience types `Int`, `Float` and `Boolean`. The contract does not change.
180
+ detection:
181
+ glob: "**/*.prisma"
182
+ matches:
183
+ - '(?<![\s\S])(?=[\s\S]*\bObjectId\b)[\s\S]*(?<![\w.])(?:Int32|Double|Bool)(?![\w])'
184
+ - id: has-one-key-must-be-unique
185
+ summary: |
186
+ Building a SQL contract fails with `CONTRACT.RELATION_INVALID` when a one-to-one relation, `rel.hasOne(Target, { by: ... })` in TypeScript, names `by` fields of the target model that no primary key, unique constraint or unique index without a `where` covers exactly. Make those fields unique, or make the relation `rel.hasMany`. PSL schemas are not affected: PSL already refused a singular back-relation over a non-unique foreign key. The detection matches TypeScript sources that declare a `hasOne` relation.
187
+ detection:
188
+ glob: "**/*.{ts,mts,cts,tsx}"
189
+ matches:
190
+ - '(?<![\w$])rel\s*\.\s*hasOne\s*\('
191
+ - id: sti-variant-unscoped-index-refused
192
+ summary: |
193
+ `prisma contract emit` now refuses every `@unique` and `@@unique`, and most `@@index` without `where:`, on a single-table variant, and stores a variant `@@index` with `where:` that it used to drop. Rewrite each refused attribute as the partial index the message gives, then plan and apply a migration.
194
+ detection:
195
+ glob: "**/*.prisma"
196
+ matches:
197
+ - '(?<![\s\S])(?=[\s\S]*@@base\s*\()[\s\S]*(@unique|@@index\s*\()'
198
+ - id: sti-variant-foreign-keys-stored
199
+ summary: |
200
+ A relation on a single-table variant now stores its foreign key on the base table, with a backing index unless the relation says `index: false`; both used to be dropped. Re-emit the contract, then plan and apply a migration.
201
+ detection:
202
+ glob: "**/*.prisma"
203
+ matches:
204
+ - '(?<![\s\S])(?=[\s\S]*@@base\s*\()[\s\S]*@relation\s*\([^)]*fields\s*:'
205
+ - id: contract-types-import-from-the-target-package
206
+ summary: |
207
+ A generated `contract.d.ts` imports all its framework, family and target types from one module of the target package, such as `@prisma/orm-postgres/contract-types`, and `contract.json` no longer records where an extension's types are imported from. Run `prisma contract emit` to regenerate both files.
208
+ detection:
209
+ glob: "**/contract.d.ts"
210
+ matches:
211
+ - '@prisma/orm-[a-z-]+/(contract/types|family-contract|target/(codec|operation)-types|adapter/codec-types)'
212
+ - id: re-emit-for-include-capabilities
213
+ summary: |
214
+ SQL adapters report two new capabilities in the `sql` group, `outerReferencesInDerivedTables` and `jsonAggWithoutTruncation`, which together with `sql.jsonAgg` decide whether the ORM loads includes with the one-query include or with one query per relation. The PostgreSQL and MySQL adapters now also report `sql.jsonAgg`. Run `prisma contract emit` to record them in `contract.json` and `contract.d.ts`. A contract that is not re-emitted keeps working, because the runtime merges the adapter's capabilities over the contract's, and the profile hash does not change, so no database needs signing again. The contract snapshots under `migrations/snapshots/` need no change.
215
+ detection:
216
+ glob: "**/contract.json"
217
+ matches:
218
+ - '(?<![\s\S])(?=[\s\S]*"targetFamily"\s*:\s*"sql")(?![\s\S]*"target"\s*:\s*"mariadb")(?![\s\S]*"jsonAggWithoutTruncation")'
219
+ - '(?<![\s\S])(?=[\s\S]*"target"\s*:\s*"mariadb")(?![\s\S]*"jsonAgg")'
220
+ - id: re-emit-mysql-contract-for-aggregates
221
+ summary: |
222
+ The MySQL target now contributes the ORM's aggregates, so `include('posts', (p) => p.count())`, `combine()` and `aggregate()` run on MySQL and MariaDB. Run `prisma contract emit` so `contract.d.ts` carries the aggregate types; until then TypeScript does not offer `count()`, `sum()`, `avg()`, `min()` and `max()`. The contract hashes do not change; `contract.json` changes only by the capabilities `re-emit-for-include-capabilities` describes.
223
+ detection:
224
+ glob: "**/contract.d.ts"
225
+ matches:
226
+ - '(?<![\s\S])(?=[\s\S]*readonly target: .(?:mysql|mariadb).)[\s\S]*AggregateTypes = Record<string, never>'
227
+ - id: mysql-reemit-contract
228
+ summary: |
229
+ On MySQL and MariaDB, `Int`, `BigInt`, `Float`, `Decimal`, `String`, `Boolean`, `Bytes` and `Json` are now convenience types, and the target has new codecs for them. The emitted `contract.d.ts` gains aggregate result types for the new codecs. Re-emit the contract; its hashes do not change, so the database needs no migration and no new signature. `contract.json` changes only by the capabilities `re-emit-for-include-capabilities` describes.
230
+ detection:
231
+ glob: "**/prisma.config.{ts,mts,cts,js,mjs}"
232
+ matches:
233
+ - '[''"]@prisma/orm-(?:mysql|mariadb)/config[''"]'
234
+ - id: contract-artifacts-restamp
235
+ summary: |
236
+ An extension that writes its own package version into the contracts it emits, such as the Supabase extension, now writes 8.0.0-rc.25. Run `contract emit` once after upgrading so the emitted `contract.json` and `contract.d.ts` match the installed extension.
237
+ detection:
238
+ glob: "**/contract.json"
239
+ contains:
240
+ - '"version": "8.0.0-rc.24"'
241
+ - id: sql-stored-name-change-is-a-rename
242
+ summary: |
243
+ On PostgreSQL and SQLite, a model, field or enum member that keeps its name while its `@@map`, `@map` or stored value changes is now renamed, or has its stored value replaced, by `migration plan` and `db update`, with no question. The by-hand rename these changes needed before is no longer needed.
244
+ - id: sql-stored-name-delete-is-unused
245
+ summary: |
246
+ A `--delete` statement that a script passed to allow the drop and create of a table or column whose stored name changed now answers no question, and the run fails with `CLI.CONSENT_UNUSED`.
247
+ - id: sql-stored-name-empty-table
248
+ summary: |
249
+ To get an empty table or column under a new stored name instead of renaming the old one, remove the model or field in one change and add it back in a second.
250
+ - id: sql-stored-name-swaps-refused
251
+ summary: |
252
+ Swaps, chains and takeovers of table and column names, which planned with no question before and left rows under the wrong model, are now refused with `MIGRATION.PLANNING_FAILED`. So are enum members that swap stored values or take the stored value of a removed member, which were asked about before. Chains of enum stored values are planned.
253
+ - id: sql-lowered-table-names-renamed
254
+ summary: |
255
+ A project with an origin snapshot whose tables still have the names an earlier release gave models with no `@@map` (the first letter lowered) now gets those tables renamed to the model names, with no question. Add `@@map` to keep the old names.
256
+ - id: mongo-nested-removals-are-asked
257
+ summary: |
258
+ A MongoDB plan now asks about a field a value object or an embedded model loses, a stored value an enum loses, and a variant the contract removes or whose discriminator value changes, where it planned only a validator change before. `--delete` removes the key or the value from the documents, or deletes the variant's documents.
259
+ - id: mongo-nested-statements-are-planned
260
+ summary: |
261
+ `--rename` of a value object field, of an embedded model's field, of an enum value, and of a variant whose discriminator value changes, `--convert` of a variant, and `--backfill` of a field inside a value object or an embedded model now plan rewrites of the documents on MongoDB instead of failing with `MIGRATION.PLANNING_FAILED`.
262
+ - id: mongo-nested-required-field-gets-temporary-value
263
+ summary: |
264
+ A required field new inside a MongoDB value object or embedded model is now filled with a temporary value in the objects that lack it, as at the top level, unless `--backfill` names it.
265
+ - id: json-default-proto-key-kept
266
+ summary: |
267
+ A JSON column default that has a `__proto__` key now keeps that key in `contract.json` and in the storage hash; it used to be dropped. Re-emit the contract, then plan and apply a migration.
268
+ detection:
269
+ glob: "**/*.prisma"
270
+ matches:
271
+ - 'json`[^`]*__proto__'
272
+ - id: mongo-proto-names-refused
273
+ summary: |
274
+ A MongoDB contract now refuses a model, composite type or value object, collection or root named `__proto__`, and the TypeScript builder refuses an enum with that name too. In a PSL contract, an enum named `__proto__` is not refused: it is left out of the contract without an error, together with every field typed by it. Choose another name.
275
+ detection:
276
+ glob: "**/*.{prisma,ts}"
277
+ matches:
278
+ - '__proto__'
279
+ - id: sql-proto-names-refused
280
+ summary: |
281
+ A SQL contract now refuses a namespace, table, column, model, field or enum named `__proto__` with `CONTRACT.NAME_UNUSABLE_AS_KEY`, and a `__proto__` key in an object literal of a TypeScript contract. Before, the entry was dropped or the contract came out wrong. Choose another name.
282
+ detection:
283
+ glob: "**/*.{prisma,ts}"
284
+ matches:
285
+ - '__proto__'
286
+ - id: update-data-refuses-discriminator
287
+ summary: |
288
+ Update data on a polymorphic model no longer takes the discriminator field: setting it is a type error, and at run time it is refused with `ORM.FIELD_IMMUTABLE`. Before, it changed only the base table and left the variant's rows inconsistent. Remove the discriminator from update data.
289
+ - id: init-target-takes-a-package-name
290
+ summary: |
291
+ `prisma orm init --target` takes the name of a target package, such as `--target @prisma/orm-sqlite`, beside the short names `postgres` and `mongodb`. The `--json` result gains `package`, the name of the target package, and its `target` is the package name when the package has no short name. A script that reads the result needs a change only if it accepts no `target` but `postgres` and `mongodb`.
292
+ detection:
293
+ glob: "**/*.{sh,bash,zsh,ts,mts,cts,js,mjs,cjs,json,yml,yaml}"
294
+ matches:
295
+ - 'orm init\b[^\n]*--json'
296
+ - id: orm-write-inside-transaction-suspends-tx
297
+ summary: |
298
+ An ORM write of more than one statement on `tx.orm`, such as a create with a nested relation, runs in a savepoint. While it runs, other work sent on the same `tx` rejects with `RUNTIME.TRANSACTION_SUSPENDED`. When such a write fails with an error that ends the whole transaction, such as a deadlock on MySQL or MariaDB, it rejects with `RUNTIME.TRANSACTION_ROLLBACK_FAILED`, whose `cause` is the database's error, and the transaction is closed. The detection matches TypeScript sources that call `transaction` and `Promise.all` or `Promise.allSettled`.
299
+ detection:
300
+ glob: "**/*.{ts,mts,cts,tsx}"
301
+ matches:
302
+ - '(?<![\s\S])(?=[\s\S]*\.transaction\s*\()[\s\S]*Promise\.all'
303
+ - id: foreign-key-with-relation-callback-refused
304
+ summary: |
305
+ `update()` data that sets a field of the foreign key the record holds for a relation (many-to-one, such as `Post.authorId` for `Post.author`) and also has a callback on that relation is refused with `ORM.ARGUMENT_INVALID` (`meta.problem: 'foreign-key-with-relation-mutation'`, with `meta.relation` and `meta.fields`) before any statement runs. It used to run, and a `create`, `connect` or `disconnect` callback overwrote the foreign key the data set. Keep either the foreign key or the callback.
306
+ - id: nullable-unique-key-is-no-row-identity
307
+ summary: |
308
+ A unique key with a nullable column no longer identifies a row: two rows may both hold NULL in it. A table whose only unique key has a nullable column now has no row identity, on every database, and the ORM refuses the calls that need one with `ORM.ROW_IDENTITY_MISSING`. Give such a table a primary key, or make the unique key's columns `NOT NULL`.
309
+ - id: relation-mutation-error-codes-merged
310
+ summary: |
311
+ A nested relation mutation now refuses malformed input with `ORM.ARGUMENT_INVALID` instead of `ORM.RELATION_MUTATION_INVALID`, and an operation it does not support in that position with `ORM.OPERATION_UNSUPPORTED` instead of `ORM.RELATION_MUTATION_UNSUPPORTED`. The error's `meta` is unchanged.
312
+ detection:
313
+ glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
314
+ matches:
315
+ - 'ORM\.RELATION_MUTATION_(?:INVALID|UNSUPPORTED)(?![\w$])'
316
+ - id: nested-create-on-polymorphic-target-needs-variant
317
+ summary: |
318
+ In a relation callback whose target is a polymorphic base model, `r.create(data)` no longer compiles. Create the rows with `r.variant(value).create(data)` and drop the discriminator field from the data.
319
+ - id: variant-create-without-returning-names-create
320
+ summary: |
321
+ `create()` on a variant stored in its own table, on a contract without the `returning` capability, fails with `ORM.CAPABILITY_MISSING` whose message and `meta.action` name `create()` instead of `createAll()`.
322
+ detection:
323
+ glob: "**/*.{ts,mts,cts,tsx}"
324
+ matches:
325
+ - 'createAll\(\) requires contract capability \\?"returning'
326
+ - 'action\s*[:=]+\s*[''"`]createAll\(\)[''"`]'
327
+ - id: disconnect-on-required-relation-refused
328
+ summary: |
329
+ In `update()` data, `r.disconnect()` on a relation whose foreign key is required (not nullable) no longer compiles, and at run time it is refused with `ORM.OPERATION_UNSUPPORTED` (`meta.reason: 'required-foreign-key'`) before any statement runs, instead of failing with the database's NOT NULL error. A `disconnect` that would have changed no row, such as `disconnect(criteria)` that matches no related row, is refused too; it used to succeed. When `meta.model` is the model being updated, the record holds the key: link it to another row with `connect` or delete the record. Otherwise the related rows hold the key: connect them to another record or delete them. Many-to-many `disconnect` and `disconnect` on an optional relation are unchanged.
330
+ - id: to-one-disconnect-criteria-applied
331
+ summary: |
332
+ In `update()` data, `r.disconnect(criteria)` on a relation the record holds the key for (many-to-one) now unlinks the record only when the row it is linked to matches one of the criteria; before, it ignored the criteria and always unlinked. Where the criteria do not match the linked row, the foreign key stays unchanged, and the other updates of the same `update()` still apply. Pass no criteria to unlink whatever row is linked. `r.variant(value).disconnect(criteria?)` on such a relation is now available and unlinks only a linked row of that variant. All of this applies to a relation whose foreign key is optional: on a required key, `disconnect` is refused with `ORM.OPERATION_UNSUPPORTED` (`reason: 'required-foreign-key'`) before its criteria or variant are looked at.
333
+ - id: disconnect-empty-criteria-disconnects-nothing
334
+ summary: |
335
+ In `update()` data, `r.disconnect([])` with an explicit empty list of criteria now disconnects nothing. Before, it acted as `r.disconnect()`: on a relation the record holds the key for it unlinked the record, and on a one-to-many or one-to-one relation it unlinked every related row. Many-to-many `disconnect([])` is still refused.
336
+ - id: create-all-skip-refuses-rows-without-conflict-key
337
+ summary: |
338
+ `createAll(rows, { onConflict: 'skip' })` and `createAndCount(rows, { onConflict: 'skip' })` now refuse, before any statement runs, a row that gives no value for any key the option watches, with `ORM.ARGUMENT_INVALID`. Such a row was inserted before.
339
+ detection:
340
+ glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
341
+ matches:
342
+ - '(?<![\w$])onConflict\s*:\s*[\x27"]skip[\x27"]'
343
+ - id: create-all-skip-refuses-tables-without-keys
344
+ summary: |
345
+ `createAll(rows, { onConflict: 'skip' })` and `createAndCount(rows, { onConflict: 'skip' })` without `conflictOn` now refuse a table with no primary key, unique constraint or unique index over columns, with `ORM.ARGUMENT_INVALID`. Every row was inserted before.
346
+ detection:
347
+ glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
348
+ matches:
349
+ - '(?<![\w$])onConflict\s*:\s*[\x27"]skip[\x27"]'
350
+ - id: sql-builder-enum-comparison-values-are-checked
351
+ summary: |
352
+ In the SQL builder, a raw value compared with a column in `fns.eq`, `fns.ne`, `fns.gt`, `fns.gte`, `fns.lt`, `fns.lte`, `fns.in` or `fns.notIn` must now have the type the contract gives that column, as it already must in `insert`, `update` and the ORM client's `where`. This affects every column whose contract type is narrower than its codec's type: enums stored as text or integers, native enums, and columns with a typed override. A value that is not a member, such as a misspelling, is now a type error. Before, the query ran and matched no rows, or, for a native enum, the database rejected the value. So is a value typed as a plain `string` or `number`, or a `string[]` passed to `fns.in`. Fix the value, or narrow it to the column's type before comparing. To match a value the column's type no longer lists, such as in a migration that renames an enum member, compare with `fns.raw` instead.
353
+ detection:
354
+ glob: "**/*.{ts,tsx,mts,cts}"
355
+ matches:
356
+ - 'fns\.(?:eq|ne|gt|gte|lt|lte|in|notIn)\('
357
+ - id: mysql-errors-drop-meta-target
358
+ summary: |
359
+ Errors from the MySQL codecs, the SQL lexer, the codec registry and the driver's parameter checks no longer carry `meta.target: 'mysql'`, since the same code now serves MariaDB. Code that reads `error.meta.target` from them gets `undefined`; read the target from the client the error came from (`db.stack.target.targetId`) instead.
360
+ detection:
361
+ glob: "**/*.{ts,mts,cts,tsx}"
362
+ matches:
363
+ - '(?<![\s\S])(?=[\s\S]*@prisma/orm-(?:mysql|mariadb))[\s\S]*\bmeta\??\.target\b'
364
+ - id: db-migrate-advances-db-ref
365
+ summary: |
366
+ `prisma db migrate` now advances the `db` ref after a successful apply when the connection comes from `prisma.config.ts` and the CLI does not detect CI. Without `--advance-ref`, it still advances nothing with `--db` or in CI. A `db migrate --advance-ref db` that reads its connection from the config outside CI can drop the flag; one that passes `--db` or runs in CI keeps it. A deploy or script that runs `db migrate` from the config outside a CI runner, and must not change `migrations/app/refs/db.json`, passes the new `--no-advance-ref` or `--db`. A failed ref write is now a warning and the command exits 0, which matters to a script that checks the exit code of `db migrate --advance-ref`. The detection finds `db migrate` commands that pass `--advance-ref`, and those that pass neither `--db` nor `--no-advance-ref`, including a Dockerfile's exec form, a YAML list and a command split with a backslash between `db` and `migrate`; it reads the flags only on the line where `migrate` is; check each against the cases below, and look for others in files it does not search.
367
+ detection:
368
+ glob: "**/{*.json,*.sh,*.bash,*.zsh,*.yml,*.yaml,*.toml,*.md,*.mdx,*.ts,*.mts,*.js,*.mjs,*.cjs,Dockerfile*,*.dockerfile,Procfile*,Makefile,justfile}"
369
+ matches:
370
+ - '(?<![\w-])db(?:\s+|\s*\\\n\s*|["'']?\s*[,\n]\s*(?:-\s+)?["'']?)migrate\b(?:(?=[^\n]*--advance-ref\b)|(?![^\n]*--(?:db|no-advance-ref)\b))'
371
+ - id: engine-pin-moves-to-0-10-4
372
+ summary: |
373
+ The toolchain now requires `@prisma/cli-engine@0.10.4` (up from 0.10.0). A project that depends on `@prisma/cli-engine` itself must move to `0.10.4`.
374
+ detection:
375
+ glob: "**/{package.json,pnpm-workspace.yaml}"
376
+ matches:
377
+ - '"@prisma/cli-engine":\s*"[^"]*(?<![\d.])0\.(?:\d|10\.[0123xX*])(?!\d)'
378
+ - '[''"]?@prisma/cli-engine[''"]?:\s*[''"]?(?:[\^~]|[<>]=?\s*)?0\.(?:\d|10\.[0123xX*])(?!\d)'
379
+ - id: consent-required-summary-is-one-fixed-sentence
380
+ summary: |
381
+ The first line of `CLI.CONSENT_REQUIRED` is now one fixed sentence. It no longer names the subject of a statement question, and it no longer quotes the question of a consent that `--confirm` answers. Code that matched the old first line must read the error's `code`, `why` and `meta` instead.
382
+ detection:
383
+ glob: "**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,snap,json,sh,bash,yml,yaml}"
384
+ matches:
385
+ - 'needs? a statement'
386
+ - '--yes cannot give'
387
+ - '--yes cannot grant'
388
+ - '--yes does not give it'
389
+ - 'requires explicit consent, (?:and|which)'
390
+ - 'Grant it by passing --confirm'
391
+ - 'session is not interactive'
392
+ ---
393
+
394
+ # 8.0.0-rc.24 → 8.0.0-rc.25 — User upgrade instructions
395
+
396
+ The examples write the ORM client as `db.orm.public.<Model>`, which is the PostgreSQL form with its namespace. On SQLite, MySQL and MariaDB the same collection is `db.orm.<Model>`.
397
+
398
+ ## Order of the steps
399
+
400
+ Do the steps in this order, and skip a step that does not apply to the project:
401
+
402
+ 1. Before you deploy the upgrade, on PostgreSQL with `money` columns, make the database print `money` in the `C` form (`postgres-lc-monetary-not-set`). The old release still forces it on its own connections, so do this first.
403
+ 2. Before you run the install for the upgrade, fix the dependencies in `package.json`: declare `pg` and `@types/pg` for the PostgreSQL packages (`pg-is-a-peer-dependency`), move a declared `temporal-polyfill` to `^1.0.8` (`temporal-polyfill-peer-range-moves-to-1-0-8`), and move a declared `@prisma/cli-engine` to `0.10.4` (`engine-pin-moves-to-0-10-4`). Then upgrade the Prisma packages.
404
+ 3. Change the config and the scripts that call the control client: the renamed config type (`config-type-renamed-to-prisma-config`), the modules a hand-assembled config names (`hand-assembled-config-names-generated-file-modules`), `typesModule` and the removed `projectDir` (`control-api-takes-types-module`), the removed `publish-surface` entries (`toolchain-publish-surface-entrypoints-removed`), the arguments of `typescriptContractFromPath` (`typescript-contract-from-path-requires-target`), and the `migrate`, `dbUpdate` and `dbSign` options (`migrate-options-ref`, `db-sign-invocation`, `permit-policy-change`). Change the commands that run `prisma db migrate`, in scripts, deploys and docs, for the `db` ref it now advances (`db-migrate-advances-db-ref`).
405
+ 4. Change the contract sources. Make each TypeScript contract import `defineContract` from its config's target (`typescript-contract-for-another-target-refused`). Save every schema file as UTF-8 (`psl-schema-must-be-utf8`). Rewrite the renamed types and helpers: `sql.String` (`psl-renamed-sql-string`, `ts-renamed-sql-string`), the PostgreSQL and SQLite column helpers (`ts-renamed-postgres-json-column-helper`, `ts-renamed-sqlite-column-helpers`), SQLite's `BigIntNumber` (`sqlite-bigintnumber-deprecated`) and MongoDB's `Int64` (`psl-renamed-mongo-int64`, `ts-removed-mongo-int64-helper`, and optionally `psl-optional-mongo-convenience-names`). Fix each `hasOne` relation without a unique key (`has-one-key-must-be-unique`) and each attribute of a single-table variant that emit refuses (`sti-variant-unscoped-index-refused`). Rename anything named `__proto__` (`sql-proto-names-refused`, `mongo-proto-names-refused`).
406
+ 5. Run `prisma contract emit` once for every contract and commit what it writes. One emit covers `contract-types-import-from-the-target-package`, `re-emit-for-include-capabilities`, `re-emit-mysql-contract-for-aggregates`, `mysql-reemit-contract`, `sqlite-decimal-codec`, `ts-sqlite-decimal-codec`, `sti-variant-foreign-keys-stored`, `json-default-proto-key-kept` and `contract-artifacts-restamp`. Leave the contract copies under `migrations/` as they are.
407
+ 6. Before you plan any migration, read what the planner now does: on PostgreSQL and SQLite a changed stored name is a rename (`sql-stored-name-change-is-a-rename`, `sql-stored-name-delete-is-unused`, `sql-stored-name-empty-table`, `sql-stored-name-swaps-refused`, `sql-lowered-table-names-renamed`), and on MongoDB changes inside documents are asked about and planned (`mongo-nested-removals-are-asked`, `mongo-nested-statements-are-planned`, `mongo-nested-required-field-gets-temporary-value`). A migration planned in the next step can hold such renames. If you add `@@map` to keep a table's old name, run `prisma contract emit` again first.
408
+ 7. Bring each database up to date. Plan and apply a migration for a new unique key (`has-one-key-must-be-unique`), for a JSON default that has a `__proto__` key (`json-default-proto-key-kept`) and for the indexes and foreign keys of single-table variants (`sti-variant-unscoped-index-refused`, `sti-variant-foreign-keys-stored`). On SQLite, fix stored values the stricter codecs refuse (`sqlite-decimal-codec`, `sqlite-integer-safe-range`), then sign the database with the new contract as the SQLite section describes. One migration can cover all of these. In a project that applied its earlier migrations with `db migrate` and no `--advance-ref`, there is no `db` ref for `migration plan` to start from: pass `--from <latest migration>`, as the SQLite section shows.
409
+ 8. Change the application code: work sent on a transaction while an ORM write runs on it (`orm-write-inside-transaction-suspends-tx`), update data that sets a discriminator (`update-data-refuses-discriminator`), `update()` data that sets a foreign key and also has a callback on its relation (`foreign-key-with-relation-callback-refused`), tables whose only unique key has a nullable column (`nullable-unique-key-is-no-row-identity`), the ORM error codes of nested relation mutations (`relation-mutation-error-codes-merged`), nested creates on a polymorphic model (`nested-create-on-polymorphic-target-needs-variant`, `variant-create-without-returning-names-create`), `disconnect` (`disconnect-on-required-relation-refused`, `to-one-disconnect-criteria-applied`, `disconnect-empty-criteria-disconnects-nothing`), `onConflict: 'skip'` (`create-all-skip-refuses-rows-without-conflict-key`, `create-all-skip-refuses-tables-without-keys`), SQL builder comparisons (`sql-builder-enum-comparison-values-are-checked`), code that reads `meta.target` from a MySQL error (`mysql-errors-drop-meta-target`), scripts that read the `--json` result of `prisma orm init` (`init-target-takes-a-package-name`) and code that matches the first line of `CLI.CONSENT_REQUIRED` (`consent-required-summary-is-one-fixed-sentence`). Three of these fixes change the contract: giving a table a primary key or required key fields (`nullable-unique-key-is-no-row-identity`), giving a table a key for `onConflict: 'skip'` (`create-all-skip-refuses-tables-without-keys`), and making a foreign key optional (`disconnect-on-required-relation-refused`). After any of them, emit the contract and plan and apply a migration again.
410
+
411
+
412
+ ## PostgreSQL: `money` needs the database's `lc_monetary` to print the `C` form
413
+
414
+ ### `postgres-lc-monetary-not-set`
415
+
416
+ Earlier releases started every PostgreSQL connection with `lc_monetary=C`, so `money` read and wrote the same value in any locale. A per-transaction connection pooler, such as the pooled address of Prisma Postgres, refuses a connection that asks for that setting, so the driver no longer sends it. The database must now provide it.
417
+
418
+ This matters only if the application reads or writes `money` columns.
419
+
420
+ 1. Connect as the role the application uses, to the database and address it uses, and run `SHOW lc_monetary`. Use `psql` or another client, not Prisma: earlier releases set `lc_monetary` to `C` on their own connections, so a query through them prints `C` whatever the database has.
421
+ 2. If it prints `C`, `POSIX` or `en_US`, with or without an encoding suffix (`C.UTF-8`, `en_US.UTF-8`), stop. Prisma Postgres also needs no action.
422
+ 3. Otherwise, set it before you deploy the upgrade, while the old release still forces `C` on its own connections:
423
+
424
+ ```sql
425
+ ALTER ROLE app_role SET lc_monetary = 'C';
426
+ -- or, for every role:
427
+ ALTER DATABASE app_db SET lc_monetary = 'C';
428
+ ```
429
+
430
+ Prefer the role. The database setting also changes how every other client of that database prints and reads `money`.
431
+
432
+ The setting applies to server connections opened afterwards. Behind a connection pooler, it takes effect once the pooler replaces its existing server connections.
433
+
434
+ PostgreSQL uses the most specific setting: one made for the role in one database (`ALTER ROLE app_role IN DATABASE app_db SET …`) wins over the role's, and the role's wins over the database's. So repeat step 1 on a new connection, through the pooler if the application uses one, and deploy the upgrade only once it prints `C`.
435
+
436
+ If you upgrade first, a `money` read fails with `RUNTIME.LC_MONETARY_NOT_C`. Under a locale with two fraction digits, such as `de_DE` or `en_GB`, nothing is stored wrong, and setting `lc_monetary` afterwards is enough.
437
+
438
+ Under a locale with no or three fraction digits, such as `ja_JP`, `ko_KR` or `ar_KW`, upgrading first also stores wrong amounts. PostgreSQL scales a written value by the locale's fraction digits, so `1234.56` is stored as 1235 units under `ja_JP`. After you set `lc_monetary` to `C`, those rows read back 100 times too small (or 10 times too large under a three-digit locale), with no error. If the application wrote `money` values between the upgrade and the change, correct those rows before you change the setting.
439
+
440
+ Raw SQL of your own that selects a `money` value as text printed the `C` form, `$1,234.56`, on Prisma's connections. It now prints in the database's locale.
441
+
442
+ The CLI needs nothing: it sets `lc_monetary` itself while it reads the database and applies migrations.
443
+
444
+
445
+ ## Dependencies: `pg` and `@types/pg` are peer dependencies, and `temporal-polyfill` moves to `^1.0.8`
446
+
447
+ ### `pg-is-a-peer-dependency`
448
+
449
+ Make this change before you run the package manager's install for the upgrade. A project that pins `pg` below 8.22.0 conflicts with the new peer range, and some package managers refuse to install until the range is fixed. If the install already failed on that conflict, make the change and run the install again.
450
+
451
+ In each `package.json` that `detection` matches and lists the Postgres package under `dependencies` or `devDependencies`:
452
+
453
+ 1. If `dependencies` has no `pg`, add `"pg": "^8.22.0"`. If it has one whose range allows any version outside `^8.22.0` (for example `8.20.0`, `^8.0.0`, `~8.21.0` or `>=8.20.0 <8.22.0`), change it to `^8.22.0`, so the install cannot keep an older version from the lockfile. If the range is a reference such as `catalog:` or `workspace:`, check the range it resolves to and change it there.
454
+ 2. If neither `devDependencies` nor `dependencies` has `@types/pg`, add `"@types/pg": "^8.20.0"` to `devDependencies`. If it has one whose range allows any version outside `^8.20.0`, change it to `^8.20.0`.
455
+
456
+ A project that already declares both inside those ranges needs no change.
457
+
458
+ A workspace library that lists the Postgres package only under `peerDependencies` does not get `pg` in its `dependencies`. Give it `pg` and `@types/pg` in `peerDependencies` with the same ranges, and in `devDependencies` if its own tests need them, so that it and the application share one copy.
459
+
460
+ Without `pg`, the application fails at startup because Node.js cannot find the package `pg`. Without `@types/pg`, TypeScript cannot resolve the `pg` types that Prisma 8's declarations import. Prisma 8's Postgres driver passes the `sslnegotiation` connection setting, which `pg` accepts from 8.22.0.
461
+
462
+ ### `temporal-polyfill-peer-range-moves-to-1-0-8`
463
+
464
+ In each `package.json`, or catalog in `pnpm-workspace.yaml`, that `detection` matches, change the `temporal-polyfill` range to `^1.0.8`, then reinstall. If the range is a reference such as `catalog:`, change the range it resolves to. A project that does not declare `temporal-polyfill` itself needs no change: its package manager installs the peer at a version inside the new range.
465
+
466
+
467
+ ## `PrismaNextConfig` is now `PrismaConfig`
468
+
469
+ ### `config-type-renamed-to-prisma-config`
470
+
471
+ In every file the detection matches, rename each import, re-export and type use of `PrismaNextConfig` to `PrismaConfig`. If the file already has its own `PrismaConfig`, import the type under an alias instead, such as `import type { PrismaConfig as PrismaToolchainConfig }`, and use the alias. Leave string literals that happen to contain the text alone; they are application values, not the type. Its type parameters do not change. Then run the project's formatter, since a shorter name can let an import fit on one line.
472
+
473
+ ```ts
474
+ // Before
475
+ import type { PrismaNextConfig } from '@prisma/orm-toolchain/cli/config-types';
476
+ const config: PrismaNextConfig<'sql', 'postgres'> = defineConfig({ /* ... */ });
477
+
478
+ // After
479
+ import type { PrismaConfig } from '@prisma/orm-toolchain/cli/config-types';
480
+ const config: PrismaConfig<'sql', 'postgres'> = defineConfig({ /* ... */ });
481
+ ```
482
+
483
+
484
+ ## Generated files import from the module the target package names
485
+
486
+ The target package an application's `prisma.config.ts` imports, such as `@prisma/orm-postgres`, now tells Prisma which modules generated files import from. The CLI no longer reads the application's `package.json` to work that out.
487
+
488
+ An application whose config calls a target package's `defineConfig` needs only the first change below.
489
+
490
+ ### `contract-types-import-from-the-target-package`
491
+
492
+ Run `prisma contract emit` and commit the regenerated `contract.json` and `contract.d.ts`.
493
+
494
+ The generated `contract.d.ts` now has one import statement for its framework, family and target types:
495
+
496
+ ```ts
497
+ import type { CodecTypes as PgTypes, Contract as ContractType, ContractWithTypeMaps } from '@prisma/orm-postgres/contract-types';
498
+ ```
499
+
500
+ where it had several, from `@prisma/orm-postgres/contract/types`, `@prisma/orm-postgres/family-contract/types` and `@prisma/orm-postgres/target/codec-types`. Each extension's types still come from the extension's own package.
501
+
502
+ In `contract.json`, each extension under `extensions` no longer records where its types are imported from: the `import` of its codec, operation and query operation types, its `typeImports` and its `parameterizedOutputTypes`. An extension's `types` entry disappears when nothing else is left in it. Nothing read these.
503
+
504
+ A file generated before the upgrade keeps working, because the modules it imports are still exported.
505
+
506
+ Leave the copies of the contract kept beside each migration, under `migrations/snapshots/`, as they are. They keep working, and no command rewrites a snapshot that already exists; only a snapshot written from now on has the new form. Do not edit them or any `migration.ts` by hand.
507
+
508
+ ### `hand-assembled-config-names-generated-file-modules`
509
+
510
+ This applies only to a config that imports `defineConfig` from `@prisma/orm-framework/config/config-types` or `@prisma/orm-toolchain/cli/config-types` and passes the family, target, adapter and driver itself. A config that calls a target package's `defineConfig` already names both modules.
511
+
512
+ Add `typesModule` to the `contract` section and `module` to the `migrations` section of the object passed to that `defineConfig`, leaving the rest of the file as it is:
513
+
514
+ ```ts
515
+ defineConfig({
516
+ family,
517
+ target,
518
+ adapter,
519
+ driver,
520
+ contract: { ...contractSource, typesModule: '#contract-types' },
521
+ migrations: { module: '@prisma/orm-target-postgres/target/migration' },
522
+ })
523
+ ```
524
+
525
+ - `contract.typesModule` names a module that exports the framework's contract types, the family's contract types and the target's codec and operation types. Write one in the application that re-exports them:
526
+
527
+ ```ts
528
+ // src/contract-types.ts
529
+ export type * from '@prisma/orm-framework/contract/types';
530
+ export type * from '@prisma/orm-family-sql/contract/types';
531
+ export type * from '@prisma/orm-target-postgres/target/codec-types';
532
+ export type * from '@prisma/orm-target-postgres/target/operation-types';
533
+ ```
534
+
535
+ and give it a name private to the application, in `package.json`:
536
+
537
+ ```json
538
+ { "imports": { "#contract-types": "./src/contract-types.ts" } }
539
+ ```
540
+
541
+ - `migrations.module` names the module that exports the migration base class and the target's operation helpers. For Postgres that is `@prisma/orm-target-postgres/target/migration`.
542
+ - Neither may be empty, a path or a URL. `'./contract-types'` is refused when the config is loaded, because generated files are written into more than one folder and a relative path is right for at most one of them.
543
+ - The application must depend directly on every package these modules import from. The target's and adapter's own types are imported from the target's package, such as `@prisma/orm-target-postgres`, so the application depends on that too.
544
+
545
+ ### `control-api-takes-types-module`
546
+
547
+ A script that calls the control client passes the module the generated contract types import from:
548
+
549
+ ```ts
550
+ await client.emit({ contractConfig: { source, output, typesModule } });
551
+ await client.renderContractDts({ contract, typesModule });
552
+ ```
553
+
554
+ Take the value from the config: `defineConfig(...).contract.typesModule`. For an application on a target package it is that package's `contract-types` entrypoint, such as `'@prisma/orm-postgres/contract-types'`.
555
+
556
+ A script that calls the control API's contract emit, `migration new` or `migration plan` operations directly, from `@prisma/orm-toolchain/cli/control-api`, removes the `projectDir` option. The operations read the module names from the config they are given.
557
+
558
+ ### `toolchain-publish-surface-entrypoints-removed`
559
+
560
+ Remove every import of `@prisma/orm-toolchain/publish-surface` and its two subpaths. They held the table and the functions that translated module names when files were generated. That translation no longer happens, so there is nothing to call in their place.
561
+
562
+
563
+ ## A TypeScript contract must be built for the config's target
564
+
565
+ ### `typescript-contract-for-another-target-refused`
566
+
567
+ For each file the detection matches that is a contract a `prisma.config.ts` names in `contract`, compare the package it imports `defineContract` from with the package the config imports `defineConfig` from. If they name different databases, change the contract's import to the `contract-builder` entry of the config's package, then run `prisma contract emit`. This also holds for a contract a PostgreSQL config passes as `typescriptContract(contract)`. If the two already match, nothing changes.
568
+
569
+ ```ts
570
+ // prisma.config.ts imports defineConfig from '@prisma/orm-postgres/config'
571
+
572
+ // Before
573
+ import { defineContract } from '@prisma/orm-sqlite/contract-builder';
574
+
575
+ // After
576
+ import { defineContract } from '@prisma/orm-postgres/contract-builder';
577
+ ```
578
+
579
+ ### `typescript-contract-from-path-requires-target`
580
+
581
+ In every file the detection matches, give each call of `typescriptContractFromPath` from `@prisma/orm-family-sql/contract-ts/config-types`, under whatever name the file imports it, all three arguments. Pass the output path second, or `undefined` to keep the default beside the contract. Pass as the third an object with `target`, the pack ref of the target the config is for, and `contractBuilderModule`, that target's `contract-builder` entry, such as `@prisma/orm-postgres/contract-builder`. Keep any `defaultControlPolicy` and `createNamespace` the call already passed beside them. The option types are exported from the same entry as `TypeScriptContractFromPathOptions` and `ConfigTarget`, though an object literal is enough. The loader then refuses a contract built for another target with `CONTRACT.TARGET_MISMATCH`.
582
+
583
+ ```ts
584
+ // Before
585
+ typescriptContractFromPath('prisma/contract.ts', 'prisma/contract.json', {
586
+ defaultControlPolicy: 'external',
587
+ createNamespace: postgresCreateNamespace,
588
+ });
589
+
590
+ // After
591
+ typescriptContractFromPath('prisma/contract.ts', 'prisma/contract.json', {
592
+ target: postgresPackRef,
593
+ contractBuilderModule: '@prisma/orm-postgres/contract-builder',
594
+ defaultControlPolicy: 'external',
595
+ createNamespace: postgresCreateNamespace,
596
+ });
597
+ ```
598
+
599
+ An application whose call passes neither `defaultControlPolicy` nor `createNamespace` can instead pass the contract's path to its target's `defineConfig`, such as `defineConfig({ contract: './prisma/contract.ts' })` from `@prisma/orm-postgres/config`, which calls `typescriptContractFromPath` with `target` and `contractBuilderModule` itself. `defineConfig` passes no control policy, so a call that sets one must keep calling `typescriptContractFromPath`.
600
+
601
+
602
+ ## `migrate` takes the target ref whole, and consents to a policy change
603
+
604
+ ### `migrate-options-ref`
605
+
606
+ ```ts
607
+ // Before
608
+ await client.migrate({
609
+ contract,
610
+ migrationsDir,
611
+ invocation,
612
+ refHash: entry.hash,
613
+ refInvariants: entry.invariants,
614
+ refName: 'production',
615
+ });
616
+
617
+ // After
618
+ await client.migrate({
619
+ contract,
620
+ migrationsDir,
621
+ invocation,
622
+ target: { kind: 'ref', ref: { name: 'production', ...entry } },
623
+ // or, for a contract hash rather than a ref: target: { kind: 'hash', hash },
624
+ // Only when the deploy should write the ref's declared policies into the database:
625
+ permitPolicyChange: true,
626
+ });
627
+ ```
628
+
629
+ `dbUpdate` takes the same `ref` for the ref `--to` named. Its hash must be the storage hash of the `contract` you pass, or the call returns a failure result with code `CLI.INVALID_ARGUMENTS` before it reads the database.
630
+
631
+ ### `db-sign-invocation`
632
+
633
+ `dbSign` takes a required `invocation`, `{ cwd, configPath, dbGiven }`. Pass the same `invocation` you pass to `migrate`.
634
+
635
+ ### `permit-policy-change`
636
+
637
+ A ref file may now carry `policies`:
638
+
639
+ ```json
640
+ {
641
+ "hash": "4b1c…e09a",
642
+ "invariants": [],
643
+ "policies": {
644
+ "change": ["migrate"],
645
+ "dataProtection": { "dataLoss": "data-loss-with-consent", "accessWidening": "access-widening-forbidden" }
646
+ }
647
+ }
648
+ ```
649
+
650
+ Code that writes ref files keeps the `policies` and `invariants` it read. Pass `permitPolicyChange: true` to `migrate` or `dbUpdate` only when the person running the deploy has said the ref's policies should be applied. A successful `migrate` that recorded policies returns them in `databasePoliciesUpdated`, one `{ setting, declared, inForce }` per setting it changed; `setting` is the key path in the ref's `policies` (`change`, `dataProtection.dataLoss`, `dataProtection.accessWidening`). `dbUpdate`'s result carries the same field.
651
+
652
+
653
+ ## Prisma schema files must be valid UTF-8
654
+
655
+ ### `psl-schema-must-be-utf8`
656
+
657
+ If `contract emit` or another command now fails with `PSL_SCHEMA_READ_FAILED` and the message says the encoded data is not valid UTF-8, the named schema file contains bytes in another encoding. A common case is a Windows-1252 character, such as an em dash, typed into a comment on Windows.
658
+
659
+ Reopen the file in the encoding it was written in, for example with your editor's "Reopen with Encoding" set to Windows-1252, then save it as UTF-8 and run the command again. Opening the file as UTF-8 and saving it does not help, because the editor keeps the replacement character instead of the original one. If the text was already saved with replacement characters, restore it from a good copy, such as version control.
660
+
661
+
662
+ ## PostgreSQL's `Json` is a convenience type, and `sql.String(n)` is `sql.Varchar(n)`
663
+
664
+ On PostgreSQL, `Json` is now a convenience type, as `Int` and `String` are. Its optional `storage` argument chooses the column: `Json` and `Json(storage: json)` are a `json` column, and `Json(storage: jsonb)` is a `jsonb` column. Written bare, `Json` gives the same `json` column as before, so schemas need no change and every contract stays the same. `Jsonb` is unchanged.
665
+
666
+ The explicit type of a `json` column is named `PlainJson`, and the column helper is renamed to match it.
667
+
668
+ On every SQL target, `sql.String(n)` is renamed `sql.Varchar(n)`, with `sql.String` kept as a deprecated alias.
669
+
670
+ ### `psl-renamed-sql-string`
671
+
672
+ `sql.String(n)` shared a name with the `String` convenience type and meant something else: a `varchar(n)` column. It is renamed `sql.Varchar(n)`. In each matched schema, replace `sql.String(` with `sql.Varchar(`, in fields and in `types {}` aliases:
673
+
674
+ ```prisma
675
+ model Label {
676
+ id Int @id
677
+ name sql.Varchar(50) // was sql.String(50)
678
+ }
679
+ ```
680
+
681
+ The contract does not change. `sql.Char(n)` keeps its name.
682
+
683
+ ### `ts-renamed-sql-string`
684
+
685
+ In each matched file, rename every `sql.String` call to `sql.Varchar`, including a call split across lines such as `type.sql` and `.String(64)` on the next line:
686
+
687
+ ```ts
688
+ field.column(type.sql.Varchar(50)); // was type.sql.String(50)
689
+ ```
690
+
691
+ The contract does not change.
692
+
693
+ ### `ts-renamed-postgres-json-column-helper`
694
+
695
+ The detection matches a file that imports or re-exports `jsonColumn` from `@prisma/orm-postgres/adapter/column-types` or `@prisma/orm-target-postgres/adapter/column-types`, or imports one of them as a namespace and reads `jsonColumn` from it. In that file, rename the import or re-export and every use of the name. Any other form, such as a dynamic import, fails type-checking because the export is gone; rename it where the compiler reports it:
696
+
697
+ ```ts
698
+ import { plainJsonColumn } from '@prisma/orm-postgres/adapter/column-types';
699
+
700
+ field.column(plainJsonColumn); // was jsonColumn
701
+ ```
702
+
703
+ `field.column(type.Json())` and `field.column(type.PlainJson())` give the same column. A file that imports `jsonColumn` from a SQLite package is covered by `ts-renamed-sqlite-column-helpers`, not this one.
704
+
705
+
706
+ ## SQLite scalars get convenience types
707
+
708
+ On SQLite, `Int`, `BigInt`, `Float`, `Decimal`, `String`, `Boolean`, `Bytes` and `Json` are now convenience types, as on PostgreSQL and MongoDB. Each chooses one explicit type: `Int` is `IntegerNumber`, `BigInt` is `IntegerBigInt`, `BigInt(as: number)` is `IntegerNumber`, `Float` is `Real`, `Decimal` is `DecimalString`, `String` is `Text`, `Boolean` is `IntegerBoolean`, `Bytes` is `Blob` and `Json` is `PlainJson`. An explicit type is named after the SQLite column type that stores it: `Text`, `Real` and `Blob`. `integer` is read by more than one codec of its data type, so those types carry the value too: `IntegerNumber` and `IntegerBigInt`. A type with a data type of its own, which a `text` column stores, is named after that data type: `DecimalString`, `PlainJson` and the date and time types. `IntegerBoolean` is a data type of its own that an `integer` column stores, so its name takes the form of the other `integer` types. Written bare, `Int`, `BigInt`, `Float`, `String`, `Bytes` and `Json` give the same codec as before.
709
+
710
+ Two names change the contract. A `Decimal` field gets its own codec, `sqlite/decimal@1`, where it was the same codec as `String`. `BigIntNumber` is a deprecated alias of `IntegerNumber`, so its codec id changes. Neither changes a column, and no data moves.
711
+
712
+ `Boolean` is new on SQLite: a schema can now write a `Boolean` field, or `type.Boolean()` in a TypeScript contract. It is an `integer` column holding 1 for `true` and 0 for `false`, which is what SQLite's own `TRUE` and `FALSE` are, with its own codec `sqlite/boolean@1`. `@default(true)` is written `DEFAULT 1`. A stored value other than 0 or 1 raises `RUNTIME.DECODE_FAILED`, naming the column. A field takes equality filters, and is not ordered or summed. No existing schema used it, so nothing changes for one.
713
+
714
+ `Int` and every other field on the codec `sqlite/integer@1` now checks that a value is an integer within the safe integer range, as `BigIntNumber` did; see `sqlite-integer-safe-range`.
715
+
716
+ A `BigInt` field now reads every stored 64-bit integer. Before, reading a row that held an integer outside ±(2^53 − 1) failed in `node:sqlite` with a `RangeError` whose code is `ERR_OUT_OF_RANGE`, so only a read through an `include()` or a `sumBigInt` gave the value. Nothing in the schema changes for it. A value read without an integer codec, such as a column of a raw SQL query, is now a `number` within the safe integer range and an exact `bigint` outside it, where the read threw before. `JSON.stringify` throws on a `bigint`, so code that serializes such a row prints the value with `String(value)`. A `BigInt` field also refuses to write a `bigint` outside the signed 64-bit range with `RUNTIME.ENCODE_FAILED`, where `node:sqlite` threw a `TypeError` before.
717
+
718
+ The column helpers of the TypeScript contract builder are renamed after the explicit type each gives, and `decimalStringColumn` and `integerBooleanColumn` are new.
719
+
720
+ ### Sign the database with the new contract
721
+
722
+ The `Decimal` and `BigIntNumber` changes below change the contract's storage hash, so `db verify` reports `CONTRACT.MARKER_MISMATCH` until the database is signed with the new contract. After re-emitting the contract:
723
+
724
+ - In a project with migrations, run `migration plan --from <latest migration>`, where `<latest migration>` is the name of the newest folder under `migrations/`. It writes a migration that names the changed table, and `db migrate` applies it and signs the database. When signing is the only change, the migration has no operations. It holds operations only for the other changes of this upgrade that you plan in it, as step 7 allows, such as the renames `sql-lowered-table-names-renamed` describes. No table is rebuilt for the `Decimal` and `BigIntNumber` changes. Without `--from`, `migration plan` starts from the `db` ref. A project that applied its migrations with `db migrate` before this release, without `--advance-ref`, has none, so the command refuses with `MIGRATION.PLAN_ORIGIN_UNKNOWN`.
725
+ - In a project without migrations, run `db update`. It runs no operation and signs the database.
726
+
727
+ `db verify --schema-only` passes before and after: the columns are the same.
728
+
729
+ ### `ts-renamed-sqlite-column-helpers`
730
+
731
+ The detection matches a file that imports or re-exports `integerColumn`, `bigintColumn` or `jsonColumn` from `@prisma/orm-sqlite/adapter/column-types` or `@prisma/orm-target-sqlite/adapter/column-types`, or imports one of them as a namespace and reads one of those names from it. In that file, rename the import or re-export and every use of the name:
732
+
733
+ | Old name | New name | Explicit type |
734
+ | --- | --- | --- |
735
+ | `integerColumn` | `integerNumberColumn` | `IntegerNumber`, codec `sqlite/integer@1` |
736
+ | `bigintColumn` | `integerBigIntColumn` | `IntegerBigInt`, codec `sqlite/bigint@1` |
737
+ | `jsonColumn` | `plainJsonColumn` | `PlainJson`, codec `sqlite/json@1` |
738
+
739
+ ```ts
740
+ import { integerNumberColumn, plainJsonColumn } from '@prisma/orm-sqlite/adapter/column-types';
741
+
742
+ field.column(integerNumberColumn); // was integerColumn
743
+ field.column(plainJsonColumn); // was jsonColumn
744
+ ```
745
+
746
+ Any other form, such as a dynamic import, fails type-checking because the export is gone; rename it where the compiler reports it. `field.column(type.Int())` and `field.column(type.IntegerNumber())` give the same column. A file that imports `jsonColumn` from a PostgreSQL package is covered by `ts-renamed-postgres-json-column-helper`, not this one. `textColumn`, `realColumn` and `blobColumn` keep their names. `decimalStringColumn` is new and gives `DecimalString`, codec `sqlite/decimal@1`, and `integerBooleanColumn` is new and gives `IntegerBoolean`, codec `sqlite/boolean@1`.
747
+
748
+ ### `sqlite-bigintnumber-deprecated`
749
+
750
+ This applies to a SQLite schema or TypeScript contract. On PostgreSQL, `BigIntNumber` is covered by the PostgreSQL scalar rename of an earlier release; skip this entry there.
751
+
752
+ In each matched SQLite schema, replace the type `BigIntNumber` with `BigInt(as: number)`, in fields, value object members and `types {}` aliases. In a SQLite TypeScript contract, replace `type.BigIntNumber()` with `type.BigInt({ as: 'number' })`. The deprecation warning names `IntegerNumber`, the explicit type, which gives the same contract as `BigInt(as: number)`; either is right:
753
+
754
+ ```prisma
755
+ model Post {
756
+ id Int @id
757
+ viewCount BigInt(as: number) // was BigIntNumber
758
+ }
759
+ ```
760
+
761
+ `Int` gives the same column too. The field's codec id changes from `sqlite/bigintnumber@1` to `sqlite/integer@1`, which writes and reads a `number` within the safe integer range, as `sqlite/bigintnumber@1` did; `sqlite-integer-safe-range` says what a value outside it raises. Re-emit the contract and sign the database as described above.
762
+
763
+ `sqlite/bigintnumber@1` stays: `count()` and the `sum` of an integer column still read their result through it, so a reference to it in generated `contract.d.ts` aggregate types is expected. A file that matches only because a comment or a string mentions `BigIntNumber` needs no change. Leave the `contract.prisma` copy inside each migration folder under `migrations/` as it is.
764
+
765
+ ### `sqlite-decimal-codec`
766
+
767
+ This applies to a schema whose target is SQLite. On PostgreSQL and MongoDB, `Decimal` does not change; skip this entry there. The detection matches every schema with a field or a `types {}` alias written `Decimal`, whatever its target.
768
+
769
+ Nothing in the schema changes. Re-emit the contract: each `Decimal` field's column now has codec `sqlite/decimal@1` and data type `sqlite/decimal` where it had `sqlite/text@1`. Then sign the database as described above.
770
+
771
+ `sqlite/decimal@1` reads and writes decimal text such as `"12.50"`, as before. It now refuses to write text that is not a decimal, and reading stored text that is not a decimal raises `RUNTIME.DECODE_FAILED`, naming the column. Such text is most often the `''` that an earlier migration wrote into the rows of a new required `Decimal` column; a new required column is now filled with `'0'`. Find those rows with this query, putting in each `Decimal` column and its table:
772
+
773
+ ```sql
774
+ SELECT rowid, "price"
775
+ FROM "product"
776
+ WHERE "price" IS NOT NULL
777
+ AND NOT (
778
+ typeof("price") = 'text'
779
+ AND ltrim("price", '-') <> ''
780
+ AND length("price") - length(ltrim("price", '-')) <= 1
781
+ AND ltrim("price", '-') NOT GLOB '*[^0-9.]*'
782
+ AND ltrim("price", '-') NOT GLOB '*.*.*'
783
+ AND ltrim("price", '-') NOT GLOB '.*'
784
+ AND ltrim("price", '-') NOT GLOB '*.'
785
+ );
786
+ ```
787
+
788
+ Set each row it returns to a decimal, such as `UPDATE "product" SET "price" = '0' WHERE "price" = '';`, or make the field optional and set it to `NULL`.
789
+
790
+ Stored text that is a decimal but has leading zeros or a minus sign on zero, such as `"0012.50"` or `"-0"`, stays as it is and still reads. An equality filter no longer finds it: the codec now writes a value, and compares a filter value, without the leading zeros or the minus sign on zero, so a filter for `"0012.50"` looks for `"12.50"`. This query returns those rows:
791
+
792
+ ```sql
793
+ SELECT rowid, "price"
794
+ FROM "product"
795
+ WHERE ltrim("price", '-') GLOB '0[0-9]*'
796
+ OR ("price" GLOB '-*' AND ltrim("price", '-0.') = '');
797
+ ```
798
+
799
+ Set each row it returns to the same number without the leading zeros or the minus sign on zero, such as `UPDATE "product" SET "price" = '12.50' WHERE "price" = '0012.50';`.
800
+
801
+ A `Decimal` field can be compared for equality only. Text compares by its characters, so `"1.5"` and `"1.50"` are different values, and ordering, the text filter `like` and aggregates such as `sum` and `max` are not offered; code that used them on a `Decimal` field no longer type-checks. A `Decimal` default may be written as text, `@default("12.50")`, or as a whole number, `@default(3)`. A number with a fraction, such as `@default(1.5)`, is refused when the contract is emitted, with `Expected a quoted string or a number that sqlite/decimal can hold; got sqlite/real`: write it as text, `@default("1.5")`.
802
+
803
+ Leave the `contract.prisma` copy inside each migration folder under `migrations/` as it is: it records the schema that migration was planned from.
804
+
805
+ ### `ts-sqlite-decimal-codec`
806
+
807
+ In a SQLite TypeScript contract, `type.Decimal()` and `type.DecimalString()` give the same column, with codec `sqlite/decimal@1`. The code does not change. Re-emit the contract and sign the database as described above; the notes under `sqlite-decimal-codec` about stored text that is not a decimal, equality and the column's values apply here too. A file that matches only because another library's `Decimal(` is called in it needs no change.
808
+
809
+ ### `sqlite-integer-safe-range`
810
+
811
+ This applies to a SQLite schema or TypeScript contract. On PostgreSQL and MongoDB, `Int` does not change; skip this entry there. The detection matches every schema with an `Int` field, whatever its target, because the change is to what the codec accepts, not to how the field is written.
812
+
813
+ Nothing in the schema or the contract changes. The codec `sqlite/integer@1`, which `Int`, `IntegerNumber`, `BigInt(as: number)` and the deprecated `BigIntNumber` give, now checks every value in both directions:
814
+
815
+ - A write of a number that is not an integer, such as `1.5`, or of an integer outside ±(2^53 − 1), the range a JavaScript `number` holds exactly, fails with `RUNTIME.ENCODE_FAILED` before any SQL runs, as in `sqlite/integer@1 value must be an integer within the safe integer range, got 1.5`. Before, the number was written as it was: SQLite stored `1.5` as a `real` in the `integer` column, and an integer past the range had already lost digits in the JavaScript `number` before it was written. Round the value in the application, or give the field `BigInt` if it needs the full 64-bit range.
816
+ - A read of a stored number that is not an integer, such as the `real` `1.5` an earlier write stored, fails with `RUNTIME.DECODE_FAILED` and names the table and column, as in `Column "line_item"."quantity" holds 1.5, which is not an integer within the safe integer range.` Before, a read of the row gave the number as it was, and a read through an `include()` already failed.
817
+ - A read of a stored integer outside the range fails with `RUNTIME.DECODE_FAILED` and names the table and column, in a row and through an `include()`, as in `Column "line_item"."quantity" holds 9007199254740993, which is not an integer within the safe integer range.` Before, a read of the row failed in `node:sqlite` before any codec ran, with a `RangeError` whose code is `ERR_OUT_OF_RANGE` and which named no column, and a read through an `include()` already raised `RUNTIME.DECODE_FAILED`.
818
+ - A stored blob fails with `RUNTIME.DECODE_FAILED` and names the table and column, in a row and through an `include()`, as in `Column "line_item"."quantity" holds bytes x'35', which is not an integer within the safe integer range.` `sql/int@1` reads a blob the same way. Before, some blobs were read as a number: in a row a one-byte blob read as the value of its byte, so `x'07'` read as 7, and a longer blob such as `x'3132'` was refused; through an `include()` a blob whose bytes spell digits read as that number, so `x'3132'` read as 12.
819
+
820
+ `sql/int@1`, which a TypeScript contract can name on SQLite, reads the same way: a stored number that is not an integer, an integer outside the range and a blob each raise `RUNTIME.DECODE_FAILED` naming the table and column. Before, it read a stored number in a row as it was.
821
+
822
+ Find such rows with this query, putting in each `Int` column and its table:
823
+
824
+ ```sql
825
+ SELECT rowid, "quantity"
826
+ FROM "line_item"
827
+ WHERE "quantity" IS NOT NULL
828
+ AND (
829
+ typeof("quantity") <> 'integer'
830
+ OR "quantity" > 9007199254740991
831
+ OR "quantity" < -9007199254740991
832
+ );
833
+ ```
834
+
835
+ Set each row it returns to an integer within the range. A fraction inside the range can be rounded, such as `UPDATE "line_item" SET "quantity" = CAST(round("quantity") AS INTEGER) WHERE typeof("quantity") = 'real' AND abs("quantity") <= 9007199254740991;`. A value outside the range cannot be repaired by a cast, which stops at the 64-bit limit and stays outside the range: set it to the value the application means, or change the field to `BigInt`, which reads the full 64-bit range. Run the query again afterward; the upgrade is done when it returns no rows. A project whose rows the query does not return needs no change.
836
+
837
+
838
+ ## MongoDB scalars get convenience types
839
+
840
+ On MongoDB, `Int`, `BigInt`, `Float`, `Decimal`, `Boolean`, `Bytes`, `String` and `Json` are now convenience types, as on PostgreSQL. Each chooses one explicit type named after the BSON type that stores it: `Int` is `Int32`, `BigInt` is `Int64BigInt`, `BigInt(as: number)` is `Int64Number`, `Float` is `Double`, `Decimal` is `Decimal128`, `Boolean` is `Bool`, `Bytes` is `Binary`, `String` is `BsonString` and `Json` is `PlainJson`. Every contract stays the same.
841
+
842
+ `Int`, `Float` and `Boolean` no longer warn, and `type.Int()`, `type.Float()` and `type.Boolean()` exist again. `BigInt`, `Bytes` and `Decimal`, which MongoDB refused before, now resolve.
843
+
844
+ ### `psl-renamed-mongo-int64`
845
+
846
+ In each matched schema, replace the type `Int64` with `BigInt`, the convenience type, or `Int64BigInt`, the explicit type. Do this in fields, value object members and `types {}` aliases. Leave `Int64Number` as it is, or write it `BigInt(as: number)`:
847
+
848
+ ```prisma
849
+ model Post {
850
+ id ObjectId @id @map("_id")
851
+ views BigInt // was Int64
852
+ }
853
+ ```
854
+
855
+ The contract does not change. A file that matches only because a comment or a string mentions `Int64` needs no change. Leave the `contract.prisma` copy inside each migration folder under `migrations/` as it is: it records the schema that migration was planned from, and `Int64` still reads there as the same type.
856
+
857
+ ### `ts-removed-mongo-int64-helper`
858
+
859
+ In each matched file, replace every `Int64` read from the `type` helpers with `BigInt` or `Int64BigInt`. This covers a call, a call split across lines, and a read with no call, such as `const long = type.Int64`:
860
+
861
+ ```ts
862
+ field.scalar(type.BigInt()); // was type.Int64()
863
+ ```
864
+
865
+ A helper taken out of `type` by destructuring, such as `const { Int64 } = type`, also matches. Take out `BigInt` or `Int64BigInt` instead and rename its calls. The contract does not change. A file that matches only because a comment mentions `.Int64`, or because it uses another library's `Int64`, such as Apache Arrow's `new arrow.Int64()`, needs no change.
866
+
867
+ ### `psl-optional-mongo-convenience-names`
868
+
869
+ This change is optional. In a MongoDB schema, `Int`, `Float` and `Boolean` are now the names to write, and they give exactly the same codecs as `Int32`, `Double` and `Bool`. To use them, replace the type `Int32` with `Int`, `Double` with `Float` and `Bool` with `Boolean`, in fields, lists, value object members and `types {}` aliases:
870
+
871
+ ```prisma
872
+ model Order {
873
+ id ObjectId @id @map("_id")
874
+ amount Int // was Int32
875
+ total Float // was Double
876
+ paid Boolean // was Bool
877
+ }
878
+ ```
879
+
880
+ The contract does not change. Do this only in a MongoDB schema: on other targets `Int32`, `Double` and `Bool` are different types or do not exist. Leave `Int32` in a codec id such as `mongo/int32@1`, and leave names that only start with these, such as a composite type named `DoubleValue`, as they are. Leave the `contract.prisma` copy inside each migration folder under `migrations/` as it is: it records the schema that migration was planned from.
881
+
882
+
883
+ ## A `hasOne` relation needs a unique key on the target
884
+
885
+ ### `has-one-key-must-be-unique`
886
+
887
+ A `hasOne` relation says that at most one row of the target model points at each row of this model. The SQL contract build now checks that the target's `by` fields are unique. They are unique when one of these covers exactly those fields, in any order:
888
+
889
+ - the target's primary key;
890
+ - a unique constraint (`.unique()` on the field, or `constraints.unique([...])` in `.attributes()`);
891
+ - a unique index (`constraints.index([...], { unique: true })` in `.sql()`) without a `where`.
892
+
893
+ A unique constraint over more fields than `by`, or over only some of them, does not count. When none matches, `prisma contract emit` and `defineContract` fail:
894
+
895
+ ```text
896
+ CONTRACT.RELATION_INVALID: Relation "User.profile" is one-to-one, but the fields "userId" of model "Profile" are not unique. Add a unique constraint over exactly those fields, or make "profile" a hasMany relation.
897
+ ```
898
+
899
+ In every file the detection matches, find each `rel.hasOne(Target, { by: ... })` whose `by` fields of `Target` are not unique, and apply one of the two fixes below. Then re-emit the contract with `prisma contract emit`.
900
+
901
+ #### Each parent has at most one related row: make the key unique
902
+
903
+ Add a unique constraint over exactly the `by` fields of the target model. For one field, use `.unique()`:
904
+
905
+ ```ts
906
+ // Before
907
+ const Profile = model('Profile', {
908
+ fields: {
909
+ id: field.column(int4Column).id(),
910
+ userId: field.column(int4Column),
911
+ },
912
+ });
913
+
914
+ // After
915
+ const Profile = model('Profile', {
916
+ fields: {
917
+ id: field.column(int4Column).id(),
918
+ userId: field.column(int4Column).unique(),
919
+ },
920
+ });
921
+ ```
922
+
923
+ For several fields, add `constraints.unique([fields.a, fields.b])` to the target's `.attributes()`. The contract's storage gains a unique constraint, so plan and apply a migration for it. The migration fails if the table already holds two rows with the same key; remove the duplicates first.
924
+
925
+ #### A parent can have several related rows: use `hasMany`
926
+
927
+ Replace `rel.hasOne(Target, { by })` with `rel.hasMany(Target, { by })`. The relation then reads as an array of rows instead of one row or `null`, so update the code that reads or writes it.
928
+
929
+
930
+ ## Constraints declared on a single-table variant
931
+
932
+ This applies to SQL contracts only; a MongoDB contract is not affected, though the detection also matches MongoDB `.prisma` files. A single-table variant is a model with `@@base(Base, "value")` and no `@@map`. Its rows are stored in the base model's table, next to the rows of the base and of every other variant.
933
+
934
+ ### `sti-variant-unscoped-index-refused`
935
+
936
+ #### A unique or an index without `where:` is refused
937
+
938
+ A unique constraint or a plain index on the shared table would also cover the other variants' rows. `prisma contract emit` used to drop these attributes from the contract. It now refuses each one at the attribute:
939
+
940
+ ```text
941
+ PSL_UNSCOPED_INDEX_ON_STI_VARIANT: Model "Bug" shares the table of its base model "Task" (single-table inheritance), so "@unique" would also cover the rows of other variants. Without a condition, only the backing index of one of its own relations is accepted. Scope it to this variant instead: @@index([ticket], unique: true, where: sql`type = 'bug'`)
942
+ ```
943
+
944
+ Without `where:`, only a plain `@@index` that backs one of the variant's own relations is still accepted: the index the relation's foreign key creates anyway, or the one its `index:` argument names. Another variant may not give the same index a different `name` or `map`, and it is not accepted over a column with a `@default`, since every row of the table gets that default.
945
+
946
+ A unique on a variant is always refused. A one-to-one relation from a single-table variant needs one, so it is not supported yet: the message for it says so and offers no partial index, which would not satisfy the relation. Make the relation one-to-many, or give the variant a table of its own with `@@map`.
947
+
948
+ In every file the detection matches, run `prisma contract emit` and find each `PSL_UNSCOPED_INDEX_ON_STI_VARIANT` it reports; leave the accepted forms above as they are. Replace each refused attribute with the `@@index` the message writes out: the same fields, `unique: true` for a unique one, and a `where:` condition that compares the base's discriminator column with the variant's value.
949
+
950
+ ```prisma
951
+ // Before
952
+ model Bug {
953
+ ticket String @unique
954
+
955
+ @@base(Task, "bug")
956
+ }
957
+
958
+ // After
959
+ model Bug {
960
+ ticket String
961
+
962
+ @@index([ticket], unique: true, where: sql`type = 'bug'`)
963
+ @@base(Task, "bug")
964
+ }
965
+ ```
966
+
967
+ These attributes were never in the contract before, so the new index is a change to storage: plan and apply a migration for it. A unique index fails to build if two rows of the variant already hold the same value; remove the duplicates first.
968
+
969
+ #### An `@@index` with `where:` is now stored
970
+
971
+ A variant's `@@index` with `where:` used to be dropped from the contract too. It now becomes a partial index on the base model's table. Re-emit the contract with `prisma contract emit`, then plan and apply a migration to create the index.
972
+
973
+ ### `sti-variant-foreign-keys-stored`
974
+
975
+ A relation with `fields:` on a variant now puts its foreign key on the base model's table. Before, it was dropped. The migration adds a backing index only when the relation derives one: a relation with `index: false` gets none, and one with `index: "<name>"` uses that index. Re-emit the contract with `prisma contract emit`, then plan and apply a migration to add them. The foreign key fails to build if a row already points at a missing row; fix those rows first.
976
+
977
+ When another model of the table maps the same column, it must declare the same relation: the same target, the same column pairs and the same referential actions. If it declares a different one, or maps the column as a plain field, the emit fails with `PSL_FOREIGN_KEY_CONFLICT_ON_STI_VARIANT`, because its rows would have to satisfy the foreign key too. It fails the same way when the relation's column has a `@default`, which every row of the table gets; remove the default. When the other foreign key is the base model's, keep only one of the two relations. Otherwise give the variant's field its own column with `@map`, in this order, so that no value is lost:
978
+
979
+ 1. Keep the old shared column. Add the variant's new column beside it, nullable and without a foreign key yet: map the field to the new column, and remove both the relation field and its back-relation on the relation's target model for now, since a back-relation without its relation fails with `PSL_ORPHANED_BACKRELATION`. If the other model of the table declares a relation on the old column, remove that relation and its back-relation for now too, and keep its scalar field. If the base model maps the old column as a plain field, the emit refuses the relation of every variant on it: give each of those variants its own new column in these steps, all at once, under a field name the base model does not use, and skip step 4, because no relation stays on the old column. A variant field that keeps the base model's field name but maps another column removes the base model's field from the contract, without an error. Then change the application's code to use the new field name on those variants: the old name still resolves there, to the base model's field on the old column, so code that writes it type-checks but no longer sets the relation. From the migration below until step 5 is done, keep the application from writing the variant's rows, for example with the application stopped or in a maintenance window: step 2 overwrites a value written to the new column before the copy, and a value written to the old column after the copy is lost. Then plan and apply a migration that adds the new column. Check that it does not drop the old column, which the other model of the table still maps, and that it adds no foreign key on the old column.
980
+ 2. Copy the values across for that variant's rows only, by discriminator value, as in `UPDATE actor SET human_contact_id = "contactId" WHERE kind = 'human'`.
981
+ 3. Check that every copied value has its target row, as in `SELECT human_contact_id FROM actor WHERE human_contact_id IS NOT NULL AND human_contact_id NOT IN (SELECT id FROM contact)`, which must return no rows.
982
+ 4. If you removed the relation of the other model of the table in step 1, clear the old column on the variant's rows, as in `UPDATE actor SET "contactId" = NULL WHERE kind = 'human'`, because that relation's foreign key will apply to every row of the table.
983
+ 5. Restore the relations you removed, the variant's on its new column, with their back-relations. Plan and apply the migration that adds their foreign keys, and drop the old column only when no model maps it any more.
984
+
985
+
986
+ ## Re-emit SQL contracts for the include capabilities
987
+
988
+ ### `re-emit-for-include-capabilities`
989
+
990
+ Run `prisma contract emit` for every SQL contract. The emitted `capabilities.sql` gains the new keys the adapter reports:
991
+
992
+ ```json
993
+ "sql": {
994
+ "jsonAgg": true,
995
+ "jsonAggWithoutTruncation": true,
996
+ "outerReferencesInDerivedTables": true
997
+ }
998
+ ```
999
+
1000
+ A MariaDB contract gains only `"jsonAgg": true`: MariaDB does not report the other two, and the emitter leaves out a capability that is `false`. Without them the ORM loads includes on MariaDB with one query per relation.
1001
+
1002
+
1003
+ ## MySQL and MariaDB: scalars get convenience types, and the ORM's aggregates run
1004
+
1005
+ On MySQL and MariaDB, `Int`, `BigInt`, `Float`, `Decimal`, `String`, `Boolean`, `Bytes` and `Json` are now convenience types, as on PostgreSQL, SQLite and MongoDB. Each chooses one explicit type named after the MySQL column type that stores it: `Int` is `Int4`, `BigInt` is `Int8BigInt`, `BigInt(as: number)` is `Int8Number`, `Float` is `Float8` (a `double`), `Decimal` is `NumericString(65, 30)`, `String` is `Varchar(191)` and `String(storage: text)` is `Text`, `Boolean` is `Bool` (a `tinyint(1)`), `Bytes` is `Longblob` and `Json` is `PlainJson`. A field written `Int`, `BigInt` or `String` gives the same codec as before, so no schema needs a change.
1006
+
1007
+ The two entries below both ask for the contract to be emitted again; one `prisma contract emit` covers both.
1008
+
1009
+ ### `re-emit-mysql-contract-for-aggregates`
1010
+
1011
+ Run `prisma contract emit` for every MySQL or MariaDB contract. The emitted `contract.d.ts` replaces `export type AggregateTypes = Record<string, never>;` with the aggregate overloads the MySQL target contributes, so TypeScript offers `count()`, `sum()`, `avg()`, `min()` and `max()` in `include('posts', (p) => p.count())`, `combine()` and `aggregate()`. Apart from the capabilities `re-emit-for-include-capabilities` describes, nothing else changes, and no database needs migrating or signing again.
1012
+
1013
+ On MySQL and MariaDB, `count` and `sum` over integers read as a JavaScript `number`, and fail with `RUNTIME.DECODE_FAILED` rather than round a value outside ±(2^53 − 1); `countBigInt` and `sumBigInt` read as a `bigint`. `avg` over an integer reads the mean as a `number`, computed as `CAST(SUM(x) AS DOUBLE) / COUNT(x)`, so it is the same whichever plan the server picks.
1014
+
1015
+ ### `mysql-reemit-contract`
1016
+
1017
+ In each matched project, emit the contract again:
1018
+
1019
+ ```bash
1020
+ pnpm prisma contract emit
1021
+ ```
1022
+
1023
+ The generated `contract.d.ts` gains entries under `AggregateTypes` for the new codecs, such as `sum` over `mysql/decimal@1` and `avg` over `mysql/double@1`. The hashes in `contract.json` do not change, so the database's signature stays as it is and no migration is needed; `contract.json` changes only by the capabilities `re-emit-for-include-capabilities` describes. Leave the `contract.d.ts` copy inside each migration snapshot under `migrations/snapshots/` as it is.
1024
+
1025
+
1026
+ ## Contracts that record an extension's version
1027
+
1028
+ ### `contract-artifacts-restamp`
1029
+
1030
+ For every `contract.json` matched by `detection`, run the project's emit command (`prisma contract emit`, or the project's `contract:emit` script) once after upgrading. This entry accounts for the extension's embedded `version` moving to `8.0.0-rc.25`; any other difference in the emitted files comes from an earlier entry in this guide.
1031
+
1032
+
1033
+ ## A changed stored name is a rename on PostgreSQL and SQLite
1034
+
1035
+ A model, field or enum member with the same name in the contract source on both sides of a change is now the same object. When only what it is stored as changes, `migration plan` and `db update` rename the storage or replace the value. This applies on PostgreSQL and SQLite, with a snapshot of the contract the database is at. MySQL and MongoDB plan these changes as before.
1036
+
1037
+ ### `sql-stored-name-change-is-a-rename`
1038
+
1039
+ Before, changing `@@map("users")` to `@@map("people")` on `model User` planned a drop of `users` and a create of `people`, and asked for `--delete User`. To keep the rows you renamed the table by hand: with `db update`, in the database; with `migration plan`, by writing `...this.renameTable({ table: 'users', to: 'people' })` into a `migration.ts` of its own.
1040
+
1041
+ Now the same change plans a rename of table `users` to `people` and the renames of its constraints (on PostgreSQL the plan prints `Rename table "users" to "people"`, on SQLite `Rename table users to people`), and asks nothing. A changed `@map` plans a column rename. An enum member that keeps its name and changes its stored value, such as `ARCHIVED = "archived"` to `ARCHIVED = "old"`, has the value replaced in every column the enum types in a table whose control policy is `managed`. A column in a table whose control policy is not `managed` keeps the old value: rewrite its values yourself. A table or column is renamed only when everything stored in it moves and its control policy is `managed` in both contracts; a variant that gains or loses a table of its own is still asked about.
1042
+
1043
+ Stop renaming by hand. Make the contract change and plan it. Migrations you already wrote by hand stay as they are.
1044
+
1045
+ ### `sql-stored-name-delete-is-unused`
1046
+
1047
+ Before:
1048
+
1049
+ ```bash
1050
+ prisma migration plan --name move-users --delete User
1051
+ ```
1052
+
1053
+ Now this fails with `CLI.CONSENT_UNUSED`, since nothing asks about `User`. Remove the `--delete` from the script:
1054
+
1055
+ ```bash
1056
+ prisma migration plan --name move-users
1057
+ ```
1058
+
1059
+ A `--rename User:User` statement still fails with `MIGRATION.STATEMENT_INVALID`. Remove it too.
1060
+
1061
+ ### `sql-stored-name-empty-table`
1062
+
1063
+ Before, a changed `@@map` gave you an empty table under the new name once you answered `--delete User`. Now it keeps the rows. To start empty, make two changes, each planned and applied before the next:
1064
+
1065
+ 1. Remove `model User` from the schema, plan, and answer `--delete User`.
1066
+ 2. Add `model User` back with `@@map("people")`, and plan again.
1067
+
1068
+ ### `sql-stored-name-swaps-refused`
1069
+
1070
+ Before, two models that swapped tables (`User` from `users` to `accounts` and `Account` from `accounts` to `users`) planned no drop and no create: each table was altered in place and then held the other model's rows. Now the plan fails with `MIGRATION.PLANNING_FAILED`, as in:
1071
+
1072
+ ```text
1073
+ Cannot rename table "accounts" to "users": table "users" is renamed in the same plan
1074
+ ```
1075
+
1076
+ The same holds for two fields that swap columns, a chain where one model or field moves to a name another frees, a model or field that takes the storage of one the change removes, and enum members that swap stored values or take the stored value of a removed member. Follow the message: make the change in two plans, each planned and applied before the next, through names nothing uses, such as `prisma_swap_users`, or, for a takeover, by first removing the model, field or enum member that holds the name. When that first plan removes an enum member and you answer `--delete`, a required column cannot keep the member's rows: delete them, or set them to a value the enum keeps, before the plan applies.
1077
+
1078
+ When the two tables or columns have the same shape and nothing else changes, the storage does not change at all, so `migration plan` still reports no change and writes nothing; `db update` refuses the swap. Make such a swap through a name nothing uses in the same way.
1079
+
1080
+ ### `sql-lowered-table-names-renamed`
1081
+
1082
+ Before, a model with no `@@map` whose table still had the name an earlier release gave it, with the first letter lowered (`userProfile` for `model UserProfile`), was refused with `MIGRATION.TABLE_NAME_CASE_CHANGED` when planned from a snapshot that named the lowered table. Now, from such a snapshot, the plan renames `userProfile` to `UserProfile` with no question.
1083
+
1084
+ To keep the lowered name, add it with `@@map` before you plan:
1085
+
1086
+ ```prisma
1087
+ model UserProfile {
1088
+ id Int @id
1089
+
1090
+ @@map("userProfile")
1091
+ }
1092
+ ```
1093
+
1094
+
1095
+ ## MongoDB plans rewrite value objects, embedded models, enum values and variants
1096
+
1097
+ ### `mongo-nested-removals-are-asked`
1098
+
1099
+ Where `migration plan` or `db update` now stops with a question, or with `CLI.CONSENT_REQUIRED` when nobody can answer, give the statement that says what the change means:
1100
+
1101
+ - A field a value object or an embedded model loses: `--rename Address.street:Address.line1` if it was renamed, or `--delete Address.street` to remove the key from every object (`removeStoredKey`).
1102
+ - A stored value an enum loses: `--rename Status.ARCHIVED:Status.<new name>` to keep the documents under another member, or `--delete Status.ARCHIVED` to unset it in optional fields and take it out of lists (`removeStoredValue`). Where a required field holds it, the apply stops with `MIGRATION.PRECHECK_FAILED`, counts the documents and gives the edit that keeps them.
1103
+ - A variant whose discriminator value changes: `--convert Bug` to rewrite the value, or `--delete Bug` to delete its documents (`deleteDocuments`).
1104
+ - A variant the contract removes: `--rename Bug:Issue` if it was renamed, or `--delete Bug` to delete its documents (`deleteDocuments`).
1105
+
1106
+ A script that runs these commands with `--yes` and no statements now fails with `CLI.CONSENT_REQUIRED`; add the statements it lists.
1107
+
1108
+ ### `mongo-nested-statements-are-planned`
1109
+
1110
+ A script or test that expects these statements to fail with `MIGRATION.PLANNING_FAILED` on MongoDB now gets a plan. A plan in which one operation writes a field, key or value that another operation of the same plan reads is still refused, with advice to make the change in two migrations: field, key and enum value renames that trade names or values or form a chain, a new required field under the name a rename moves away, a rename onto a name whose field the origin also stores, and variant changes where one variant takes a discriminator value another frees. MongoDB applies operations one at a time, so the later operation would act on what the earlier one wrote, or a re-run after a later operation stops would rewrite those documents twice.
1111
+
1112
+ If you rewrote such documents by hand in `mongosh` or in a `dataTransform` because the statement was refused, nothing changes for migrations you already applied.
1113
+
1114
+ ### `mongo-nested-required-field-gets-temporary-value`
1115
+
1116
+ To write your own value instead, plan the change with `migration plan --backfill Address.zip` and write an aggregation expression in the `placeholder('Address.zip:value')` slot of each `fillStoredKey` it writes, such as `{ $literal: 'unknown' }`. A field whose type has no temporary value, such as a date, gets none, and the validator change's document check stops the apply while objects lack it; use `--backfill` for it.
1117
+
1118
+
1119
+ ## Names and keys that JavaScript objects inherit
1120
+
1121
+ Names such as `constructor` and `toString` now work everywhere as model, table, column and field names, and need no action. Three cases with `__proto__` do.
1122
+
1123
+ ### `json-default-proto-key-kept`
1124
+
1125
+ ```prisma
1126
+ model User {
1127
+ id Int @id
1128
+ meta Jsonb @default(json`{ "__proto__": { "x": 1 }, "a": 2 }`)
1129
+ }
1130
+ ```
1131
+
1132
+ `prisma contract emit` used to leave the `__proto__` key out of `contract.json` and out of the storage hash, so the database got the default `{"a": 2}`. It now keeps the key. For each file the detection matches:
1133
+
1134
+ 1. Run `prisma contract emit`. The storage hash changes.
1135
+ 2. Run `prisma migration plan` and apply the migration, or run `prisma db update`. Either plans one operation per such column, `Set default on "<table>"."<column>"`.
1136
+
1137
+ Until the operation is applied, the SQL runtime logs `CONTRACT.MARKER_MISMATCH` as a warning and still runs queries. If you do not want the key in the default, remove it from the contract source instead.
1138
+
1139
+ ### `mongo-proto-names-refused`
1140
+
1141
+ JavaScript reads `__proto__` as the prototype of an object rather than as a key, so a contract could not hold such a name: the client lost the model or collection. A MongoDB contract now refuses it. The TypeScript builder raises `CONTRACT.NAME_UNUSABLE_AS_KEY`; a PSL contract reports `PSL_STORED_NAME_UNSUPPORTED` at the declaration:
1142
+
1143
+ ```text
1144
+ A model is named "__proto__", which JavaScript reads as the prototype of an object rather than as a key. Choose another name.
1145
+ ```
1146
+
1147
+ In a PSL contract, an enum named `__proto__` is not refused: it is left out of the contract without an error, together with every field typed by it.
1148
+
1149
+ Rename the model, composite type, enum or root. For a collection, name another collection with `@@map`. `@@map` only changes which collection the client reads and writes: documents already in a collection named `__proto__` stay there, so rename that collection in the database to the new name (`renameCollection`) in the same deployment. The TypeScript builder also refuses an object literal with a `__proto__` key, such as `models: { __proto__: Post, User }`, which used to drop the entry without an error.
1150
+
1151
+ ### `sql-proto-names-refused`
1152
+
1153
+ A SQL contract refuses the same name. A namespace, table, column, model, field or enum named `__proto__`, including a stored name given with `@@map("__proto__")` or `@map("__proto__")`, fails `prisma contract emit` with:
1154
+
1155
+ ```text
1156
+ CONTRACT.NAME_UNUSABLE_AS_KEY: A table in namespace "public" is named "__proto__", which JavaScript reads as the prototype of an object rather than as a key. Choose another name.
1157
+ ```
1158
+
1159
+ Choose another name. In a TypeScript contract, an object literal with a `__proto__:` key is refused too; it used to drop the entry without an error. Such a contract did not work before: the entry was dropped or the contract came out wrong.
1160
+
1161
+ A SQL query builder `select` that names a result column `__proto__` is refused with `RUNTIME.AST_INVALID`; choose another alias.
1162
+
1163
+
1164
+ ## Concurrent work on `tx` during an ORM write
1165
+
1166
+ ### `orm-write-inside-transaction-suspends-tx`
1167
+
1168
+ Inside `db.transaction(async (tx) => ...)`, where an ORM write of several statements runs at the same time as other work on `tx`, for example in `Promise.all`, await the write before sending the other work:
1169
+
1170
+ ```ts
1171
+ await tx.orm.public.Post.create({ title, author: (author) => author.create(user) });
1172
+ await tx.execute(plan);
1173
+ ```
1174
+
1175
+ On any SQL database, when such a write fails with an error that ends the whole transaction, such as a deadlock on MySQL or MariaDB, the rollback to the savepoint fails too. The write then rejects with `RUNTIME.TRANSACTION_ROLLBACK_FAILED`, whose `cause` is the database's error, and the transaction is closed. Before, it rejected with the database's error itself. Code that retries on the database's deadlock error reads that error from `error.cause`.
1176
+
1177
+
1178
+ ## `update()` data refuses a foreign key together with a callback on its relation
1179
+
1180
+ ### `foreign-key-with-relation-callback-refused`
1181
+
1182
+ `update()` data that sets the foreign key the record holds for a relation and also has a callback on that relation is now refused, whatever the callback returns (`create`, `connect`, `disconnect`, `update` or `delete`). The ORM refuses it while it plans the write, before any statement runs, with:
1183
+
1184
+ ```text
1185
+ ORM.ARGUMENT_INVALID: update() data sets "authorId", the foreign key of relation "author", and also has a callback on "author"; set the foreign key or use the callback
1186
+ ```
1187
+
1188
+ `meta.relation` names the relation and `meta.fields` the foreign-key fields the data sets. A foreign-key field whose value is `undefined` does not count. It is not a type error.
1189
+
1190
+ Such data used to run, and a `create`, `connect` or `disconnect` callback silently overwrote the foreign key the data set.
1191
+
1192
+ For each such call, keep one of the two. To point the record at another row, set the foreign key, or use `connect` on the relation:
1193
+
1194
+ ```ts
1195
+ // before
1196
+ await db.orm.public.Post.where({ id: 10 }).update({
1197
+ authorId: 2,
1198
+ author: (author) => author.connect({ id: 2 }),
1199
+ });
1200
+
1201
+ // after
1202
+ await db.orm.public.Post.where({ id: 10 }).update({
1203
+ author: (author) => author.connect({ id: 2 }),
1204
+ });
1205
+ ```
1206
+
1207
+ The relation callback's `update` and `delete` are new in this release. To use one of them on the row the record points at and also point the record at another row, make two calls: first the callback, then the foreign key. Run them in one transaction, so that both changes apply or neither does. Where the foreign key is required, the callback's `delete` is refused: set the foreign key first, then delete the old row through its own collection.
1208
+
1209
+ ```ts
1210
+ await db.transaction(async (tx) => {
1211
+ await tx.orm.public.Post.where({ id: 10 }).update({
1212
+ author: (author) => author.update({ name: 'Ada' }),
1213
+ });
1214
+ await tx.orm.public.Post.where({ id: 10 }).update({ authorId: 2 });
1215
+ });
1216
+ ```
1217
+
1218
+
1219
+ ## Update data cannot set the discriminator of a polymorphic model
1220
+
1221
+ ### `update-data-refuses-discriminator`
1222
+
1223
+ `update()`, `updateAll()`, `updateAndCount()`, the `update` data of `upsert()` and a nested `updateAll` no longer take the discriminator field of a polymorphic model. Setting it is a type error, and at run time it is refused with `ORM.FIELD_IMMUTABLE` before any statement runs. Before, the update changed the discriminator in the base table only, so the row's variant data no longer matched it.
1224
+
1225
+ Remove the discriminator from the update data. To move a row to another variant, delete it and create it as that variant.
1226
+
1227
+
1228
+ ## A unique key with a nullable column is no row identity
1229
+
1230
+ ### `nullable-unique-key-is-no-row-identity`
1231
+
1232
+ The ORM matches rows by their primary key, or else by a unique key. It now skips a unique key that has a nullable column, because two rows can both hold `NULL` in it. If such a key is the only one a table has, the table has no row identity, and these calls fail with `ORM.ROW_IDENTITY_MISSING`:
1233
+
1234
+ - `update()` and `delete()`, on every database.
1235
+ - `create()`, `createAll()`, `update()`, `updateAll()` and `upsert()` after `.include(...)`, on every database.
1236
+ - On a database without `RETURNING`: `create()`, `createAll()` and `updateAll()` that return rows, since they read their rows back by key.
1237
+ - On a database whose adapter does not report `sql.jsonAgg`, `sql.outerReferencesInDerivedTables` and `sql.jsonAggWithoutTruncation`: any read with an include of that table, at any level, and `deleteAll()` after `.include(...)`, since the included rows are matched to their parents by key.
1238
+
1239
+ `deleteAll()` on such a table, where it must read the rows before deleting them, deletes by the caller's condition, as it does on any table with no primary key or unique constraint.
1240
+
1241
+ Find each model whose table has no `@id` and whose `@unique` or `@@unique` fields include an optional one. Then do one of these:
1242
+
1243
+ - Add a primary key to the table (`@id` or `@@id`), and create a migration for it.
1244
+ - Make the unique key's fields required, so its columns are `NOT NULL`, and create a migration for it.
1245
+
1246
+
1247
+ ## Nested relation mutation errors use the general ORM codes
1248
+
1249
+ ### `relation-mutation-error-codes-merged`
1250
+
1251
+ Replace every comparison with the old codes:
1252
+
1253
+ - `ORM.RELATION_MUTATION_INVALID` becomes `ORM.ARGUMENT_INVALID`.
1254
+ - `ORM.RELATION_MUTATION_UNSUPPORTED` becomes `ORM.OPERATION_UNSUPPORTED`.
1255
+
1256
+ The `meta` of these errors keeps its fields (`kind`, `relation`, `problem`, `reason` and the others). Code that needs to tell a nested relation mutation error from another error with the same code can check `meta.relation`, which the nested relation mutation errors with these two codes carry.
1257
+
1258
+
1259
+ ## A nested create on a polymorphic model names its variant
1260
+
1261
+ ### `nested-create-on-polymorphic-target-needs-variant`
1262
+
1263
+ The mutator a relation callback receives for a polymorphic base model now has `variant(value)`, which takes a discriminator value the model declares, as a collection's `variant()` does. Its `create(data)` writes a complete row of that variant, including the row of a variant stored in its own table. `r.create(data)` on such a mutator now takes no data, as a collection's `create()` on a polymorphic base model without `variant()` does, so each such call is a type error. Run the project's typecheck to find them.
1264
+
1265
+ For each call, take the value of the discriminator field from the data, pass it to `variant(...)` and remove the field from the data:
1266
+
1267
+ ```ts
1268
+ // before
1269
+ await db.orm.public.Project.where({ id: 1 }).update({
1270
+ tasks: (tasks) => tasks.create({ title: 'Crash on login', type: 'bug' }),
1271
+ });
1272
+
1273
+ // after
1274
+ await db.orm.public.Project.where({ id: 1 }).update({
1275
+ tasks: (tasks) => tasks.variant('bug').create({ title: 'Crash on login' }),
1276
+ });
1277
+ ```
1278
+
1279
+ The data of `r.variant(value).create(...)` takes the variant's own fields too, such as `severity` for the `bug` variant, and requires those the variant requires; add them where the type check asks for them. When the rows of one call have different discriminator values, split it into one `variant(value).create(...)` per value and return them as an array from the callback.
1280
+
1281
+ A variant stored in its own table needs the contract capability `returning`; without it the call is refused with `ORM.CAPABILITY_MISSING`, as `create()` on that variant collection is.
1282
+
1283
+ ### `variant-create-without-returning-names-create`
1284
+
1285
+ On a contract without the `returning` capability, `db.orm.public.Task.variant('feature').create(data)` for a variant stored in its own table is refused with `ORM.CAPABILITY_MISSING`. Its message is now `create() requires contract capability "returning"` and its `meta.action` is `'create()'`; they used to name `createAll()`. `createAll()` on the variant still names `createAll()`. Code or tests that match this error of a `create()` call by its message or by `meta.action === 'createAll()'` match `create()` instead.
1286
+
1287
+
1288
+ ## `disconnect` on a required relation is refused, and to-one `disconnect` applies its criteria
1289
+
1290
+ ### `disconnect-on-required-relation-refused`
1291
+
1292
+ `r.disconnect()` in the data of `update()` sets the foreign key of the relation to null. When the record holds the key (a many-to-one relation, such as `Post.author`, which is also the side of a one-to-one that holds the key), that is the record's own key; when the related rows hold the key (one-to-many, or one-to-one from the side without the key), it is the key of the related rows. When that key is required, the database refused the statement with a NOT NULL error, which reached the caller unwrapped. When the related rows hold the key and no related row was changed, because `disconnect(criteria)` matched none of them or, without criteria, the record had no related rows, the statement changed nothing and succeeded; such a call is now refused as well, like every `disconnect` on that relation.
1293
+
1294
+ Such a call is now a type error, on an emitted `contract.d.ts` and on a contract built with the TypeScript contract builder. Run the project's typecheck to find them. At run time, the ORM refuses it while it plans the write, before any statement runs, with:
1295
+
1296
+ ```text
1297
+ ORM.OPERATION_UNSUPPORTED: disconnect() nested mutation for relation "author" cannot set "userId" of model "Post" to null, because the foreign key is required
1298
+ ```
1299
+
1300
+ `meta.reason` is `'required-foreign-key'`, `meta.model` names the model that holds the key and `meta.fields` its fields. Because nothing has been written, the whole `update()` is refused, including its own field changes.
1301
+
1302
+ For each such call, decide what should become of the row that holds the key. The refusal names it: when `meta.model` is the model being updated, the record holds the key; otherwise the related rows hold it.
1303
+
1304
+ When the record holds the key (a many-to-one relation, such as `Post.author`), the key is on the record being updated:
1305
+
1306
+ - To link the record to another row, use `connect` on the same relation instead:
1307
+
1308
+ ```ts
1309
+ // before
1310
+ await db.orm.public.Post.where({ id: 10 }).update({
1311
+ author: (author) => author.disconnect(),
1312
+ });
1313
+
1314
+ // after
1315
+ await db.orm.public.Post.where({ id: 10 }).update({
1316
+ author: (author) => author.connect({ id: 2 }),
1317
+ });
1318
+ ```
1319
+
1320
+ - To remove the record, delete it with its own collection, for example `db.orm.public.Post.where({ id: 10 }).delete()`.
1321
+
1322
+ When the related rows hold the key (one-to-many, or one-to-one from the side without the key), the key is on the related rows:
1323
+
1324
+ - To move them to another record, use `connect` on that record instead:
1325
+
1326
+ ```ts
1327
+ // before
1328
+ await db.orm.public.User.where({ id: 1 }).update({
1329
+ posts: (posts) => posts.disconnect([{ id: 10 }]),
1330
+ });
1331
+
1332
+ // after
1333
+ await db.orm.public.User.where({ id: 2 }).update({
1334
+ posts: (posts) => posts.connect({ id: 10 }),
1335
+ });
1336
+ ```
1337
+
1338
+ - To remove them, delete them: `r.where(filter).delete()` for one row or `r.where(filter).deleteAll()` for every match on a one-to-many relation, `r.delete()` on a one-to-one relation, or the related model's own `delete()`.
1339
+
1340
+ In both cases, if the row that holds the key may exist without the row it points at, make the foreign key optional in the contract (`.optional()` on the field, or `?` in PSL), re-emit the contract and migrate the column to nullable. `disconnect` is then available.
1341
+
1342
+ Code that caught the database's NOT NULL error of such a call catches `ORM.OPERATION_UNSUPPORTED` with `meta.reason === 'required-foreign-key'` instead.
1343
+
1344
+ ### `to-one-disconnect-criteria-applied`
1345
+
1346
+ On a relation the record holds the key for, such as `author` on a post, `r.disconnect(criteria)` used to set the record's foreign key to null whatever row it was linked to; the criteria had no effect. It now sets it to null only when the linked row matches one of the criteria. Otherwise the foreign key stays unchanged, with no error, and the other updates of the same `update()`, such as changes to the record's own fields, still apply. `r.disconnect()` without criteria is unchanged.
1347
+
1348
+ This applies to a relation whose foreign key is optional. On a relation whose foreign key is required, every `disconnect`, with or without criteria and on a variant too, is refused with `ORM.OPERATION_UNSUPPORTED` (`reason: 'required-foreign-key'`) before its criteria or variant are looked at; see `disconnect-on-required-relation-refused`.
1349
+
1350
+ Find each `disconnect([...])` in a relation callback for a many-to-one relation. Where the call is meant to unlink the record whatever it is linked to, drop the criteria:
1351
+
1352
+ ```ts
1353
+ // before
1354
+ await db.orm.public.Post.where({ id: 1 }).update({
1355
+ editor: (editor) => editor.disconnect([{ id: 7 }]),
1356
+ });
1357
+
1358
+ // after, when the post should be unlinked from any editor
1359
+ await db.orm.public.Post.where({ id: 1 }).update({
1360
+ editor: (editor) => editor.disconnect(),
1361
+ });
1362
+ ```
1363
+
1364
+ Where the call is meant to unlink only from that row, keep it. Code that read the record back and expected the key to be null after a call whose criteria did not match the linked row now reads the unchanged key.
1365
+
1366
+ On a relation whose target is a polymorphic model and whose foreign key is optional, `r.variant(value).disconnect(criteria?)` is also available: it unlinks the record only when the linked row is of that variant and, when criteria are given, matches one of them.
1367
+
1368
+ ### `disconnect-empty-criteria-disconnects-nothing`
1369
+
1370
+ `r.disconnect([])` with an explicit empty list of criteria used to behave as `r.disconnect()` without criteria: it unlinked the record on a relation the record holds the key for, and every related row on a one-to-many or one-to-one relation. An empty list now matches no row, so the call disconnects nothing; other updates in the same `update()` still apply. Many-to-many `disconnect([])` is still refused with `ORM.ARGUMENT_INVALID`. On a relation whose foreign key is required, `disconnect([])` is refused like every other `disconnect` (see `disconnect-on-required-relation-refused`).
1371
+
1372
+ Find each `disconnect(...)` whose criteria list can be empty, such as one built from a filtered array. Where the call is meant to unlink everything when the list is empty, call `disconnect()` without criteria in that case.
1373
+
1374
+
1375
+ ## `onConflict: 'skip'` refuses rows that cannot conflict
1376
+
1377
+ ### `create-all-skip-refuses-rows-without-conflict-key`
1378
+
1379
+ With `onConflict: 'skip'`, `createAll` and `createAndCount` watch the fields named in `conflictOn` when given, and otherwise every primary key, unique constraint and unique index over columns of the table. A row can conflict when it gives a non-null value for every field of at least one of those keys. Values count when the row gives them or when the ORM fills them in from a create default such as `uuid()`, `cuid()` or `now()`. A column the database fills in (auto-increment, a database default) and `null` do not count.
1380
+
1381
+ A call with a row that cannot conflict now throws `ORM.ARGUMENT_INVALID` before any statement runs, and inserts no row. The error's `meta` gives the method, the model, `problem: 'row-cannot-conflict'`, the row's `index` and the `conflictKeys`; the message and `conflictKeys` list each conflict key by its storage columns, such as `invited_by_id` for the field `invitedById`. Before, such a row was always inserted, since nothing could collide with it.
1382
+
1383
+ For each call that throws:
1384
+
1385
+ 1. If the row should be skipped when a matching row exists, give it a value for each field named in `conflictOn`, or name in `conflictOn` fields the row gives values for.
1386
+ 2. If the row should always be inserted, insert it with a separate `createAll(rows)` or `createAndCount(rows)` call without `onConflict`.
1387
+
1388
+ ### `create-all-skip-refuses-tables-without-keys`
1389
+
1390
+ Without `conflictOn`, a call on a table with no primary key, unique constraint or unique index over columns now throws `ORM.ARGUMENT_INVALID` with `problem: 'no-conflict-key'` before any statement runs, since nothing in the table can collide. Before, every row was inserted. Leave `onConflict` out of such a call, or give the table a key and name it in `conflictOn`.
1391
+
1392
+
1393
+ ## SQL builder comparisons check values against the column's type
1394
+
1395
+ ### `sql-builder-enum-comparison-values-are-checked`
1396
+
1397
+ A builder `where` such as `fns.eq(f.kind, 'humna')` on an enum column whose members are `human` and `agent` now fails to type-check, with the same error as `update({ kind: 'humna' })`. Correct the value to one of the enum's members.
1398
+
1399
+ The same check applies to any column whose contract type is narrower than its codec's type: an enum stored as an integer (`0 | 1 | 2`), a native enum, or a column with a typed override.
1400
+
1401
+ A value whose type is wider than the column's is also refused. For example, `fns.eq(f.status, req.query.status)` fails when `req.query.status` is a `string`, and `fns.in(f.status, values)` fails when `values` is a `string[]`. Narrow the value first, for example by checking it against the enum's members, so that TypeScript knows it is one of them.
1402
+
1403
+ To find rows that hold a value the column's type no longer lists, compare with a raw SQL operand, which keeps the codec's input type: ``fns.eq(fns.raw`kind`.returns('pg/text@1'), 'old_value')``.
1404
+
1405
+
1406
+ ## Errors from MySQL's shared code carry no `meta.target`
1407
+
1408
+ ### `mysql-errors-drop-meta-target`
1409
+
1410
+ Find code that reads `meta.target` from an error a MySQL or MariaDB client raised, and read the target from the client instead: `db.stack.target.targetId` is `'mysql'` or `'mariadb'`.
1411
+
1412
+
1413
+ ## `prisma orm init --target` takes any target package by name
1414
+
1415
+ ### `init-target-takes-a-package-name`
1416
+
1417
+ ```bash
1418
+ prisma orm init --target @prisma/orm-sqlite --authoring psl
1419
+ ```
1420
+
1421
+ `--target` is looked up among the short names (`postgres`, `mongodb` and their aliases). A value that is not one of them is taken as a package name: `init` installs that package and writes the project from the init contribution it exports. `--target postgres` and `--target mongodb` do what they did before. A value that is not a valid package name is refused with `CLI.INIT_INVALID_FLAG_VALUE` before anything changes, and the error's `meta.problems` says why. Before installing, `init` checks that the package lists the `prisma-orm-extension` keyword and refuses with `CLI.INIT_TARGET_PACKAGE_NOT_VERIFIED` when it does not. That includes `--target sqlite`, which names an unrelated package: use `--target @prisma/orm-sqlite`. The first error's `meta.allowed` still lists the short names only, and `meta.acceptsPackageName` is `true`.
1422
+
1423
+ Without `--target`, the picker has one more entry, "Another target package", which asks for the package name.
1424
+
1425
+ Nothing changes for a script that runs `init --target postgres` or `--target mongodb` and ignores fields it does not know.
1426
+
1427
+ In each matched file that reads the `--json` result of `prisma orm init`:
1428
+
1429
+ - The result has a new string field, `package`: the name of the target package, such as `@prisma/orm-postgres`. A reader that refuses unknown fields must allow it.
1430
+ - `target` is still `postgres` or `mongodb` for those packages, also when the package was given by name (`--target @prisma/orm-postgres` reports `target: "postgres"`). For any other package it is the package name, so a reader that checks `target` against the two short names must accept any string. Use `package` when you need the package name.
1431
+
1432
+
1433
+ ## `db migrate` advances the `db` ref
1434
+
1435
+ ### `db-migrate-advances-db-ref`
1436
+
1437
+ `prisma db migrate` now moves the `db` ref to the contract the database is at after it applies, the way `db init` and `db update` do. It does so only when the connection comes from `db.connection` in `prisma.config.ts` and the CLI does not detect 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`. When CI detection is what stops the advance, the command says so with `MIGRATION.REF_NOT_ADVANCED_IN_CI`. A pipeline that runs `db migrate` from the config silences that notice with `--no-advance-ref`.
1438
+
1439
+ | Situation | Ref advancement |
1440
+ | --- | --- |
1441
+ | Connection from `prisma.config.ts`, CI not detected | `db` |
1442
+ | Connection from `prisma.config.ts`, CI detected | None |
1443
+ | `--db <url>` | None |
1444
+ | `--advance-ref <name>` | `<name>` instead, in every case above |
1445
+ | `--no-advance-ref` | None |
1446
+ | The run ends at the empty contract, for example `--to @empty`; connection from `prisma.config.ts`, neither flag | None; `db` is left unchanged, with a warning when it exists |
1447
+ | The run ends at the empty contract, `--advance-ref <name>` | Refused before anything is applied; before, the write failed after the apply |
1448
+
1449
+ Change the commands the project runs:
1450
+
1451
+ - In a development command that reads the connection from the config, such as a `package.json` script or a README step, remove `--advance-ref db` from `db migrate`. Keep it where the command passes `--db` or runs in CI, because there `db migrate` advances nothing by default.
1452
+
1453
+ ```bash
1454
+ # Before
1455
+ prisma db migrate --advance-ref db
1456
+ # After
1457
+ prisma db migrate
1458
+ ```
1459
+
1460
+ - Add `--no-advance-ref`, or pass the URL with `--db`, wherever `db migrate` runs from the config outside a CI runner and must not change files in the repository. That covers deploys: a container entrypoint, a Kubernetes job, a release command such as Fly's `release_command`, or a deploy script on a server checkout. On a persistent checkout the run would otherwise rewrite the tracked `migrations/app/refs/db.json` to the deployed contract, and the next `git pull` that touches that file refuses. It also covers a job that commits its results.
1461
+
1462
+ A ref that `db migrate` cannot write, for example on a read-only filesystem, is now a warning, `MIGRATION.REF_NOT_WRITTEN`, and the command exits 0. Before, a failed `--advance-ref` write failed the command after the migrations had applied. A script that checked the exit code to detect that failure reads the warning from the `--json` result's diagnostics instead.
1463
+
1464
+
1465
+ ## The CLI engine is 0.10.4, and its consent error has one fixed first line
1466
+
1467
+ ### `engine-pin-moves-to-0-10-4`
1468
+
1469
+ For every file matched by `detection`, change the `@prisma/cli-engine` version (`0.10.3`, `0.10.2`, `0.10.1`, `0.10.0` or any earlier 0.x) to `0.10.4` and reinstall. Projects assembled by the `prisma` CLI resolve the engine automatically.
1470
+
1471
+ ### `consent-required-summary-is-one-fixed-sentence`
1472
+
1473
+ Two errors have the code `CLI.CONSENT_REQUIRED`. Both are raised when the run cannot ask (it is not interactive, or `--yes` is set). The first line (the `summary`) of each changed, and both now have the same one:
1474
+
1475
+ - `This command requires explicit consent, but it was not provided.`
1476
+ - Under `--yes`: `This command requires explicit consent for which --yes is not sufficient.` Engines 0.10.2 and 0.10.3 said `This command requires explicit consent, and --yes does not give it.`
1477
+
1478
+ **A statement question nobody answered.** `prisma migration plan` or `prisma db update` would lose data or change access, and no `--rename`, `--delete` or similar flag answers the question.
1479
+
1480
+ - Before: `"User.nick" needs a statement, and the session is not interactive.`, or `2 subjects need a statement, and the session is not interactive: "Bug", "Task".` for several questions. Under `--yes`, the line said `which --yes cannot give` in place of `and the session is not interactive`.
1481
+ - `why` (the questions), the next actions, `meta`, the code and the exit code (2) are unchanged. Read the unanswered subjects from `meta.unanswered` (each with its `subject` and `verbs`).
1482
+
1483
+ **A consent that `--confirm` answers.** For example `prisma init` over a project it would replace.
1484
+
1485
+ - Before: `"<question>" requires explicit consent, and the session is not interactive.`, or `…, which --yes cannot grant.` under `--yes`. When the consent has a token, the line ended `Grant it by passing --confirm <token>.`
1486
+ - The question is now in `why`, which this error did not have before. The next action, `meta.consentToken`, the code and the exit code (2) are unchanged. Read the token from `meta.consentToken`.
1487
+
1488
+ For every file matched by `detection`, stop matching the first line of this error. A match on `session is not interactive` needs a change only where it is for this error; other errors still use those words. Branch on the error's `code` (`CLI.CONSENT_REQUIRED`). The code alone does not tell the two errors apart: the first has `meta.unanswered`, and the second does not.