@prisma/orm-sqlite 8.0.0-rc.20-dev.9 → 8.0.0-rc.20-dev.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime.mjs +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/{sqlite-static-CnyBsQfq-BR59alOC.mjs → sqlite-static-CdrqgTo3-DogFJ5NP.mjs} +3 -3
- package/dist/sqlite-static-CdrqgTo3-DogFJ5NP.mjs.map +1 -0
- package/dist/static.mjs +1 -1
- package/package.json +8 -8
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/references/contract.md +3 -3
- package/skills/prisma-8/references/debug.md +1 -1
- package/skills/prisma-8/references/upgrade-app.md +2 -2
- package/skills/prisma-8/references/upgrade-extension.md +2 -2
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +130 -94
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +245 -30
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +8 -5
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +77 -23
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +1668 -19
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +23 -12
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +50 -15
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +273 -87
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +245 -30
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +1668 -19
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +8 -6
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +50 -15
- package/dist/sqlite-static-CnyBsQfq-BR59alOC.mjs.map +0 -1
|
@@ -4,9 +4,9 @@ to: "8.0.0-rc.19"
|
|
|
4
4
|
changes:
|
|
5
5
|
- id: stored-contracts-drop-nocheck
|
|
6
6
|
summary: |
|
|
7
|
-
A stored SQL contract that has a `noCheck` key on a column no longer loads. Before any other step of this change, run `scripts/remove-nocheck/remove-nocheck.ts` from the project root, then run `prisma db sign` against every database. The script removes the key from every stored contract, migration snapshots and the emitted `contract.json` included. A list whose element check was waived becomes a list whose elements may be null, which is what the database allows. The script refreshes every hash and reference that changes.
|
|
7
|
+
A stored SQL contract that has a `noCheck` key on a column no longer loads. Before any other step of this change, run `scripts/remove-nocheck/remove-nocheck.ts` from the project root, then run `prisma db sign` against every database. Sign a database that has not applied every migration with `prisma db sign --contract <the last migration it applied>`, and migrate it once each `ops.json` is written again. The script removes the key from every stored contract, migration snapshots and the emitted `contract.json` included. A list whose element check was waived becomes a list whose elements may be null, which is what the database allows. The script also writes each PostgreSQL default in the form this release stores (`postgres-defaults-stored-in-another-spelling`). It refreshes every hash and reference that changes.
|
|
8
8
|
detection:
|
|
9
|
-
glob: "
|
|
9
|
+
glob: "**/*.json"
|
|
10
10
|
matches:
|
|
11
11
|
- '"noCheck"\s*:'
|
|
12
12
|
script: ./scripts/remove-nocheck/remove-nocheck.ts
|
|
@@ -26,11 +26,12 @@ changes:
|
|
|
26
26
|
- '\.noCheck\('
|
|
27
27
|
- id: prisma7-lists-allow-null-elements
|
|
28
28
|
summary: |
|
|
29
|
-
A contract read from a Prisma 7 `schema.prisma` now types the elements of every list as `T | null`, because Prisma 7 creates no check against null elements, and its storage hash changes. Run `stored-contracts-drop-nocheck` first. Otherwise, re-emit the contract and then run `prisma db sign` against every database. A database Prisma 7 built still matches the contract with no migration.
|
|
29
|
+
A contract read from a Prisma 7 `schema.prisma` now types the elements of every list as `T | null`, because Prisma 7 creates no check against null elements, and its storage hash changes. Run `stored-contracts-drop-nocheck` first. Otherwise, re-emit the contract and then run `prisma db sign` against every database. A database Prisma 7 built still matches the contract with no migration. The detection matches a Prisma 7 schema file, one without the `// use prisma-8` directive, with a list of a scalar type, or with any list when the same file declares an enum; check whether such a list is of an enum, and check a list of an enum declared in another file of the schema yourself.
|
|
30
30
|
detection:
|
|
31
|
-
glob: "
|
|
31
|
+
glob: "**/*.prisma"
|
|
32
32
|
matches:
|
|
33
|
-
- '\
|
|
33
|
+
- '(?<![\s\S])(?!\s*// *use +(?:prisma-8|prisma-next) *(?!\S))[\s\S]*\n[ \t]*\w+[ \t]+(?:String|Int|BigInt|Float|Decimal|Boolean|DateTime|Json|Bytes)\[\]'
|
|
34
|
+
- '(?<![\s\S])(?!\s*// *use +(?:prisma-8|prisma-next) *(?!\S))(?=[\s\S]*\benum[ \t]+\w+[ \t]*\{)[\s\S]*\n[ \t]*\w+[ \t]+\w+\[\]'
|
|
34
35
|
- id: supabase-contract-lists-allow-null-elements
|
|
35
36
|
summary: |
|
|
36
37
|
The `@prisma/orm-extension-supabase` contract now declares its four `text[]` columns as lists whose elements may be null, so code that reads them gets `string | null` elements, and the Supabase space's storage hash changes. Run `prisma db sign` against every database after upgrading.
|
|
@@ -48,22 +49,30 @@ changes:
|
|
|
48
49
|
script: ./scripts/data-type-values/data-type-values.ts
|
|
49
50
|
- id: date-time-interval-and-bytes-defaults-use-tags
|
|
50
51
|
summary: |
|
|
51
|
-
A date, time, interval or bytes default is written with its type's tag instead of a quoted string: `@default(timestamptz`2024-01-01T00:00:00Z`)` on PostgreSQL, `@default(datetime`2024-01-01T00:00:00Z`)` on SQLite, and `@default(bytea`\x0102`)` for bytes on PostgreSQL and `@default(blob`0102`)` on SQLite. `contract emit` refuses the quoted form and names the tag to write.
|
|
52
|
+
A date, time, interval or bytes default is written with its type's tag instead of a quoted string: `@default(timestamptz`2024-01-01T00:00:00Z`)` on PostgreSQL, `@default(datetime`2024-01-01T00:00:00Z`)` on SQLite, and `@default(bytea`\x0102`)` for bytes on PostgreSQL and `@default(blob`0102`)` on SQLite. `contract emit` refuses the quoted form and names the tag to write. The detection matches Prisma 8 schema files, those with the `// use prisma-8` directive, with a quoted default that looks like a date or an interval, or that sits on a date, time, interval or bytes column. It skips a quoted time such as `"12:30"` on a column whose type is a type alias, because a `String` default can look the same; `contract emit` names such a default.
|
|
52
53
|
detection:
|
|
53
54
|
glob: "**/*.prisma"
|
|
54
55
|
matches:
|
|
55
|
-
- '
|
|
56
|
-
- '\
|
|
56
|
+
- '(?<![\s\S])\s*// *use +(?:prisma-8|prisma-next) *(?!\S)[\s\S]*@default\(\s*"(?:[+-]?\d{4,6}-\d{2}-\d{2}|-?P(?:\d|T\d)|[+-]?infinity")'
|
|
57
|
+
- '(?<![\s\S])\s*// *use +(?:prisma-8|prisma-next) *(?!\S)[\s\S]*\b(?:DateTime|Date|Time|Timetz|Timestamp|Timestamptz|Interval)\b[^\n]*@default\(\s*"'
|
|
58
|
+
- '(?<![\s\S])\s*// *use +(?:prisma-8|prisma-next) *(?!\S)[\s\S]*\bBytes\??[^\n]*@default\(\s*"'
|
|
57
59
|
- id: postgres-defaults-stored-in-another-spelling
|
|
58
60
|
summary: |
|
|
59
|
-
The CLI refuses a PostgreSQL contract that an earlier release emitted when it stores a default in another spelling than its column's parameters give, for example `"1.5"` on `numeric(10,2)`, or a date or time default written as earlier releases stored it. Run `prisma contract emit`, then `prisma db sign`.
|
|
61
|
+
The CLI refuses a PostgreSQL contract that an earlier release emitted when it stores a default in another spelling than its column's parameters give, for example `"1.5"` on `numeric(10,2)`, or a date or time default written as earlier releases stored it. Migration snapshots store such defaults too, and the CLI refuses to plan from them. Run `scripts/remove-nocheck/remove-nocheck.ts` (`stored-contracts-drop-nocheck`): it writes each stored default in the new form, migration snapshots included, and refreshes every hash that changes. Then run `prisma contract emit`, then `prisma db sign`.
|
|
62
|
+
script: ./scripts/remove-nocheck/remove-nocheck.ts
|
|
60
63
|
- id: prisma7-datetime-default-finer-than-column
|
|
61
64
|
summary: |
|
|
62
|
-
A project that reads a Prisma 7 schema: a `DateTime` default with more fraction digits than its column holds is now refused instead of rounded. Write the value PostgreSQL stores, which the message names.
|
|
65
|
+
A project that reads a Prisma 7 schema: a `DateTime` default with more fraction digits than its column holds is now refused instead of rounded. Write the value PostgreSQL stores, which the message names. The detection matches a quoted default with more fraction digits than the precision of its `@db.Timestamp`, `@db.Timestamptz`, `@db.Time` or `@db.Timetz` type, or with more than 3 on a field without a `@db` type.
|
|
63
66
|
detection:
|
|
64
67
|
glob: "**/*.prisma"
|
|
65
68
|
matches:
|
|
66
|
-
- '
|
|
69
|
+
- '(?:^|\n)(?![^\n]*@db\.)[^\n]*@default\(\s*"\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}\.\d{4,}'
|
|
70
|
+
- '(?:^|\n)(?=[^\n]*@db\.(?:Timestamp|Timestamptz|Time|Timetz)\(\s*0\s*\))[^\n]*@default\(\s*"[^"\n]*:\d{2}\.\d{1,}'
|
|
71
|
+
- '(?:^|\n)(?=[^\n]*@db\.(?:Timestamp|Timestamptz|Time|Timetz)\(\s*1\s*\))[^\n]*@default\(\s*"[^"\n]*:\d{2}\.\d{2,}'
|
|
72
|
+
- '(?:^|\n)(?=[^\n]*@db\.(?:Timestamp|Timestamptz|Time|Timetz)\(\s*2\s*\))[^\n]*@default\(\s*"[^"\n]*:\d{2}\.\d{3,}'
|
|
73
|
+
- '(?:^|\n)(?=[^\n]*@db\.(?:Timestamp|Timestamptz|Time|Timetz)\(\s*3\s*\))[^\n]*@default\(\s*"[^"\n]*:\d{2}\.\d{4,}'
|
|
74
|
+
- '(?:^|\n)(?=[^\n]*@db\.(?:Timestamp|Timestamptz|Time|Timetz)\(\s*4\s*\))[^\n]*@default\(\s*"[^"\n]*:\d{2}\.\d{5,}'
|
|
75
|
+
- '(?:^|\n)(?=[^\n]*@db\.(?:Timestamp|Timestamptz|Time|Timetz)\(\s*5\s*\))[^\n]*@default\(\s*"[^"\n]*:\d{2}\.\d{6,}'
|
|
67
76
|
- id: stored-values-a-column-type-does-not-hold
|
|
68
77
|
summary: |
|
|
69
78
|
Reading a value its column's type does not hold now throws `RUNTIME.DECODE_FAILED`, in a plain read and in an include alike: text or bytes in a SQLite INTEGER or REAL column, text or a number in a SQLite BLOB column, and a multi-dimensional array in a PostgreSQL `text[]` column read with `pg/text-array@1`.
|
|
@@ -75,14 +84,14 @@ changes:
|
|
|
75
84
|
`min` and `max` of a `pg/text-array@1` column return an array of strings, as a row of the column does, instead of the array's text (`{a,b}`).
|
|
76
85
|
- id: sign-databases-after-data-type-values
|
|
77
86
|
summary: |
|
|
78
|
-
The upgrade changes the storage hash of every SQLite contract with a datetime or JSON column, and of every PostgreSQL contract you emit again. Run `prisma db sign` against every database before deploying the application built with the new contract.
|
|
87
|
+
The upgrade changes the storage hash of every SQLite contract with a datetime or JSON column, and of every PostgreSQL contract you emit again. Run `prisma db sign` against every database before deploying the application built with the new contract. Sign a database that has not applied every migration with `prisma db sign --contract <the last migration it applied>`.
|
|
79
88
|
- id: client-functions-move-from-default-to-on-create
|
|
80
89
|
summary: |
|
|
81
|
-
`@default` now sets a database default only. `@default(uuid())`, `@default(cuid(2))`, `@default(ulid())` and `@default(nanoid())`, with any arguments, are refused with `PSL_GENERATOR_IN_DEFAULT`. Write `@onCreate(uuid())` and so on instead. Run `scripts/default-generators-to-on-create/rewrite-default-generators.mjs` with the Prisma 8
|
|
90
|
+
`@default` now sets a database default only. `@default(uuid())`, `@default(cuid(2))`, `@default(ulid())` and `@default(nanoid())`, with any arguments, are refused with `PSL_GENERATOR_IN_DEFAULT`. Write `@onCreate(uuid())` and so on instead. Run `scripts/default-generators-to-on-create/rewrite-default-generators.mjs` with every `.prisma` file of the project as arguments, including the schema copies in migration directories; it rewrites the Prisma 8 ones and leaves the others unchanged. The contract does not change, so there is nothing to re-emit, sign or migrate. The detection matches Prisma 8 schema files, those with the `// use prisma-8` directive, that write one of these functions in `@default`.
|
|
82
91
|
detection:
|
|
83
92
|
glob: "**/*.prisma"
|
|
84
93
|
matches:
|
|
85
|
-
- '
|
|
94
|
+
- '(?<![\s\S])\s*// *use +(?:prisma-8|prisma-next) *(?!\S)[\s\S]*@default\(\s*(?:uuid|cuid|ulid|nanoid)\s*\('
|
|
86
95
|
script: ./scripts/default-generators-to-on-create/rewrite-default-generators.mjs
|
|
87
96
|
- id: contract-print-writes-generator-attributes
|
|
88
97
|
summary: |
|
|
@@ -95,7 +104,7 @@ changes:
|
|
|
95
104
|
matches:
|
|
96
105
|
- '\buuid\(\s*(?![47]\s*\))[^\s)]'
|
|
97
106
|
- '\bcuid\(\s*(?!2\s*\))[^\s)]'
|
|
98
|
-
- '\bnanoid\(\s*(?:[01]\s*\)|\d{4,}|[3-9]\d\d|2[6-9]\d|25[6-9]|[^)]*[.:])'
|
|
107
|
+
- '\bnanoid\(\s*(?:[01]\s*\)|\d{4,}|[3-9]\d\d|2[6-9]\d|25[6-9]|[^)]*[.:]|[-"''])'
|
|
99
108
|
- id: generator-function-argument-diagnostics
|
|
100
109
|
summary: |
|
|
101
110
|
In Prisma 8 PSL, an argument of `uuid`, `cuid` or `nanoid` the function does not take is reported with the code `PSL_INVALID_GENERATOR_ARGUMENT` instead of `PSL_INVALID_ATTRIBUTE_SYNTAX`, and with the function's message, such as `uuid: version must be 4 or 7, got 5`. A missing or extra argument names the callee `Generator function "<name>"` instead of `Attribute "<name>"`, and `Default function "<name>"` for `now` and `autoincrement` in `@default`.
|
|
@@ -157,10 +166,10 @@ changes:
|
|
|
157
166
|
detection:
|
|
158
167
|
glob: "**/*.prisma"
|
|
159
168
|
matches:
|
|
160
|
-
- 'enum\s+\w+\s*\{(?=[^}]*@@type\(\s*"(?!(?:pg/(?:text|char|varchar|uuid|inet|bit|varbit)|sql/(?:text|char|varchar)|sqlite/text|mongo/[\w-]+)@1")[^"]+"\s*\))[^}]*=\s*"'
|
|
169
|
+
- 'enum\s+\w+\s*\{(?=[^{}]*@@type\(\s*"(?!(?:pg/(?:text|char|varchar|uuid|inet|bit|varbit)|sql/(?:text|char|varchar)|sqlite/text|mongo/[\w-]+)@1")[^"]+"\s*\))[^{}]*=\s*"'
|
|
161
170
|
- id: enum-members-compare-by-their-data-type
|
|
162
171
|
summary: |
|
|
163
|
-
An enum typed by `pg/numeric@1`, `pg/interval@1` or `mongo/decimal128@1` now compares values as its data type does, as PostgreSQL's CHECK constraint already did: `db.enums.<Enum>.has()`, `nameOf()` and `ordinalOf()` find `0.50` as the numeric member `0.5`, and `PT24H` as the interval member `P1D`. Two members that are one value in different forms, such as `0.5` and `0.50`, or `P1D` and `PT24H`, are now refused as duplicates: `CONTRACT.ENUM_INVALID` from `defineContract`, and `PSL_ENUM_DUPLICATE_MEMBER_VALUE` from PSL. Such an enum's members, and a column typed by it, are typed as the codec's type, such as `string` for `pg/numeric@1`, because a read can return a member in another form. This holds both in the emitted `contract.d.ts` and in the types `defineContract` infers. A `mongo/decimal128@1` enum is refused when the contract is built, because a collection validator cannot list BSON decimals, so for it only the types changed.
|
|
172
|
+
An enum typed by `pg/numeric@1`, `pg/interval@1` or `mongo/decimal128@1` now compares values as its data type does, as PostgreSQL's CHECK constraint already did: `db.enums.<namespace>.<Enum>.has()`, `nameOf()` and `ordinalOf()` find `0.50` as the numeric member `0.5`, and `PT24H` as the interval member `P1D`. Two members that are one value in different forms, such as `0.5` and `0.50`, or `P1D` and `PT24H`, are now refused as duplicates: `CONTRACT.ENUM_INVALID` from `defineContract`, and `PSL_ENUM_DUPLICATE_MEMBER_VALUE` from PSL. Such an enum's members, and a column typed by it, are typed as the codec's type, such as `string` for `pg/numeric@1`, because a read can return a member in another form. This holds both in the emitted `contract.d.ts` and in the types `defineContract` infers. A `mongo/decimal128@1` enum is refused when the contract is built, because a collection validator cannot list BSON decimals, so for it only the types changed.
|
|
164
173
|
detection:
|
|
165
174
|
glob: "**/*.{prisma,ts,tsx,mts,cts}"
|
|
166
175
|
matches:
|
|
@@ -168,7 +177,7 @@ changes:
|
|
|
168
177
|
- '(?<![\s\S])(?![\s\S]*GENERATED FILE - DO NOT EDIT)(?=[\s\S]*\benumType\()[\s\S]*?(?:[''"`](?:pg/(?:numeric|interval)|mongo/decimal128)@1[''"`]|\b(?:numericColumn|intervalColumn)\()'
|
|
169
178
|
- id: enum-columns-typed-by-member-literals
|
|
170
179
|
summary: |
|
|
171
|
-
A column typed by an enum whose codec is `pg/uuid@1`, `pg/inet@1`, `pg/bit@1`, `pg/varbit@1`, `pg/date-string@1`, `pg/time-string@1`, `sql/char@1`, `sql/varchar@1`, `sql/text@1`, `sql/int@1` or `sql/float@1` on Postgres, or `sqlite/text@1`, `sqlite/integer@1`, `sqlite/real@1`, `sqlite/bigint@1`, `sqlite/json@1`, `sql/char@1`, `sql/varchar@1`, `sql/int@1` or `sql/float@1` on SQLite, is now typed in the emitted `contract.d.ts` as the union of its members' values, as a `pg/text@1` or `pg/int4@1` enum column already was, instead of the codec's whole type. Re-emit the contract. Code that writes a value that is not a member to such a column, or compares a value read from it with one, no longer typechecks; use a member, such as `
|
|
180
|
+
A column typed by an enum whose codec is `pg/uuid@1`, `pg/inet@1`, `pg/bit@1`, `pg/varbit@1`, `pg/date-string@1`, `pg/time-string@1`, `sql/char@1`, `sql/varchar@1`, `sql/text@1`, `sql/int@1` or `sql/float@1` on Postgres, or `sqlite/text@1`, `sqlite/integer@1`, `sqlite/real@1`, `sqlite/bigint@1`, `sqlite/json@1`, `sql/char@1`, `sql/varchar@1`, `sql/int@1` or `sql/float@1` on SQLite, is now typed in the emitted `contract.d.ts` as the union of its members' values, as a `pg/text@1` or `pg/int4@1` enum column already was, instead of the codec's whole type. Re-emit the contract. Code that writes a value that is not a member to such a column, or compares a value read from it with one, no longer typechecks; use a member, such as `db.enums.public.Host.members.Loopback`.
|
|
172
181
|
- id: db-schema-json-names-type-text
|
|
173
182
|
summary: |
|
|
174
183
|
`prisma db schema --json` names each column's type field `typeText` instead of `nativeType`, holding the type as introspection reads it from the database (`integer`, `timestamp(3) with time zone`), and no longer has `resolvedNativeType`. The tree output of `prisma db schema` shows the same text, such as `integer` where it showed `int4`.
|
|
@@ -185,11 +194,13 @@ changes:
|
|
|
185
194
|
- '(?<![\s\S])(?=[\s\S]*\bDEFAULT_INVALID\b)[\s\S]*\bnativeType\b'
|
|
186
195
|
- id: client-takes-contract-value
|
|
187
196
|
summary: |
|
|
188
|
-
Every client and static entry takes the contract only as a value, `{ contract }`. The `contractJson` option is removed,
|
|
197
|
+
Every client and static entry takes the contract only as a value, `{ contract }`. The `contractJson` option is removed, so `postgres<Contract>({ contractJson, url })` no longer compiles, and the client infers its contract type from the value, so the call needs no type argument. Turn the emitted JSON into a typed value once with `contractFromJson<Contract>(contractJson)` from the facade's `/static` entry (`@prisma/orm-postgres/static`, `@prisma/orm-sqlite/static`, `@prisma/orm-mongo/static`; Supabase uses the Postgres one), export it from the module that creates the client, and pass `{ contract }`. This applies to `postgres()`, `postgresServerless()`, `sqlite()`, `supabase()`, `mongo()`, `postgresStatic()`, `sqliteStatic()`, `mongoStatic()` and `mongoQuery()`. A `migration.ts` that builds a client from `contractJson`, for example for a data transform, fails to load until it is moved too, so move it before you run it again. The colocated script moves source files; move test files by hand.
|
|
189
198
|
detection:
|
|
190
199
|
glob: "**/*.{ts,tsx,mts,cts}"
|
|
191
200
|
matches:
|
|
192
|
-
- '(?<![\w$.])(?:postgres|postgresServerless|sqlite|supabase|mongo|postgresStatic|sqliteStatic|mongoStatic|mongoQuery)(?:<[
|
|
201
|
+
- '(?<![\w$.])(?:postgres|postgresServerless|sqlite|supabase|mongo|postgresStatic|sqliteStatic|mongoStatic|mongoQuery)(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{[^{}]*\})*?,)?\s*contractJson\s*[,}:]'
|
|
202
|
+
- '(?<![\s\S])(?:(?!import\s+[\w$]+\s*(?:,\s*\{[^{}]*\}\s*)?from\s*[''"]@prisma/orm-(?:(?:postgres|sqlite|mongo)/(?:runtime|serverless|static|query-builder)|extension-supabase/runtime)[''"])[\s\S])*import\s+([\w$]+)\s*(?:,\s*\{[^{}]*\}\s*)?from\s*[''"]@prisma/orm-(?:(?:postgres|sqlite|mongo)/(?:runtime|serverless|static|query-builder)|extension-supabase/runtime)[''"][\s\S]*(?<![\w$.])\1(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{[^{}]*\})*?,)?\s*contractJson\s*[,}:]'
|
|
203
|
+
- '(?<![\s\S])(?:(?!import\s*(?:[\w$]+\s*,\s*)?\{[^{}]*\b(?:default|supabase|mongoQuery|postgresStatic|sqliteStatic|mongoStatic)\s+as\s+[\w$]+[^{}]*\}\s*from\s*[''"]@prisma/orm-(?:(?:postgres|sqlite|mongo)/(?:runtime|serverless|static|query-builder)|extension-supabase/runtime)[''"])[\s\S])*import\s*(?:[\w$]+\s*,\s*)?\{[^{}]*\b(?:default|supabase|mongoQuery|postgresStatic|sqliteStatic|mongoStatic)\s+as\s+([\w$]+)[^{}]*\}\s*from\s*[''"]@prisma/orm-(?:(?:postgres|sqlite|mongo)/(?:runtime|serverless|static|query-builder)|extension-supabase/runtime)[''"][\s\S]*(?<![\w$.])\1(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{[^{}]*\})*?,)?\s*contractJson\s*[,}:]'
|
|
193
204
|
script: ./scripts/client-takes-contract-value/contract-from-json.ts
|
|
194
205
|
- id: collections-on-the-client
|
|
195
206
|
summary: |
|
|
@@ -197,31 +208,33 @@ changes:
|
|
|
197
208
|
detection:
|
|
198
209
|
glob: "**/*.{ts,tsx,mts,cts}"
|
|
199
210
|
matches:
|
|
200
|
-
- '(?<![\w$.])orm\s*(?:<[
|
|
201
|
-
- 'import\s*\{[^}]*\borm\s+as\s+([\w$]+)[^}]*\}\s*from\s*[''\"][^''\"]+[''\"][\s\S]*(?<![\w$.])\1\s*(?:<[
|
|
211
|
+
- '(?<![\w$.])orm\s*(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*?,)?\s*collections\s*[,}:]'
|
|
212
|
+
- '(?<![\s\S])(?:(?!import\s*\{[^{}]*\borm\s+as\s+[\w$]+[^{}]*\}\s*from\s*[''\"][^''\"]+[''\"])[\s\S])*import\s*\{[^{}]*\borm\s+as\s+([\w$]+)[^{}]*\}\s*from\s*[''\"][^''\"]+[''\"][\s\S]*(?<![\w$.])\1\s*(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*?,)?\s*collections\s*[,}:]'
|
|
202
213
|
- id: client-query-and-to-sql
|
|
203
214
|
summary: |
|
|
204
|
-
Additive for code that only uses these types. Every SQL client gets `query(plan)` and `execute(plan)`, with the types a transaction's have, and `toSql(plan)`, which returns `{ sql, params }` with no database. A serverless connection gets `query` and `execute` too; the serverless client, `postgresStatic()`, `sqliteStatic()` and every transaction get `toSql`. `postgres()`, `postgresServerless()`, `sqlite()` and `supabase()` take `mode: 'strict' | 'permissive'`. `supabase()` creates its pool on the first query instead of when it is called. Application code can move from `db.runtime().query(plan)` to `db.query(plan)`; code that builds its own object of one of the changed types, such as a test double, must add the new members. The detection matches a file that
|
|
215
|
+
Additive for code that only uses these types. Every SQL client gets `query(plan)` and `execute(plan)`, with the types a transaction's have, and `toSql(plan)`, which returns `{ sql, params }` with no database. A serverless connection gets `query` and `execute` too; the serverless client, `postgresStatic()`, `sqliteStatic()` and every transaction get `toSql`. `postgres()`, `postgresServerless()`, `sqlite()` and `supabase()` take `mode: 'strict' | 'permissive'`. `supabase()` creates its pool on the first query instead of when it is called. Application code can move from `db.runtime().query(plan)` to `db.query(plan)`; code that builds its own object of one of the changed types, such as a test double, must add the new members. The detection matches a file that imports one of the changed types from a Prisma package, calls `runtime().query(` or `runtime().execute(`, or reads the renamed error details or the old message texts.
|
|
205
216
|
detection:
|
|
206
217
|
glob: "**/*.{ts,tsx,mts,cts}"
|
|
207
218
|
matches:
|
|
208
|
-
- '(?<![\w$])(?:PostgresClient|PostgresServerlessClient|PostgresServerlessConnection|PostgresStaticContext|PostgresStaticMembers|
|
|
219
|
+
- 'import\s*(?:type\s*)?(?:[\w$]+\s*,\s*)?\{[^}]*(?<![\w$])(?:PostgresClient|PostgresServerlessClient|PostgresServerlessConnection|PostgresStaticContext|PostgresStaticMembers|SqliteClient|SqliteStaticContext|RoleBoundDb|ServiceRoleDb|SupabaseInternalDb|PostgresTransactionContext|SqliteTransactionContext)(?![\w$])[^}]*\}\s*from\s*[''"]@prisma/orm-'
|
|
209
220
|
- '\.runtime\(\)\s*\.(?:query|execute)\('
|
|
221
|
+
- '(?<![\w$])(?:runtimeTarget|runtimeStorageHash)\s*:|\.(?:runtimeTarget|runtimeStorageHash)\b|[''"](?:runtimeTarget|runtimeStorageHash)[''"]'
|
|
222
|
+
- 'Ad-hoc execute received a bind-site slot|Plan target does not match runtime target|Plan storage hash does not match runtime contract'
|
|
210
223
|
- id: orm-collection-member-using-reserved
|
|
211
224
|
summary: |
|
|
212
225
|
Every ORM collection has a `using` member, which holds the collection methods packages contribute for the model, such as `db.orm.public.Post.using.post_search(q)` for a Postgres full-text index. A custom collection class that declares its own member named `using` no longer compiles; rename that member. The detection matches a file that extends `Collection` and declares a class member named `using`.
|
|
213
226
|
detection:
|
|
214
227
|
glob: "**/*.{ts,tsx,mts,cts}"
|
|
215
228
|
matches:
|
|
216
|
-
- '(?<![\s\S])(?=[\s\S]*\bextends\s+Collection\b)[\s\S]
|
|
229
|
+
- '(?<![\s\S])(?=[\s\S]*\bextends\s+Collection\b)[\s\S]*[\n{;][ \t]*(?:(?:public|private|protected|override|readonly|async|declare|static|accessor)[ \t]+)*(?:(?:(?:get|set)[ \t]+)?using[ \t]*[?!]?[ \t]*[(<]|using[ \t]*[?!]?[ \t]*=(?![=>])|using[ \t]*[?!]?[ \t]*:[^\n]*[^,\s][ \t]*(?:\n|$))'
|
|
217
230
|
- id: orm-annotations-on-the-call
|
|
218
231
|
summary: |
|
|
219
|
-
Every SQL ORM terminal method runs as one `orm-call` activity, and the annotations a `configure` callback records live on that activity. The statements the call sends carry none, so a middleware that reads an ORM annotation from a statement plan (`handle.read(plan)` or `plan.meta.annotations`) in `beforeEncode`, `intercept.onQuery`, `onRow` or `activityStarted` of a statement finds nothing. Read it from the call instead: in `activityStarted(activity)`, `if (activity.kind === 'orm-call') handle.read(activity)`.
|
|
232
|
+
Every SQL ORM terminal method runs as one `orm-call` activity, and the annotations a `configure` callback records live on that activity. The statements the call sends carry none, so a middleware that reads an ORM annotation from a statement plan (`handle.read(plan)` or `plan.meta.annotations`) in `beforeEncode`, `intercept.onQuery`, `onRow` or `activityStarted` of a statement finds nothing. Read it from the call instead: in `activityStarted(activity)`, `if (activity.kind === 'orm-call') handle.read(activity)`. The detection matches a file with a middleware hook, not a MongoDB one, that reads an annotation from something other than the activity, or reads `meta.annotations`.
|
|
220
233
|
detection:
|
|
221
234
|
glob: "**/*.{ts,mts,cts,tsx}"
|
|
222
235
|
matches:
|
|
223
|
-
- '
|
|
224
|
-
- '
|
|
236
|
+
- '(?<![\s\S])(?![\s\S]*(?:familyId:\s*[''"]mongo[''"]|\bMongoMiddleware\b))(?=[\s\S]*\b(?:beforeEncode|beforeCompile|onQuery|onExecute|onRow|activityStarted)\b)[\s\S]*\.read\(\s*(?!activity\b)[\w$]+(?:\.[\w$]+)*\s*\)'
|
|
237
|
+
- '(?<![\s\S])(?![\s\S]*(?:familyId:\s*[''"]mongo[''"]|\bMongoMiddleware\b))(?=[\s\S]*\b(?:beforeEncode|beforeCompile|onQuery|onExecute|onRow|activityStarted)\b)[\s\S]*\bmeta\.annotations\b'
|
|
225
238
|
- id: cached-orm-reads-key-on-the-call
|
|
226
239
|
summary: |
|
|
227
240
|
The cache middleware caches an annotated ORM read as a whole: a hit sends no statement. Without a `key`, the read is keyed by the call's content hash, and the `deriveKey` option applies only to annotated SQL builder queries. Where a `deriveKey` added a prefix (for example a tenant) to ORM reads, pass that prefix in `cacheAnnotation({ key })` on those reads. If your `deriveKey` separates tenants or users, ORM reads are no longer separated: until each annotated ORM read has a tenant-prefixed `key`, one tenant's cached ORM read can be served to another. Statement middleware such as a slow-query log sees no statement for a cache hit of an ORM read.
|
|
@@ -231,15 +244,16 @@ changes:
|
|
|
231
244
|
- '\bderiveKey\b(?!FromContentHash)'
|
|
232
245
|
- id: cache-store-holds-cached-values
|
|
233
246
|
summary: |
|
|
234
|
-
A cache store holds `CachedValue`, `{ kind: 'statement-rows', rows } | { kind: 'call-result', result }`, not `CachedRows`. Type a custom store as `CacheStore<TMeta, CachedValue>` (or `CacheStore<TMeta>`), and make `get` give back a value equivalent to the one `set` was given, `kind` included. An ORM call's result holds decoded values such as `Date`, `bigint`, Temporal values and extension class instances, so a store that serializes needs a serializer that rebuilds them; `JSON.stringify` throws on a `bigint` and turns a `Date` into a string. `createInMemoryCacheStore` takes only the meta type now and always holds `CachedValue`: drop its second type argument.
|
|
247
|
+
A cache store holds `CachedValue`, `{ kind: 'statement-rows', rows } | { kind: 'call-result', result }`, not `CachedRows`. Type a custom store as `CacheStore<TMeta, CachedValue>` (or `CacheStore<TMeta>`), and make `get` give back a value equivalent to the one `set` was given, `kind` included. An ORM call's result holds decoded values such as `Date`, `bigint`, Temporal values and extension class instances, so a store that serializes needs a serializer that rebuilds them; `JSON.stringify` throws on a `bigint` and turns a `Date` into a string. `createInMemoryCacheStore` takes only the meta type now and always holds `CachedValue`: drop its second type argument. The detection matches a file that names `CachedRows`, or imports from the cache package and names `CacheStore` or `CacheEntry` but not `CachedValue`, or passes `createInMemoryCacheStore` a second type argument.
|
|
235
248
|
detection:
|
|
236
249
|
glob: "**/*.{ts,mts,cts,tsx}"
|
|
237
250
|
matches:
|
|
238
251
|
- '\bCachedRows\b'
|
|
239
252
|
- 'createInMemoryCacheStore<[^>(]*,'
|
|
253
|
+
- '(?<![\s\S])(?![\s\S]*\bCachedValue\b)(?=[\s\S]*[''"](?:@prisma/orm-extension-middleware-cache|@internal/middleware-cache)[''"])[\s\S]*(?<![\w$])(?:CacheStore|CacheEntry)(?![\w$])'
|
|
240
254
|
- id: orm-needs-a-runtime-queryable
|
|
241
255
|
summary: |
|
|
242
|
-
Pass `orm()` a runtime, connection or transaction from the SQL runtime itself, or `db.runtime()`. A hand-built object that copies only `query` and `execute` (for example `orm({ context, runtime: { query(plan) { return runtime.query(plan); }, execute(plan) { return runtime.execute(plan); } } })`) has no activity source, so every terminal method on it now fails with `ORM.ACTIVITY_SOURCE_MISSING`: `all()` and the other streaming terminals throw when called, and the others reject. If you need the wrapper, keep the original's `[activitySource]` member on it.
|
|
256
|
+
Pass `orm()` a runtime, connection or transaction from the SQL runtime itself, or `db.runtime()`. A hand-built object that copies only `query` and `execute` (for example `orm({ context, runtime: { query(plan) { return runtime.query(plan); }, execute(plan) { return runtime.execute(plan); } } })`) has no activity source, so every terminal method on it now fails with `ORM.ACTIVITY_SOURCE_MISSING`: `all()` and the other streaming terminals throw when called, and the others reject. If you need the wrapper, keep the original's `[activitySource]` member on it; the symbol `activitySource` is exported from `@prisma/orm-postgres/family-runtime` (`@prisma/orm-sqlite/family-runtime` on SQLite).
|
|
243
257
|
detection:
|
|
244
258
|
glob: "**/*.{ts,mts,cts,tsx}"
|
|
245
259
|
matches:
|
|
@@ -253,11 +267,11 @@ changes:
|
|
|
253
267
|
- 'Runtime is closed|Postgres client is closed'
|
|
254
268
|
- id: typescript-contract-include-row-types
|
|
255
269
|
summary: |
|
|
256
|
-
A contract built with `defineContract` from TypeScript now types each relation with its target model, namespace and cardinality, as an emitted `contract.d.ts` does. Rows from `include(...)`, which were typed `unknown` and always as an array, now have the target model's field types: a has-many or many-to-many relation is an array, a belongs-to relation is one row (or `null` when optional), and a has-one relation is one row or `null`. A cast on an included value that disagrees with this type now fails to typecheck. The detection matches
|
|
270
|
+
A contract built with `defineContract` from TypeScript now types each relation with its target model, namespace and cardinality, as an emitted `contract.d.ts` does. Rows from `include(...)`, which were typed `unknown` and always as an array, now have the target model's field types: a has-many or many-to-many relation is an array, a belongs-to relation is one row (or `null` when optional), and a has-one relation is one row or `null`. A cast on an included value that disagrees with this type now fails to typecheck. The detection matches a file that imports `defineContract` from a SQL contract builder; the change matters only where code queries through the contract it builds without an emitted `contract.d.ts`.
|
|
257
271
|
detection:
|
|
258
272
|
glob: "**/*.{ts,mts,cts,tsx}"
|
|
259
273
|
matches:
|
|
260
|
-
- '
|
|
274
|
+
- '\bimport\s*\{[^}]*\bdefineContract\b[^}]*\}\s*from\s*[''"]@prisma/orm-(?:postgres|sqlite|family-sql/contract-ts)/contract-builder[''"]'
|
|
261
275
|
- id: typescript-contract-aggregates-and-operations
|
|
262
276
|
summary: |
|
|
263
277
|
A contract built with `defineContract` now carries the aggregate types and query operation types of its target, adapter and extensions, and the capabilities of its adapter, in its type and in its value. `count`, `sum`, `max` and the other aggregates, inside `aggregate(...)` and inside include refinements, are typed; field operations such as `ilike` and capability-gated methods such as `distinctOn` and `forUpdate` are available in the types; `contract.capabilities.postgres.distinctOn` is `true` at run time. Casts that dispatched aggregates by name can be removed. The detection matches casts of the aggregate builder to a record of functions.
|
|
@@ -275,8 +289,8 @@ changes:
|
|
|
275
289
|
- '\bfield\.(id\.)?(uuidv4String|uuidv7String|uuidString|ulid|nanoid|cuid2|ksuid)\('
|
|
276
290
|
- '\bfield\.temporal\.(timestampString|timestamptzString)\(\s*\d'
|
|
277
291
|
- '\b(charColumn|varcharColumn|numericColumn|bitColumn|varbitColumn|timetzColumn|intervalColumn|timeStringColumn)\(\s*\d'
|
|
278
|
-
- '\btype\.sql\.String\(\s*\d'
|
|
279
|
-
- '\bvector\(\s*\d'
|
|
292
|
+
- '\btype\.(?:sql\.String|pgvector\.Vector)\(\s*\d'
|
|
293
|
+
- '(?<![\s\S])(?=[\s\S]*\bimport\s*(?:type\s*)?\{[^}]*\bvector\b[^}]*\}\s*from\s*[''"]@prisma/orm-extension-pgvector/column-types[''"])[\s\S]*(?<![\w$.''"`])vector\(\s*\d'
|
|
280
294
|
- '\bfield\.generated\('
|
|
281
295
|
- id: orm-filters-and-writes-take-input-types
|
|
282
296
|
summary: |
|
|
@@ -287,20 +301,18 @@ changes:
|
|
|
287
301
|
- 'as\s+(unknown\s+as\s+)?(Char|Varchar|Numeric|Bit|VarBit|Timetz|Interval|TimeString|TimestampString|TimestamptzString)<'
|
|
288
302
|
- id: typescript-contract-index-references
|
|
289
303
|
summary: |
|
|
290
|
-
A contract built with `defineContract` now types each table's indexes as an emitted `contract.d.ts` does: the indexes `.sql({ indexes })` declares, under the `name:` or `map:` they were given or their default `<table>_<columns>_idx` name, and the backing indexes the build derives for foreign keys. In `where` and `orderBy` callbacks, `indexes.<name>` offers exactly these names, so a misspelt index name fails to typecheck instead of failing at run time, and `fns.fullTextMatches(indexes.<name>, query)` and `fns.fullTextRank(...)` now typecheck for a `fullTextIndex`. The detection matches
|
|
304
|
+
A contract built with `defineContract` now types each table's indexes as an emitted `contract.d.ts` does: the indexes `.sql({ indexes })` declares, under the `name:` or `map:` they were given or their default `<table>_<columns>_idx` name, and the backing indexes the build derives for foreign keys. In `where` and `orderBy` callbacks, `indexes.<name>` offers exactly these names, so a misspelt index name fails to typecheck instead of failing at run time, and `fns.fullTextMatches(indexes.<name>, query)` and `fns.fullTextRank(...)` now typecheck for a `fullTextIndex`. The detection matches a file that imports `defineContract` from a SQL contract builder; the change matters only where code queries through the contract it builds without an emitted `contract.d.ts`.
|
|
291
305
|
detection:
|
|
292
306
|
glob: "**/*.{ts,mts,cts,tsx}"
|
|
293
307
|
matches:
|
|
294
|
-
- '\
|
|
295
|
-
- '\{\s*(fns,\s*)?indexes\s*\}'
|
|
308
|
+
- '\bimport\s*\{[^}]*\bdefineContract\b[^}]*\}\s*from\s*[''"]@prisma/orm-(?:postgres|sqlite|family-sql/contract-ts)/contract-builder[''"]'
|
|
296
309
|
- id: typescript-contract-storage-and-domain-types
|
|
297
310
|
summary: |
|
|
298
|
-
A contract built with `defineContract` now types its unique constraints with their columns, so `whereUnique` accepts only the fields of the primary key or of one unique constraint, as with an emitted contract; it no longer accepts any record. `db.enums` lists only the enums the contract declares; a contract without enums no longer offers an accessor under any name. A many-to-many relation whose target has no primary key types its junction columns from the target's unique key. The detection matches `
|
|
311
|
+
A contract built with `defineContract` now types its unique constraints with their columns, so `whereUnique` accepts only the fields of the primary key or of one unique constraint, as with an emitted contract; it no longer accepts any record. `db.enums` lists only the enums the contract declares; a contract without enums no longer offers an accessor under any name. A many-to-many relation whose target has no primary key types its junction columns from the target's unique key. The detection matches a file that imports `defineContract` from a SQL contract builder; the change matters only where code queries through the contract it builds without an emitted `contract.d.ts`.
|
|
299
312
|
detection:
|
|
300
313
|
glob: "**/*.{ts,mts,cts,tsx}"
|
|
301
314
|
matches:
|
|
302
|
-
- '
|
|
303
|
-
- '\.enums\.'
|
|
315
|
+
- '\bimport\s*\{[^}]*\bdefineContract\b[^}]*\}\s*from\s*[''"]@prisma/orm-(?:postgres|sqlite|family-sql/contract-ts)/contract-builder[''"]'
|
|
304
316
|
- id: typescript-contract-enums-in-domain
|
|
305
317
|
summary: |
|
|
306
318
|
The type of a contract built with `defineContract` carries its enums as an emitted `contract.d.ts` does: in the domain namespace's `enum` and `enumMemberTypes`, and in the storage namespace's `valueSet`. The type-only `enumAccessors` key is gone. `db.enums` reads its accessors from `enumMemberTypes` for both kinds of contract, so its types are the emitted ones: `has(value)` takes any value and narrows it to the enum's values, and `nameOf` and `ordinalOf` take the enum's values as before. An `enumType` keeps its codec id as a literal, so its fields gain their codec's query methods, such as `eq`, `ilike`, `gt` and `asc`. Code that read `enumAccessors` from the contract's type should use `NamespacedEnums<typeof contract>` from `@prisma/orm-framework/contract/enum-accessor`, or `db.enums`. The detection matches reads of `enumAccessors`.
|
|
@@ -310,14 +322,14 @@ changes:
|
|
|
310
322
|
- 'enumAccessors'
|
|
311
323
|
- id: emitted-contract-types-from-generics
|
|
312
324
|
summary: |
|
|
313
|
-
`prisma contract emit` now writes the field and storage column type maps of a SQL contract (`FieldOutputTypes`, `FieldInputTypes`, `StorageColumnTypes`, `StorageColumnInputTypes`) as generics applied to the contract's own shape, the ones a contract built with `defineContract` uses, with only the types a codec computes at emit time written out (`FieldTypeOverrides`, `ColumnTypeOverrides`). A column with type parameters is typed through the pack's type function (`ParameterizedOutputTypeFunctions`) instead of a named type such as `Char<24>`; it resolves to the same type. `Models` members index `FieldOutputTypes`. The types do not change; re-emit to update the committed `contract.d.ts`. The extension metadata in `contract.json` changes too: a pack's codec types name their `parameterizedOutputTypes` instead of `typeImports` such as `Vector`. Migration snapshots keep the form they were written in and need no change. The detection matches a SQL `contract.d.ts` emitted before this change; Mongo contracts never have `StorageColumnTypes`.
|
|
325
|
+
`prisma contract emit` now writes the field and storage column type maps of a SQL contract (`FieldOutputTypes`, `FieldInputTypes`, `StorageColumnTypes`, `StorageColumnInputTypes`) as generics applied to the contract's own shape, the ones a contract built with `defineContract` uses, with only the types a codec computes at emit time written out (`FieldTypeOverrides`, `ColumnTypeOverrides`). A column with type parameters is typed through the pack's type function (`ParameterizedOutputTypeFunctions`) instead of a named type such as `Char<24>`; it resolves to the same type. `Models` members index `FieldOutputTypes`. The types do not change; re-emit to update the committed `contract.d.ts`. The extension metadata in `contract.json` changes too: a pack's codec types name their `parameterizedOutputTypes` instead of `typeImports` such as `Vector`. Migration snapshots keep the form they were written in and need no change. The detection matches a SQL `contract.d.ts` emitted before this change; Mongo contracts never have `StorageColumnTypes`. It also matches the `contract.d.ts` of each migration snapshot (`migrations/snapshots/<hash>/`); leave those as they are.
|
|
314
326
|
detection:
|
|
315
327
|
glob: "**/contract.d.ts"
|
|
316
328
|
matches:
|
|
317
329
|
- 'export type StorageColumnTypes = \{'
|
|
318
330
|
- id: emitted-field-types-from-shared-generic
|
|
319
331
|
summary: |
|
|
320
|
-
`prisma contract emit` now writes `FieldOutputTypes` and `FieldInputTypes` of every contract, Mongo and SQL, as `FieldTypesFromDomain` from the contract types entry (`@prisma/orm-mongo/contract/types`, `@prisma/orm-postgres/contract/types`, `@prisma/orm-sqlite/contract/types`) applied to the contract's own shape, and each `<Name>Output` and `<Name>Input` value object type as an entry of `ValueObjectTypesFromDomain`. A Mongo vector field with a length is typed through the target's type function instead of the written-out `Vector<N>`. The types do not change; re-emit every `contract.d.ts`. A SQL `contract.d.ts` written by a development build after 8.0.0-rc.18 imports `FieldTypesFromDomain` from the family contract types entry, which no longer exports it, so it does not compile until it is re-emitted. The detection matches a `contract.d.ts` that writes its field types out, as one emitted by 8.0.0-rc.18 does, and a SQL one that imports the generic from the family entry.
|
|
332
|
+
`prisma contract emit` now writes `FieldOutputTypes` and `FieldInputTypes` of every contract, Mongo and SQL, as `FieldTypesFromDomain` from the contract types entry (`@prisma/orm-mongo/contract/types`, `@prisma/orm-postgres/contract/types`, `@prisma/orm-sqlite/contract/types`) applied to the contract's own shape, and each `<Name>Output` and `<Name>Input` value object type as an entry of `ValueObjectTypesFromDomain`. A Mongo vector field with a length is typed through the target's type function instead of the written-out `Vector<N>`. The types do not change; re-emit every `contract.d.ts`. A SQL `contract.d.ts` written by a development build after 8.0.0-rc.18 imports `FieldTypesFromDomain` from the family contract types entry, which no longer exports it, so it does not compile until it is re-emitted. The detection matches a `contract.d.ts` that writes its field types out, as one emitted by 8.0.0-rc.18 does, and a SQL one that imports the generic from the family entry. It also matches the `contract.d.ts` of each migration snapshot (`migrations/snapshots/<hash>/`), which no command emits again; leave those as they are.
|
|
321
333
|
detection:
|
|
322
334
|
glob: "**/contract.d.ts"
|
|
323
335
|
matches:
|
|
@@ -325,12 +337,11 @@ changes:
|
|
|
325
337
|
- 'FieldTypesFromDomain,\s+RelationKeys,'
|
|
326
338
|
- id: value-object-enum-fields-narrow
|
|
327
339
|
summary: |
|
|
328
|
-
An enum field inside a value object (a composite type in PSL) now reads and writes the members of its enum, in an emitted `contract.d.ts` and in a contract built with `defineContract`, as an enum field of a model does. Before, the emitted contract typed it as its codec's type, such as `string`. A value object field whose codec renders its own type text, such as `arktype/json@1`, has that type, as before this change. Code that assigns an arbitrary string to such a field now fails to typecheck. Re-emit `contract.d.ts`. The detection matches PSL sources
|
|
340
|
+
An enum field inside a value object (a composite type in PSL) now reads and writes the members of its enum, in an emitted `contract.d.ts` and in a contract built with `defineContract`, as an enum field of a model does. Before, the emitted contract typed it as its codec's type, such as `string`. A value object field whose codec renders its own type text, such as `arktype/json@1`, has that type, as before this change. Code that assigns an arbitrary string to such a field now fails to typecheck. Re-emit `contract.d.ts`. The detection matches PSL sources that declare both an enum and a composite type, so check whether a field of the composite type has the enum's type (an enum in another file of a multi-file schema is not found), and TypeScript value objects whose fields include an enum field, also in the factory form of `defineContract` with renamed helpers.
|
|
329
341
|
detection:
|
|
330
342
|
glob: "**/*.{prisma,ts,mts,cts,tsx}"
|
|
331
343
|
matches:
|
|
332
|
-
- '(
|
|
333
|
-
- '(?:^|\n)type\s+\w+\s*\{[^}]*\s(\w+)[?\[\]]*\s[\s\S]*\n\s*enum\s+\1\s*\{'
|
|
344
|
+
- '(?<![\s\S])(?=(?:[\s\S]*\n)?enum[ \t]+\w+\s*\{)(?:[\s\S]*\n)?[ \t]*type[ \t]+\w+\s*\{'
|
|
334
345
|
- '(?:\bvalueObject|\bvalueObject\s*:\s*(\w+)[\s\S]*?\b\1)\(\s*[''"][^''"]+[''"]\s*,\s*\{\s*fields:\s*\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\.namedType\('
|
|
335
346
|
- id: mongo-contracts-record-stored-field-names
|
|
336
347
|
summary: |
|
|
@@ -343,12 +354,14 @@ changes:
|
|
|
343
354
|
script: ./scripts/mongo-field-storage-names/mongo-field-storage-names.ts
|
|
344
355
|
- id: mongo-orm-uses-field-names
|
|
345
356
|
summary: |
|
|
346
|
-
The MongoDB ORM names every field by its name in the schema: a field declared `id ObjectId @id @map("_id")` is `user.id` in rows and `where({ id })`, `select('id')`, `orderBy({ id: 1 })` and create, update and upsert data, where it was `_id`. Passing a stored name such as `_id` fails with `ORM.FIELD_UNKNOWN`, and a row no longer carries a key that no field stores. The pipeline builder (`db.query`) works on documents and keeps naming stored names (`_id`).
|
|
357
|
+
The MongoDB ORM names every field by its name in the schema: a field declared `id ObjectId @id @map("_id")` is `user.id` in rows and `where({ id })`, `select('id')`, `orderBy({ id: 1 })` and create, update and upsert data, where it was `_id`. Passing a stored name such as `_id` fails with `ORM.FIELD_UNKNOWN`, and a row no longer carries a key that no field stores. The pipeline builder (`db.query`) works on documents and keeps naming stored names (`_id`). This applies only to a project with a MongoDB contract; skip it otherwise. The detection matches code that reads or names `_id`, outside generated `contract.d.ts` files, contract sources and `migration.ts`; a match in pipeline code needs no change. It cannot find other fields with `@map`; the type checker finds them after you re-emit.
|
|
347
358
|
detection:
|
|
348
359
|
glob: "**/*.{ts,tsx,mts,cts,js,mjs,cjs}"
|
|
349
360
|
matches:
|
|
350
|
-
- '
|
|
351
|
-
- '(?<![\w$])_id\s
|
|
361
|
+
- '(?<![\s\S])(?![\s\S]*(?:GENERATED FILE - DO NOT EDIT|\bdefineContract\b|\bextends\s+Migration\b))[\s\S]*\._id\b'
|
|
362
|
+
- '(?<![\s\S])(?![\s\S]*(?:GENERATED FILE - DO NOT EDIT|\bdefineContract\b|\bextends\s+Migration\b))[\s\S]*(?<![\w$])_id\s*[:,}]'
|
|
363
|
+
- '(?<![\s\S])(?![\s\S]*(?:GENERATED FILE - DO NOT EDIT|\bdefineContract\b|\bextends\s+Migration\b))[\s\S]*\.(?:select|orderBy|include|where|distinct)\([^)]*[''"]_id[''"]'
|
|
364
|
+
- '(?<![\s\S])(?![\s\S]*(?:GENERATED FILE - DO NOT EDIT|\bdefineContract\b|\bextends\s+Migration\b))[\s\S]*\b(?:Omit|Pick)<[^>]*[''"]_id[''"]'
|
|
352
365
|
- id: mongo-statements-name-fields
|
|
353
366
|
summary: |
|
|
354
367
|
A MongoDB `--rename` or `--delete` statement names a field by its name in the schema, as on SQL: `id @map("_id")` is `User.id`, where it was `User._id`. A rename that keeps the stored name, such as `--rename User.name:User.title` with both stored as `display_name`, plans nothing; a field whose `@map` changes while its name stays is asked about as a removal, as a column is on SQL; to keep its values, write `renameField(...)` into the planned `migration.ts`.
|
|
@@ -372,21 +385,21 @@ changes:
|
|
|
372
385
|
detection:
|
|
373
386
|
glob: "**/*.{ts,mts,cts,tsx}"
|
|
374
387
|
matches:
|
|
375
|
-
- '(?<![\s\S])(?=[\s\S]*orm-mongo/contract-builder)[\s\S]*(\.many\(|\.valueObject\(|\.vector\()'
|
|
388
|
+
- '(?<![\s\S])(?=[\s\S]*orm-(?:mongo|family-mongo/contract-ts)/contract-builder)[\s\S]*(\.many\(|\.valueObject\(|\.vector\()'
|
|
376
389
|
- id: mongo-define-contract-factory-field-types
|
|
377
390
|
summary: |
|
|
378
391
|
`defineContract(scaffold, factory)` from `@prisma/orm-mongo/contract-builder` typed every codec, and so every field, row and create input, as `never`, because the scaffold's forbidden `family` and `target` keys made the whole definition type `never`. The contract type now leaves them out, so fields have their codec types. Code that compiled only because a field was `never`, such as assigning a row field to an unrelated type, now fails to typecheck. The detection matches the factory form of the Mongo `defineContract`.
|
|
379
392
|
detection:
|
|
380
393
|
glob: "**/*.{ts,mts,cts,tsx}"
|
|
381
394
|
matches:
|
|
382
|
-
- '(?<![\s\S])(?=[\s\S]*orm-mongo/contract-builder)[\s\S]*defineContract\(\s*(?:\w+|\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})\s*,\s*(?:\(|function\b|\w+\s*=>)'
|
|
395
|
+
- '(?<![\s\S])(?=[\s\S]*orm-(?:mongo|family-mongo/contract-ts)/contract-builder)[\s\S]*defineContract\(\s*(?:\w+|\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})\s*,\s*(?:\(|function\b|\w+\s*=>)'
|
|
383
396
|
- id: mongo-update-accessors-take-input-types
|
|
384
397
|
summary: |
|
|
385
398
|
In Mongo ORM updates, the field accessor's `set`, `push`, `pull` and `addToSet` take each field's input type from the contract, including fields reached by a dot path into a value object. `u.role.set(...)` on an enum field takes only its members, a list field takes a readonly list, and a vector field takes `readonly number[]`, which a `Vector<N>` satisfies. Code that passed a value outside an enum now fails to typecheck. A list of numbers no longer offers `inc` and `mul`, which only a single number takes. The detection matches update callbacks, `(u) => [...]`, that call one of these methods on a field of their argument, by name or by a dot path such as `u('home.kind')`.
|
|
386
399
|
detection:
|
|
387
400
|
glob: "**/*.{ts,mts,cts,tsx}"
|
|
388
401
|
matches:
|
|
389
|
-
- '\
|
|
402
|
+
- '(?:\(\s*)?(?<![\w$])(\w+)\s*\)?\s*=>\s*\[[^\]]*?\b\1(?:\.\w+|\(\s*[''"][^''"]+[''"]\s*\))+\.(?:set|push|pull|addToSet|inc|mul)\('
|
|
390
403
|
- id: mongo-typescript-contract-validator
|
|
391
404
|
summary: |
|
|
392
405
|
A MongoDB contract written in TypeScript with `defineContract` now gets the same closed collection validator as a PSL contract, and its storage hash changes once. `defineContract` refuses what a validator cannot describe: a field whose codec has no MongoDB data type, a model whose `_id` field can hold an array, a regular expression, undefined or null, an enum a validator cannot list, and an embed relation to a model with variants. MongoDB does not check existing documents when a validator is added, so find and fix the documents the validator would refuse, then apply it with `prisma db update`, or with `prisma migration plan` and `prisma db migrate`. Writing an enum in a TypeScript contract to avoid the validator, as the rc.17 notes advised, no longer works.
|
|
@@ -412,9 +425,9 @@ changes:
|
|
|
412
425
|
summary: |
|
|
413
426
|
A failed migration apply reports the runner's own code, such as `MIGRATION.SCHEMA_VERIFY_FAILED`, `MIGRATION.PRECHECK_FAILED`, `MIGRATION.POSTCHECK_FAILED` or `MIGRATION.EXECUTION_FAILED`, instead of `MIGRATION.RUNNER_FAILED` with `meta.runnerErrorCode`. `MIGRATION.RUNNER_FAILED` no longer exists. The facts move into typed `meta` keys: a failed schema check lists its issues in `meta.schemaIssues` (was `meta.issues`), and a failed check is `meta.failedCheck` (`operationId`, `phase`, `description`; was `operationId`, `phase`, `stepDescription`).
|
|
414
427
|
detection:
|
|
415
|
-
glob: "
|
|
428
|
+
glob: "**/*.{ts,tsx,mts,cts,js,mjs,cjs,sh}"
|
|
416
429
|
matches:
|
|
417
|
-
- 'RUNNER_FAILED
|
|
430
|
+
- 'MIGRATION\.RUNNER_FAILED|\brunnerErrorCode\b'
|
|
418
431
|
- id: setdefault-operation-class-derived
|
|
419
432
|
summary: |
|
|
420
433
|
On PostgreSQL, `this.setDefault` in `migration.ts` no longer takes `operationClass`. The operation is widening when the migration's start contract gives the column a default, and additive otherwise. `migration plan` no longer writes `operationClass` into the call. A `migration.ts` that passes it no longer type-checks; delete the option.
|
|
@@ -576,12 +589,12 @@ Several changes in this release rewrite stored contracts and change storage hash
|
|
|
576
589
|
|
|
577
590
|
1. Commit your work, so every script's changes can be reviewed and undone with git. Then upgrade the Prisma packages.
|
|
578
591
|
2. Rewrite the stored contracts, from the project root: first `scripts/remove-nocheck/remove-nocheck.ts` (`stored-contracts-drop-nocheck`), then `scripts/data-type-values/data-type-values.ts` (`sqlite-contracts-name-datetime-and-json-data-types`). Each script leaves a project it does not apply to unchanged and says so.
|
|
579
|
-
3. If either script changed a storage hash, run `prisma db sign` against every database.
|
|
592
|
+
3. If either script changed a storage hash, run `prisma db sign` against every database. Sign a database that has not applied every migration with `--contract <the last migration it applied>`, as `stored-contracts-drop-nocheck` describes, and migrate it in step 8.
|
|
580
593
|
4. Change the contract source as the entries below say. `scripts/default-generators-to-on-create/rewrite-default-generators.mjs` rewrites `@default(uuid())` and the other client generators in Prisma 8 schema files (`client-functions-move-from-default-to-on-create`).
|
|
581
594
|
5. Run `prisma contract emit`. In a MongoDB project, then run `scripts/mongo-field-storage-names/mongo-field-storage-names.ts` (`mongo-contracts-record-stored-field-names`).
|
|
582
|
-
6.
|
|
583
|
-
7.
|
|
584
|
-
8.
|
|
595
|
+
6. Change the application code and every `migration.ts`. `scripts/client-takes-contract-value/contract-from-json.ts` moves each client to a contract value (`client-takes-contract-value`); a `migration.ts` that builds a client from `contractJson` fails to load on this release until it is moved. In `migration.ts`, also delete `operationClass` from `setDefault` (`setdefault-operation-class-derived`) and rewrite an `alterColumnType` that `postgres-alter-column-type-unchanged-refused` refuses.
|
|
596
|
+
7. For each migration that is not applied yet, write its `ops.json` again when a postcheck entry at the end of this guide matches it: run its `migration.ts` (`node migration.ts`). Do this before any database applies the migration, or it applies with the old checks.
|
|
597
|
+
8. Bring each database to the new contract: sign it where an entry says the database does not change (`sign-databases-after-data-type-values`, `prisma7-lists-allow-null-elements`, `supabase-contract-lists-allow-null-elements`), and plan and apply a migration where an entry says one is needed.
|
|
585
598
|
|
|
586
599
|
The script paths are relative to the directory that holds this guide, which the commands below call `<guide>`.
|
|
587
600
|
|
|
@@ -589,7 +602,7 @@ The script paths are relative to the directory that holds this guide, which the
|
|
|
589
602
|
|
|
590
603
|
Prisma 8 adds a check to a list column of a managed table so that its elements cannot be null, and a check to an enum-typed column so that it holds only the enum's values. `@noCheck` in PSL and `.noCheck()` in TypeScript used to skip these checks while the field kept its non-null element type. The client type then said the elements could not be null while the database accepted null. Both are removed.
|
|
591
604
|
|
|
592
|
-
Do the steps in this order: rewrite the stored contracts and sign the databases (`stored-contracts-drop-nocheck`), then change the contract source (`psl-nocheck-removed`, `ts-nocheck-method-removed`), then re-emit and
|
|
605
|
+
Do the steps in this order: rewrite the stored contracts and sign the databases (`stored-contracts-drop-nocheck`), then change the contract source (`psl-nocheck-removed`, `ts-nocheck-method-removed`), then re-emit. Plan and apply a migration in step 8 of "Order of the steps", after each `ops.json` is written again.
|
|
593
606
|
|
|
594
607
|
### `stored-contracts-drop-nocheck`
|
|
595
608
|
|
|
@@ -599,17 +612,20 @@ Migration snapshots, the emitted `contract.json` and any other stored contract w
|
|
|
599
612
|
node <guide>/scripts/remove-nocheck/remove-nocheck.ts
|
|
600
613
|
```
|
|
601
614
|
|
|
602
|
-
`<guide>` is the directory that holds this guide. Node 24 or later runs the TypeScript script directly; it needs no `tsx`. The script reads and writes files only and needs no database. It rewrites every
|
|
615
|
+
`<guide>` is the directory that holds this guide. Node 24 or later runs the TypeScript script directly; it needs no `tsx`. The script reads and writes files only and needs no database. It rewrites every `*.json` file under the root that is a SQL contract, whatever its name, skipping `node_modules`, `dist`, `build` and every directory whose name starts with a dot, such as `.git`, `.agents` or `.claude`. It follows links to files and directories, also outside the root; commit or back up the files there too. That includes a test fixture of an old contract: if you keep one on purpose, restore it with git afterwards. A copy of the project under a directory whose name starts with a dot, such as a worktree under `.claude/worktrees/`, is left alone: run the script in that copy separately. The script takes the project root and one option, `--default`, described below; any other option, a malformed `--default` or a root that is not a directory makes it print its usage and exit 1.
|
|
603
616
|
|
|
604
|
-
In each contract it removes the `noCheck` key from every column. Where the key waived the element check of a list, it also makes the column, the field that maps it and their types in `contract.d.ts` lists whose elements may be null. That is what the database allows, and it is what the source says after `psl-nocheck-removed` or `ts-nocheck-method-removed`. The script does not change which checks a contract declares: an enum column whose membership check was waived still has none until you migrate.
|
|
617
|
+
In each contract it removes the `noCheck` key from every column. Where the key waived the element check of a list, it also makes the column, the field that maps it and their types in `contract.d.ts`, the row types such as `ReadonlyArray<CodecTypes['pg/text@1']['output'] | null>` included, lists whose elements may be null. That is what the database allows, and it is what the source says after `psl-nocheck-removed` or `ts-nocheck-method-removed`. The script does not change which checks a contract declares: an enum column whose membership check was waived still has none until you migrate.
|
|
605
618
|
|
|
606
|
-
|
|
619
|
+
In each PostgreSQL contract it also writes each literal default in the form this release stores, for example `"1.5"` on `numeric(10,2)` as `"1.50"` (`postgres-defaults-stored-in-another-spelling`). The script carries this release's rules for each PostgreSQL built-in data type and for the extension data types `postgis/geometry` and `pgvector/vector`, so its result does not depend on the installed packages. A geometry default is written as the upper-case little-endian HEXEWKB PostGIS prints, whatever case and byte order it had. It leaves a default of any other data type as it is.
|
|
607
620
|
|
|
608
|
-
|
|
621
|
+
The storage hash changes, so the script renames each changed snapshot directory to its new hash. It rewrites every `migration.json`, ref, `migration.ts` and `contract.d.ts` that names an old hash, and gives each changed migration a new `migrationHash`. When it finishes, it prints how many files it rewrote, how many snapshot directories it renamed, and each storage hash it replaced (`<old> -> <new>`). A project with no `noCheck` key and no default in another form is left unchanged, and the script says so.
|
|
609
622
|
|
|
610
|
-
|
|
623
|
+
It changes no file and exits 1 in four cases, and names the file:
|
|
624
|
+
|
|
625
|
+
- a `contract.json`, `migration.json` or ref is not valid JSON, or the `ops.json` of a migration whose hashes change is not;
|
|
611
626
|
- a contract's stored storage hash, or the name of its snapshot directory, does not match its content. Restore that file from version control, or re-emit it, and run the script again;
|
|
612
|
-
- a renamed snapshot directory already exists with different content
|
|
627
|
+
- a renamed snapshot directory already exists with different content;
|
|
628
|
+
- this release refuses a PostgreSQL default: it is not a value of its column's type, for example a time with more fraction digits than its column holds, a `pgvector/vector` element that `real` cannot hold exactly, or a `postgis/geometry` in another SRID than its column's; or a list column's default is not a list. The script names the column. Do not edit the stored file: that breaks its storage hash, and the next run refuses it. Instead choose the value the database stores, and run the script again with that value as JSON, for example `--default 'public.product.opensAt="12:34:00.123457"'`. The script stores it in every stored contract where that column's default is refused, migration snapshots included, checks it by the same rules and refreshes the hashes. It stops when the value is refused too, or when a `--default` names a column whose default it does not refuse. Then change the default in the contract source to the same value, so that `prisma contract emit` writes it.
|
|
613
629
|
|
|
614
630
|
If it stops partway, for example on a full disk, it says so; run it again to finish.
|
|
615
631
|
|
|
@@ -621,6 +637,16 @@ prisma db sign --db "$DATABASE_URL"
|
|
|
621
637
|
|
|
622
638
|
`db sign` checks the database against the rewritten contract and writes the new hash to its marker.
|
|
623
639
|
|
|
640
|
+
A plain `prisma db sign` checks the database against the emitted contract, so it signs only a database that has applied every migration. A database that has not, such as production while the latest migrations wait for review, is refused: `db sign` says its schema does not satisfy the contract, and `prisma db migrate` stops with `MIGRATION.MARKER_MISMATCH`, because the marker holds an old hash that no migration names any more. Sign such a database with the contract of the last migration it applied:
|
|
641
|
+
|
|
642
|
+
```sh
|
|
643
|
+
prisma db sign --contract <the last migration it applied> --db "$DATABASE_URL"
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
Then apply the other migrations with `prisma db migrate` in step 8 of "Order of the steps", after step 7 has written their `ops.json` again.
|
|
647
|
+
|
|
648
|
+
`--contract` takes the migration's directory name, such as `20260917T0818_add_post_expires_at`, or the new hash that migration goes to. To find it, run `prisma migration status` against the database. It prints the start of the old hash the marker holds: `Database marker <hash> is not in the on-disk migration graph`. The error of `prisma db migrate` prints the whole hash: `DB marker is <hash>`. Find the line of the script's `<old> -> <new>` list whose old hash is that one. The new hash on that line is the one to sign with, and the migration that goes to it is the last one the database applied.
|
|
649
|
+
|
|
624
650
|
The script also gives each rewritten migration a new hash, and the database's migration history keeps the old ones. After the upgrade, `prisma migration status` therefore no longer marks the migrations applied before it as applied, although it still reports the database as up to date. Nothing else is affected: `prisma db migrate` runs none of them again, `prisma db verify` passes, and migrations you plan and apply after the upgrade are marked as usual.
|
|
625
651
|
|
|
626
652
|
### `psl-nocheck-removed`
|
|
@@ -637,9 +663,9 @@ tags String?[]
|
|
|
637
663
|
|
|
638
664
|
The element type gains `| null`, so code that reads the list must handle null elements. The database does not change: neither form has a check. If you ran `stored-contracts-drop-nocheck`, re-emitting gives the contract the script wrote, so there is nothing to sign or migrate. If you did not, re-emit and then run `prisma db sign` against every database.
|
|
639
665
|
|
|
640
|
-
If you want the check instead, delete the attribute and keep `T[]`. Re-emit, then run `prisma migration plan` and `prisma db migrate`, or `prisma db update` in a project without migrations. The migration adds the check. Applying it fails if a stored list already holds a null element, so fix those rows first.
|
|
666
|
+
If you want the check instead, delete the attribute and keep `T[]`. Re-emit, then, in step 8 of "Order of the steps", run `prisma migration plan` and `prisma db migrate`, or `prisma db update` in a project without migrations. The migration adds the check. Applying it fails if a stored list already holds a null element, so fix those rows first.
|
|
641
667
|
|
|
642
|
-
Delete `@noCheck(membership)`. Re-emit, then plan and apply a migration the same way. The migration adds the membership check to the enum column. Applying it fails if a stored value is not one of the enum's values, so fix those rows first.
|
|
668
|
+
Delete `@noCheck(membership)`. Re-emit, then plan and apply a migration the same way, in step 8. The migration adds the membership check to the enum column. Applying it fails if a stored value is not one of the enum's values, so fix those rows first.
|
|
643
669
|
|
|
644
670
|
A bare `@noCheck` waived every check the column had. Apply both rules above: a list column becomes `T?[]`, and an enum column loses the attribute.
|
|
645
671
|
|
|
@@ -698,14 +724,14 @@ Commit your work first, so the script's changes can be reviewed and undone with
|
|
|
698
724
|
node <guide>/scripts/data-type-values/data-type-values.ts
|
|
699
725
|
```
|
|
700
726
|
|
|
701
|
-
Node 24 or later runs the TypeScript script directly; it needs no `tsx`. It reads and writes files only and needs no database. It rewrites every `*.json` file under the root that parses as a SQLite contract in the previous release's form, skipping `node_modules`,
|
|
727
|
+
Node 24 or later runs the TypeScript script directly; it needs no `tsx`. It reads and writes files only and needs no database. It rewrites every `*.json` file under the root that parses as a SQLite contract in the previous release's form, skipping `node_modules`, `dist`, `build` and every directory whose name starts with a dot, such as `.git`, `.agents` or `.claude`, and follows links to files and directories, also outside the root; commit or back up the files there too. That includes a test fixture of a contract in the previous release's form: if you keep such a fixture on purpose, restore it with git afterwards (`git restore <file>`), or keep it outside the project root. In each contract it changes:
|
|
702
728
|
|
|
703
729
|
- the `dataType` of each column and named type whose codec is `sqlite/datetime@1` or `sqlite/json@1`, from `sqlite/text` to `sqlite/datetime` or `sqlite/json`;
|
|
704
730
|
- each literal default of a `sqlite/datetime@1` column, and each value of an enum typed by `sqlite/datetime@1`, to three fraction digits: `"2024-01-01T00:00:00Z"` becomes `"2024-01-01T00:00:00.000Z"`, and `"2024-01-01T00:00:00.5Z"` becomes `"2024-01-01T00:00:00.500Z"`. A JSON default keeps its value.
|
|
705
731
|
|
|
706
732
|
It then writes the storage hash each contract now has, renames the contract's snapshot directory under `migrations/snapshots/` to that hash, and replaces the old hash in every `migration.json` (recomputing its `migrationHash`), every ref under `refs/`, every `migration.ts` and every `contract.d.ts`. The planned SQL does not change: SQLite stores the same text in the column default.
|
|
707
733
|
|
|
708
|
-
When it finishes, it prints how many files it rewrote and how many snapshot directories it renamed, and each storage hash it replaced (`<old> -> <new>`). A project already in the new form is left unchanged, and the script says so. If it finds no SQLite contract under the root, it says so;
|
|
734
|
+
When it finishes, it prints how many files it rewrote and how many snapshot directories it renamed, and each storage hash it replaced (`<old> -> <new>`). A project already in the new form is left unchanged, and the script says so. If it finds no SQLite contract under the root, it says so and changes nothing; that is the expected result in a PostgreSQL or MongoDB project. In a SQLite project, check that you ran it from the project root. It prints `<file>: stored hash did not recompute; rehashed from content` for a contract whose stored hash does not match its content, and rewrites it anyway. It changes no file and exits 1 when a `contract.json`, `migration.json` or ref is not valid JSON, when the `ops.json` of a migration whose hashes change is not valid JSON, or when a renamed snapshot directory already exists with different content. An option or a project root that is not a directory makes it print its usage and exit 1.
|
|
709
735
|
|
|
710
736
|
If the script stops on an error partway, for example on a full disk, it prints the error and `the upgrade stopped partway, run the script again to finish it`, and exits 1. Run it again: it finishes the upgrade and removes its own temporary files (ending in `.data-type-values-tmp`).
|
|
711
737
|
|
|
@@ -774,7 +800,11 @@ The cases are:
|
|
|
774
800
|
- a number default spelled without its scale, such as `"1.5"` on `numeric(10,2)`, which is now `"1.50"`;
|
|
775
801
|
- a `char` default padded with spaces, which is now stored without them;
|
|
776
802
|
- a time default with more fraction digits than its column's precision;
|
|
777
|
-
- a date or time default in a spelling earlier releases stored: an instant with `.000Z` (`"2024-01-01T00:00:00.000Z"` is now `"2024-01-01T00:00:00Z"`), an offset such as `+01:00` on a `timestamptz` (now converted to `Z`), a time without seconds (`"12:34"` is now `"12:34:00"`), or a space instead of `T` between date and time
|
|
803
|
+
- a date or time default in a spelling earlier releases stored: an instant with `.000Z` (`"2024-01-01T00:00:00.000Z"` is now `"2024-01-01T00:00:00Z"`), an offset such as `+01:00` on a `timestamptz` (now converted to `Z`), a time without seconds (`"12:34"` is now `"12:34:00"`), or a space instead of `T` between date and time;
|
|
804
|
+
- a `postgis/geometry` default in lower-case or big-endian HEXEWKB, which is now upper-case little-endian HEXEWKB, as PostGIS prints it, or a geometry whose SRID is not its column's;
|
|
805
|
+
- a `pgvector/vector` default with an element that `real` cannot hold exactly, such as `0.123456789`, which the database stores as `0.12345679`.
|
|
806
|
+
|
|
807
|
+
Migration snapshots store defaults too. `migration plan`, `migration check` and every other command that reads a snapshot refuse an old one the same way, and name it (`Predecessor contract at migrations/snapshots/<hash>/contract.json failed to deserialize: ...`). A snapshot cannot be emitted again, so `scripts/remove-nocheck/remove-nocheck.ts` rewrites it (`stored-contracts-drop-nocheck`). It writes each default of every stored PostgreSQL contract in the form this release stores, renames each changed snapshot directory to its new storage hash, and rewrites every migration, ref, `migration.ts` and `contract.d.ts` that names an old hash. A snapshot rewritten this way has the storage hash `contract emit` gives the same schema, so `migration plan` plans nothing for this change. If a default is not a value of its column's type at all, for example a time with more fraction digits than its column holds, the script changes no file, names the file and column, and exits 1. Run it again with `--default` and the value the database stores, as `stored-contracts-drop-nocheck` describes; do not edit the stored file.
|
|
778
808
|
|
|
779
809
|
Then run `prisma contract emit`, which writes the default in the new spelling, then `prisma db sign` (`sign-databases-after-data-type-values`). Two kinds of default in the schema need rewriting first, or `contract emit` refuses them:
|
|
780
810
|
|
|
@@ -848,6 +878,8 @@ prisma contract emit
|
|
|
848
878
|
prisma db sign --db "$DATABASE_URL"
|
|
849
879
|
```
|
|
850
880
|
|
|
881
|
+
A database that has not applied every migration is refused by a plain `prisma db sign`. Sign it with `prisma db sign --contract <the last migration it applied>`, then migrate it, as `stored-contracts-drop-nocheck` describes. `data-type-values.ts` prints its `<old> -> <new>` list in the same form.
|
|
882
|
+
|
|
851
883
|
## Client generators are written `@onCreate(...)` and `@onUpdate(...)`
|
|
852
884
|
|
|
853
885
|
Prisma 8 PSL now says who writes a value. `@default(...)` is a database default: the database fills the column when an insert leaves it out. `@onCreate(fn())` and `@onUpdate(fn())` are values the client generates, on create and on every update. A function resolves for the column's codec, so `uuid()` works on `String`, `VarChar(n)`, `Char(n)` and `Uuid`, and `now()` gives each date and time type the value its codec takes.
|
|
@@ -872,15 +904,15 @@ model Post {
|
|
|
872
904
|
|
|
873
905
|
### `client-functions-move-from-default-to-on-create`
|
|
874
906
|
|
|
875
|
-
Commit your work first, so the change can be reviewed and undone with git. Run the script with every
|
|
907
|
+
Commit your work first, so the change can be reviewed and undone with git. Run the script from the project root with every `.prisma` file git tracks as arguments:
|
|
876
908
|
|
|
877
909
|
```sh
|
|
878
|
-
node <guide>/scripts/default-generators-to-on-create/rewrite-default-generators.mjs
|
|
910
|
+
git ls-files -z '*.prisma' | xargs -0 node <guide>/scripts/default-generators-to-on-create/rewrite-default-generators.mjs
|
|
879
911
|
```
|
|
880
912
|
|
|
881
|
-
`<guide>` is the directory that holds this guide. The script reads and rewrites only the files it is given. For each one it prints how many calls it rewrote, or that it left the file unchanged. It rewrites every `@default(uuid(...))`, `@default(cuid(...))`, `@default(ulid())` and `@default(nanoid(...))` to `@onCreate(...)`, keeping the call exactly as written, spaces included, and changes nothing else. It leaves string literals and `//` comments unchanged and does not count them, so rewrite a commented-out field yourself if you want it in step.
|
|
913
|
+
`<guide>` is the directory that holds this guide. Pass every file, not only the schema `contract emit` reads: a migration directory can hold a copy of the schema, such as `migrations/app/<migration>/intermediate.prisma` or a `contract.prisma` beside a migration, and the CLI reads those too. The script reads and rewrites only the files it is given, and with no file it prints its usage and exits 1. For each one it prints how many calls it rewrote, or that it left the file unchanged. It rewrites every `@default(uuid(...))`, `@default(cuid(...))`, `@default(ulid())` and `@default(nanoid(...))` to `@onCreate(...)`, keeping the call exactly as written, spaces included, and changes nothing else. It leaves string literals and `//` comments unchanged and does not count them, so rewrite a commented-out field yourself if you want it in step.
|
|
882
914
|
|
|
883
|
-
|
|
915
|
+
A Prisma 7 `schema.prisma` that your config reads with `prisma7Schema(...)` keeps `@default(uuid())`, and the Prisma 7 reader turns it into the same generator. Passing it is safe: the script rewrites only a file that has the `// use prisma-8` directive (or the older `// use prisma-next`), read by the same rule `contract emit` uses. It leaves every other file unchanged and prints a line for it, so a Prisma 7 schema split across files is safe even when a file holds only models.
|
|
884
916
|
|
|
885
917
|
The contract does not change: `@onCreate(uuid())` lowers to the generator `@default(uuid())` lowered to, so `prisma contract emit` writes the same `contract.json` and hashes, and nothing needs to be signed or migrated.
|
|
886
918
|
|
|
@@ -942,8 +974,8 @@ The messages are `uuid: version must be 4 or 7, got <n>`, `cuid: version must be
|
|
|
942
974
|
|
|
943
975
|
```prisma
|
|
944
976
|
// Before: read as nanoid(8) and uuid(7)
|
|
945
|
-
slug String @
|
|
946
|
-
id String @id @
|
|
977
|
+
slug String @default(nanoid(8.0))
|
|
978
|
+
id String @id @default(uuid(7.0))
|
|
947
979
|
|
|
948
980
|
// After
|
|
949
981
|
slug String @onCreate(nanoid(8))
|
|
@@ -954,7 +986,7 @@ id String @id @onCreate(uuid(7))
|
|
|
954
986
|
|
|
955
987
|
```prisma
|
|
956
988
|
// Before: emitted, then on Postgres every insert failed with "value too long"
|
|
957
|
-
code Char(5) @
|
|
989
|
+
code Char(5) @default(nanoid())
|
|
958
990
|
|
|
959
991
|
// After
|
|
960
992
|
code Char(21) @onCreate(nanoid())
|
|
@@ -999,7 +1031,7 @@ await db.orm.public.Post.create({ title: 'Hello', publishedAt: new Date().toISOS
|
|
|
999
1031
|
|
|
1000
1032
|
A direct call of the codec's `encode` with a `Date` is now a type error as well.
|
|
1001
1033
|
|
|
1002
|
-
To work with `Date` values, you can change the column to `TimestamptzJsDate(p)` (`temporal.timestamptzJsDate(...)` as a preset). That changes the column type to `timestamptz`, so it needs a migration: plan and apply one with `prisma migration plan` and `prisma
|
|
1034
|
+
To work with `Date` values, you can change the column to `TimestamptzJsDate(p)` (`temporal.timestamptzJsDate(...)` as a preset). That changes the column type to `timestamptz`, so it needs a migration: plan and apply one with `prisma migration plan` and `prisma db migrate` in step 8 of "Order of the steps", and check how existing `timestamp` values convert, because Postgres reads them in the session's time zone.
|
|
1003
1035
|
|
|
1004
1036
|
## Type-constructor arguments are values of data types
|
|
1005
1037
|
|
|
@@ -1009,7 +1041,7 @@ Write each number argument of a type constructor as a number, positional or name
|
|
|
1009
1041
|
|
|
1010
1042
|
A length, precision, scale or SRID on Postgres is a 32-bit integer, so a number written with a fraction is refused, even when the fraction is zero: `VarChar(255.0)` becomes `VarChar(255)`, and `Timestamptz(3.0)` becomes `Timestamptz(3)`. A number larger than 2147483647 is refused too; write the value the column needs.
|
|
1011
1043
|
|
|
1012
|
-
On SQLite, the length of `sql.String` is a value of `sqlite/real`, so `sql.String(2.0)` is accepted and gives the length `2`. Write `sql.String(2)` anyway, so the schema reads the same on every target. A SQLite length is at most 2147483647, SQLite's largest string length.
|
|
1044
|
+
On SQLite, the length of `sql.String` is a value of `sqlite/real`, so `sql.String(2.0)` is accepted and gives the length `2`. Write `sql.String(2)` anyway, so the schema reads the same on every target. The detection matches `sql.String(2.0)` on every target for this reason. A SQLite length is at most 2147483647, SQLite's largest string length.
|
|
1013
1045
|
|
|
1014
1046
|
## Enums refuse more codecs and read members as values of their data type
|
|
1015
1047
|
|
|
@@ -1059,7 +1091,7 @@ enum Ratio {
|
|
|
1059
1091
|
|
|
1060
1092
|
1. If the contract build refuses two members as one value, such as `enum "Ratio": members "Half" and "Halves" store "0.5" and "0.50", which the database holds equal`, remove one of them. The database already held them equal, so a row could never tell them apart.
|
|
1061
1093
|
2. Re-emit the contract.
|
|
1062
|
-
3. Typecheck the project. Code that reads such an enum column as a member literal type, such as `'0.5' | '1.50'`, now reads the codec's type; compare the value with a member through `db.enums.<Enum>.has()` or `nameOf()`, which find `0.50` as `0.5`.
|
|
1094
|
+
3. Typecheck the project. Code that reads such an enum column as a member literal type, such as `'0.5' | '1.50'`, now reads the codec's type; compare the value with a member through `db.enums.<namespace>.<Enum>.has()` or `nameOf()`, which find `0.50` as `0.5`.
|
|
1063
1095
|
|
|
1064
1096
|
The TypeScript detection matches a file that calls `enumType(` and names one of these codecs or `numericColumn(` or `intervalColumn(` anywhere, even on a column that is not an enum. Check only the enums.
|
|
1065
1097
|
|
|
@@ -1101,7 +1133,7 @@ if (error.code === 'CONTRACT.DEFAULT_INVALID') console.log(error.meta.typeText);
|
|
|
1101
1133
|
|
|
1102
1134
|
## A client takes a typed contract value
|
|
1103
1135
|
|
|
1104
|
-
A client no longer takes `contractJson
|
|
1136
|
+
A client no longer takes `contractJson`, and it needs no type argument. The emitted JSON becomes a typed value in one call, and every client infers its contract type from that value:
|
|
1105
1137
|
|
|
1106
1138
|
```ts
|
|
1107
1139
|
// Before
|
|
@@ -1126,13 +1158,14 @@ A contract value is validated once, however many clients are built from it. A co
|
|
|
1126
1158
|
|
|
1127
1159
|
### Run the script
|
|
1128
1160
|
|
|
1129
|
-
Run `node <guide>/scripts/client-takes-contract-value/contract-from-json.ts <project root>`. The script reads source files with the TypeScript compiler from the project's `typescript` package; if the project has none, it changes nothing, says so and exits 1. In each source file that passes `contractJson` to a client, static entry or `mongoQuery`, it:
|
|
1161
|
+
Run `node <guide>/scripts/client-takes-contract-value/contract-from-json.ts <project root>`. The script reads source files with the TypeScript compiler from the project's `typescript` package; if the project has none, it changes nothing, says so and exits 1. It skips `node_modules`, `dist`, `build` and every directory whose name starts with a dot, such as `.git`, `.agents` or `.claude`; move a client in such a directory by hand. In each source file that passes `contractJson` to a client, static entry or `mongoQuery`, it:
|
|
1130
1162
|
|
|
1131
1163
|
- adds `import { contractFromJson } from '<facade>/static';`, or adds `contractFromJson` to an existing import of that entry, in the file's quote, semicolon and line-ending style;
|
|
1132
|
-
- declares `export const contract = contractFromJson<Contract>(contractJson);` after the imports. In a module with a default export, such as a Worker entry, it declares `const contract` without `export` and prints a note: a Worker treats every named export of its entry module as an entrypoint, so a module that needs the value gets it from a separate module (see step
|
|
1133
|
-
- removes the type argument from the call and replaces the `contractJson` property with `contract
|
|
1164
|
+
- declares `export const contract = contractFromJson<Contract>(contractJson);` after the imports. In a module with a default export, such as a Worker entry, it declares `const contract` without `export` and prints a note: a Worker treats every named export of its entry module as an entrypoint, so a module that needs the value gets it from a separate module (see step 3 below);
|
|
1165
|
+
- removes the type argument from the call and replaces the `contractJson` property with `contract`;
|
|
1166
|
+
- where the call's result is destructured with `contract` in it, as in a `migration.ts` (`const { sql: db, contract } = postgres<End>({ contractJson: endContract })`), removes `contract` from the destructuring, because the declared value is that contract: `const { sql: db } = postgres({ contract })`.
|
|
1134
1167
|
|
|
1135
|
-
It prints each file it moved. It prints to stderr, with the reason, each file that passes `contractJson` but that it did not move, and then exits 1: a test file, a file that already has
|
|
1168
|
+
It prints each file it moved. It prints to stderr, with the reason, each file that passes `contractJson` but that it did not move, and then exits 1: a test file, a file that already has another binding named `contract` (rename that binding and run the script again), a file whose clients use different contracts, a file whose `contractJson` value uses a binding the file declares after its imports, a file whose `contractJson` value uses a parameter or local binding of the function that creates the client (pass `contract: contractFromJson<Contract>(<value>)` to that call instead; the message gives the exact text), and a call it cannot read. Move those by hand in the same way.
|
|
1136
1169
|
|
|
1137
1170
|
### Then, by hand
|
|
1138
1171
|
|
|
@@ -1148,7 +1181,9 @@ It prints each file it moved. It prints to stderr, with the reason, each file th
|
|
|
1148
1181
|
const db = postgres({ contract, url });
|
|
1149
1182
|
```
|
|
1150
1183
|
|
|
1151
|
-
2.
|
|
1184
|
+
2. **`migration.ts` files.** The script moves a `migration.ts` that builds a client over a contract snapshot, such as `const { sql: db, contract } = postgres<End>({ contractJson: endContract })` for a data transform. Move by hand only a `migration.ts` the script refuses, with the text its message gives. Move every such file, so that `node migration.ts` still runs when you write its `ops.json` again (step 7 of the order above). `prisma db migrate` applies `ops.json` and does not load `migration.ts`, so an applied migration keeps working either way.
|
|
1185
|
+
|
|
1186
|
+
3. **Browser modules.** If a module that browser code imports (for example a file a `'use client'` component imports, to read `enums`) also needs the contract, it must not import the module that creates the client, because that module loads the database driver. Move the declaration into a module that imports no driver, and import it from both:
|
|
1152
1187
|
|
|
1153
1188
|
```ts
|
|
1154
1189
|
// src/contract-value.ts
|
|
@@ -1171,11 +1206,11 @@ It prints each file it moved. It prints to stderr, with the reason, each file th
|
|
|
1171
1206
|
export const enums = mongoStatic({ contract }).enums;
|
|
1172
1207
|
```
|
|
1173
1208
|
|
|
1174
|
-
|
|
1209
|
+
4. **Several clients from one contract**, such as two serverless clients in a Worker, take the same `contract` value; the script already gives a file one value for all its clients.
|
|
1175
1210
|
|
|
1176
|
-
|
|
1211
|
+
5. **Types.** The option types `PostgresOptionsWithContract`, `PostgresOptionsWithContractJson`, `PostgresServerlessOptionsWithContract`, `PostgresServerlessOptionsWithContractJson`, `SqliteOptionsWithContract`, `SqliteOptionsWithContractJson`, `MongoOptionsWithContract`, `MongoOptionsWithContractJson`, `SupabaseOptionsWithContract` and `SupabaseOptionsWithContractJson` are removed. Use `PostgresOptions<Contract>`, `PostgresServerlessOptions<Contract>`, `SqliteOptions<Contract>`, `MongoOptions<Contract>` or `SupabaseOptions<Contract>`.
|
|
1177
1212
|
|
|
1178
|
-
|
|
1213
|
+
6. **Docs and comments** in the project that show `postgres<Contract>({ contractJson })` or another client called with `contractJson`: rewrite them to the new form.
|
|
1179
1214
|
|
|
1180
1215
|
## Custom collection classes go on the client
|
|
1181
1216
|
|
|
@@ -1440,7 +1475,7 @@ An `enumType` keeps its codec id as a literal type, as the emitted contract does
|
|
|
1440
1475
|
|
|
1441
1476
|
This section covers `emitted-field-types-from-shared-generic`, `mongo-define-contract-readonly-rows`, `mongo-define-contract-factory-field-types`, `value-object-enum-fields-narrow` and `mongo-update-accessors-take-input-types`. Their summaries above say what changes for each.
|
|
1442
1477
|
|
|
1443
|
-
Re-emit every contract with `prisma contract emit
|
|
1478
|
+
Re-emit every contract with `prisma contract emit`, and leave the `contract.d.ts` files in migration snapshots as they are. The committed `contract.d.ts` changes form, not meaning: `FieldOutputTypes`, `FieldInputTypes` and the value object types are now applications of `FieldTypesFromDomain` and `ValueObjectTypesFromDomain`, with only the types a codec computes at emit time written out in `FieldTypeOverrides`. A SQL `contract.d.ts` written by a development build after 8.0.0-rc.18 imports `FieldTypesFromDomain` from the family contract types entry, which no longer exports it; it fails to compile until you re-emit it. This is the same re-emit as `emitted-contract-types-from-generics`.
|
|
1444
1479
|
|
|
1445
1480
|
For a Mongo contract written with `defineContract`, rows now have the types an emitted contract gives:
|
|
1446
1481
|
|
|
@@ -1498,7 +1533,7 @@ Relations name fields too: `"on": { "localFields": ["authorId"], "targetFields":
|
|
|
1498
1533
|
node <guide>/scripts/mongo-field-storage-names/mongo-field-storage-names.ts
|
|
1499
1534
|
```
|
|
1500
1535
|
|
|
1501
|
-
Node 24 or later runs the TypeScript script directly. It reads and writes files only. It rewrites every `*.json` file under the root that is a MongoDB contract with a model whose `storage` has no `fields`, skipping `node_modules`, `.git`, `
|
|
1536
|
+
Node 24 or later runs the TypeScript script directly. It reads and writes files only. It rewrites every `*.json` file under the root that is a MongoDB contract with a model whose `storage` has no `fields`, skipping `node_modules`, `dist`, `build`, every directory whose name starts with a dot, such as `.git`, `.agents` or `.claude`, and every link it cannot follow, and the `contract.d.ts` next to it (`<name>.d.ts` next to `<name>.json`). These are the contract snapshots under `migrations/snapshots/<hash>/`, which no command regenerates, and any other contract you keep in the old form, such as a test fixture; if you keep one on purpose, restore it with git afterwards. A contract that step 2 emitted is already in the new form and is left alone. The script prints each file it rewrote, or that nothing changed.
|
|
1502
1537
|
|
|
1503
1538
|
A snapshot cannot be rebuilt as a re-emit would write it, because the old contract does not say what the schema called the field (`_id` could have been `id @map("_id")` or `_id`). So the script keeps every field's name and records it as stored under that name, which is what the old contract meant: `"_id"` stays the field `_id`, stored as `_id`. The snapshot directory names stay as they are. Planning from such a snapshot to the re-emitted contract plans nothing and asks nothing, because the planner compares stored names.
|
|
1504
1539
|
|
|
@@ -1684,13 +1719,14 @@ This section covers `control-client-apply-takes-invocation` and `runner-failures
|
|
|
1684
1719
|
|
|
1685
1720
|
```ts
|
|
1686
1721
|
// Before
|
|
1687
|
-
await control.dbUpdate({ contract, mode: 'apply', migrationsDir: 'migrations' });
|
|
1722
|
+
await control.dbUpdate({ contract, mode: 'apply', migrationsDir: 'migrations', answerQuestions });
|
|
1688
1723
|
|
|
1689
1724
|
// After
|
|
1690
1725
|
await control.dbUpdate({
|
|
1691
1726
|
contract,
|
|
1692
1727
|
mode: 'apply',
|
|
1693
1728
|
migrationsDir: 'migrations',
|
|
1729
|
+
answerQuestions,
|
|
1694
1730
|
invocation: { cwd: process.cwd(), configPath: undefined, dbGiven: false },
|
|
1695
1731
|
});
|
|
1696
1732
|
```
|
|
@@ -1706,7 +1742,7 @@ The failure's fields change too:
|
|
|
1706
1742
|
| `failure.summary` | `failure.message` |
|
|
1707
1743
|
| `failure.code === 'PLANNING_FAILED'`, `failure.conflicts` | `failure.code === 'MIGRATION.PLANNING_FAILED'`, `failure.meta.conflicts` |
|
|
1708
1744
|
| `failure.warnings` on a failed `dbInit` or `dbUpdate`, and `value.warnings` on a successful one | the `onPlannerWarnings(warnings)` option, called once per run when planning raised warnings, whether the apply then succeeds or fails |
|
|
1709
|
-
| `failure.
|
|
1745
|
+
| `failure.rowsWithoutValue`, `failure.failedTypeChange` | the runner's facts in `failure.meta`: `rowsWithoutValue` and `failedTypeChange`, and `schemaIssues` and `failedCheck` when the runner found them. A field in them is a subject object, not text such as `"User.age"` |
|
|
1710
1746
|
| `failure.failedMigration`, `failure.databaseStorageHash` | removed; the advice in `failure.fix` names the migration directory and the `--from` hash |
|
|
1711
1747
|
|
|
1712
1748
|
In `--json` output, `db init` and `db update` print the planner's warnings of a failed apply as `warn` messages before the error, instead of in the error's `meta.plannerWarnings`.
|
|
@@ -1747,9 +1783,9 @@ Read the facts from these `meta` keys:
|
|
|
1747
1783
|
|
|
1748
1784
|
```typescript
|
|
1749
1785
|
// before
|
|
1750
|
-
this.setDefault({ table: 'user', column: col('role', 'text', { default: lit('member'), codecRef: { codecId: 'pg/text@1' } }), operationClass: 'widening' })
|
|
1786
|
+
this.setDefault({ schema: 'public', table: 'user', column: col('role', 'text', { default: lit('member'), codecRef: { codecId: 'pg/text@1' } }), operationClass: 'widening' })
|
|
1751
1787
|
// after
|
|
1752
|
-
this.setDefault({ table: 'user', column: col('role', 'text', { default: lit('member'), codecRef: { codecId: 'pg/text@1' } }) })
|
|
1788
|
+
this.setDefault({ schema: 'public', table: 'user', column: col('role', 'text', { default: lit('member'), codecRef: { codecId: 'pg/text@1' } }) })
|
|
1753
1789
|
```
|
|
1754
1790
|
|
|
1755
1791
|
`node migration.ts` does not check types, so a file that still passes `operationClass` runs and ignores it. An applied migration needs nothing: `prisma db migrate` applies `ops.json`.
|