@prisma/orm-postgres 8.0.0-rc.23-dev.14 → 8.0.0-rc.24-dev.2
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/{binding-BilWdtbO-DQOnbc6i.d.mts → binding-BN5X69gf-CIDnIWcw.d.mts} +3 -3
- package/dist/{binding-BilWdtbO-DQOnbc6i.d.mts.map → binding-BN5X69gf-CIDnIWcw.d.mts.map} +1 -1
- package/dist/{binding-DgumIe5f-BPV5_73g.mjs → binding-DkfRsUZE-Co5ssUZw.mjs} +4 -29
- package/dist/binding-DkfRsUZE-Co5ssUZw.mjs.map +1 -0
- package/dist/{contract-from-json-Cg0YjE7V-DcM6l3n6.mjs → contract-from-json-B5HzTVcl-ndoIqEHE.mjs} +3 -3
- package/dist/contract-from-json-B5HzTVcl-ndoIqEHE.mjs.map +1 -0
- package/dist/internal__options.d.mts +3 -3
- package/dist/internal__options.mjs +3 -2
- package/dist/internal__static-context.mjs +1 -1
- package/dist/internal__transaction-members.d.mts +1 -1
- package/dist/internal__transaction-members.mjs +1 -1
- package/dist/internal__validate-contract.mjs +1 -1
- package/dist/{postgres-members-Bwcngc1q-HwIhD-Fq.mjs → postgres-members-B7ZvxGYc-D_L3NVGm.mjs} +11 -4
- package/dist/postgres-members-B7ZvxGYc-D_L3NVGm.mjs.map +1 -0
- package/dist/{postgres-members-C-tRvikK-CCXnwtJ2.d.mts → postgres-members-F9CVSrrN-BFAuNPbW.d.mts} +4 -3
- package/dist/postgres-members-F9CVSrrN-BFAuNPbW.d.mts.map +1 -0
- package/dist/{postgres-options-BmYdDr4L-Dir2eRdu.d.mts → postgres-options-B0YrJID9-YkuL0Mao.d.mts} +10 -3
- package/dist/postgres-options-B0YrJID9-YkuL0Mao.d.mts.map +1 -0
- package/dist/postgres-options-CZyV9Him-2OSYJKqo.mjs +51 -0
- package/dist/postgres-options-CZyV9Him-2OSYJKqo.mjs.map +1 -0
- package/dist/{postgres-static-CI-UYXCi-DBAI4T10.mjs → postgres-static-D6D18p5D-Bwj0XxHU.mjs} +3 -3
- package/dist/{postgres-static-CI-UYXCi-DBAI4T10.mjs.map → postgres-static-D6D18p5D-Bwj0XxHU.mjs.map} +1 -1
- package/dist/runtime.d.mts +5 -4
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +10 -7
- package/dist/runtime.mjs.map +1 -1
- package/dist/serverless.d.mts +4 -3
- package/dist/serverless.d.mts.map +1 -1
- package/dist/serverless.mjs +10 -7
- package/dist/serverless.mjs.map +1 -1
- package/dist/static.mjs +2 -2
- package/package.json +8 -8
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/references/contract.md +3 -1
- package/skills/prisma-8/references/migrations.md +1 -1
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +319 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +304 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
- package/dist/binding-DgumIe5f-BPV5_73g.mjs.map +0 -1
- package/dist/contract-from-json-Cg0YjE7V-DcM6l3n6.mjs.map +0 -1
- package/dist/postgres-members-Bwcngc1q-HwIhD-Fq.mjs.map +0 -1
- package/dist/postgres-members-C-tRvikK-CCXnwtJ2.d.mts.map +0 -1
- package/dist/postgres-options-BmYdDr4L-Dir2eRdu.d.mts.map +0 -1
package/dist/serverless.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { t as postgresError } from "./errors-DfWK9xep-CB07krZF.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
5
|
-
import { n as
|
|
2
|
+
import { i as validateTransactionOptions, n as toDriverCursorOptions, r as validateCursorOptions, t as DEFAULT_CONNECT_TIMEOUT_MILLIS } from "./postgres-options-CZyV9Him-2OSYJKqo.mjs";
|
|
3
|
+
import { s as validatePostgresUrl } from "./binding-DkfRsUZE-Co5ssUZw.mjs";
|
|
4
|
+
import { n as validatePostgresContract } from "./contract-from-json-B5HzTVcl-ndoIqEHE.mjs";
|
|
5
|
+
import { n as buildPostgresStaticContext } from "./postgres-static-D6D18p5D-Bwj0XxHU.mjs";
|
|
6
|
+
import { n as buildPostgresRuntimeBoundMembers } from "./postgres-members-B7ZvxGYc-D_L3NVGm.mjs";
|
|
6
7
|
import { t as PostgresRuntimeImpl } from "./postgres-runtime-BKdag6p9-gHVB2jfC.mjs";
|
|
7
8
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
9
|
+
import postgresTarget, { postgresIsolationLevels as IsolationLevel } from "@prisma/orm-target-postgres/target/runtime";
|
|
8
10
|
import postgresDriver, { createPgClient, suppressIdleConnectionErrors } from "@prisma/orm-target-postgres/driver/runtime";
|
|
9
|
-
import postgresTarget from "@prisma/orm-target-postgres/target/runtime";
|
|
10
11
|
import postgresAdapter from "@prisma/orm-target-postgres/adapter/runtime";
|
|
11
12
|
import { createExecutionContext, createSqlExecutionStack, toRuntimeOptions } from "@prisma/orm-family-sql/runtime";
|
|
12
13
|
import { redactDatabaseUrl } from "@prisma/orm-framework/utils/redact-db-url";
|
|
@@ -57,6 +58,7 @@ function connectionFailedError(url, cause) {
|
|
|
57
58
|
*/
|
|
58
59
|
function postgresServerless(options) {
|
|
59
60
|
const cursor = validateCursorOptions(options.cursor, "postgresServerless");
|
|
61
|
+
const transactionOptions = validateTransactionOptions(options.transactionOptions);
|
|
60
62
|
const contract = validatePostgresContract(options.contract);
|
|
61
63
|
const stack = createSqlExecutionStack({
|
|
62
64
|
target: postgresTarget,
|
|
@@ -79,7 +81,8 @@ function postgresServerless(options) {
|
|
|
79
81
|
nativeEnums,
|
|
80
82
|
toSql,
|
|
81
83
|
getRuntime,
|
|
82
|
-
getRuntimeForWork
|
|
84
|
+
getRuntimeForWork,
|
|
85
|
+
transactionOptions
|
|
83
86
|
});
|
|
84
87
|
const noRuntime = () => {
|
|
85
88
|
throw new InternalError("The serverless client has no runtime");
|
|
@@ -151,6 +154,6 @@ function postgresServerless(options) {
|
|
|
151
154
|
};
|
|
152
155
|
}
|
|
153
156
|
//#endregion
|
|
154
|
-
export { postgresServerless as default };
|
|
157
|
+
export { IsolationLevel, postgresServerless as default };
|
|
155
158
|
|
|
156
159
|
//# sourceMappingURL=serverless.mjs.map
|
package/dist/serverless.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverless.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/serverless.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport {
|
|
1
|
+
{"version":3,"file":"serverless.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/serverless.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { i as validateTransactionOptions, n as toDriverCursorOptions, r as validateCursorOptions, t as DEFAULT_CONNECT_TIMEOUT_MILLIS } from \"./postgres-options-CZyV9Him.mjs\";\nimport { s as validatePostgresUrl } from \"./binding-DkfRsUZE.mjs\";\nimport { t as buildPostgresStaticContext } from \"./postgres-static-D6D18p5D.mjs\";\nimport { n as validatePostgresContract } from \"./contract-from-json-B5HzTVcl.mjs\";\nimport { n as buildPostgresRuntimeBoundMembers } from \"./postgres-members-B7ZvxGYc.mjs\";\nimport { t as PostgresRuntimeImpl } from \"./postgres-runtime-BKdag6p9.mjs\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport postgresTarget, { postgresIsolationLevels as IsolationLevel } from \"@internal/target-postgres/runtime\";\nimport postgresDriver, { createPgClient, suppressIdleConnectionErrors } from \"@internal/driver-postgres/runtime\";\nimport postgresAdapter from \"@internal/adapter-postgres/runtime\";\nimport { createExecutionContext, createSqlExecutionStack, toRuntimeOptions } from \"@internal/sql-runtime\";\nimport { redactDatabaseUrl } from \"@internal/utils/redact-db-url\";\n//#region src/runtime/postgres-serverless.ts\nfunction closedConnectionError() {\n\treturn postgresError(\"DRIVER.NOT_CONNECTED\", \"Postgres connection is closed\", {\n\t\twhy: \"close() was called on this connection, or the await using scope that held it has ended.\",\n\t\tfix: \"Call connect({ url }) again to open a new connection.\",\n\t\tmeta: { extension: \"postgres\" }\n\t});\n}\nfunction connectionFailedError(url, cause) {\n\treturn postgresError(\"DRIVER.CONNECTION_FAILED\", \"Database connection failed\", {\n\t\twhy: cause instanceof Error ? cause.message : String(cause),\n\t\tfix: \"Verify the database URL, ensure the database is reachable, and confirm credentials/permissions\",\n\t\tmeta: {\n\t\t\textension: \"postgres\",\n\t\t\t...redactDatabaseUrl(url)\n\t\t},\n\t\tcause\n\t});\n}\n/**\n* Creates a serverless client for serverless and edge runtimes (Cloudflare Workers + Hyperdrive,\n* AWS Lambda, Vercel, Deno Deploy).\n*\n* The serverless client holds no database connection and has the static members. Each\n* `connect({ url })` opens one database connection, a fresh `pg.Client`, and returns a connection\n* with the members of a `postgres()` client except `connect`. It rejects with\n* `DRIVER.CONNECTION_FAILED` when the database refuses the connection, rejects the credentials,\n* or does not answer within 20 seconds. Close the connection with `await using` or `close()`.\n*\n* The client infers its contract type from `contract` and validates it once, when the client is\n* created; connections reuse it.\n*\n* @example\n* ```ts\n* const postgres = postgresServerless({ contract: contractFromJson<Contract>(contractJson) });\n*\n* export default {\n* async fetch(_req: Request, env: Env): Promise<Response> {\n* await using db = await postgres.connect({ url: env.HYPERDRIVE.connectionString });\n* const users = await db.orm.public.User.all();\n* return Response.json(users);\n* },\n* };\n* ```\n*/\nfunction postgresServerless(options) {\n\tconst cursor = validateCursorOptions(options.cursor, \"postgresServerless\");\n\tconst transactionOptions = validateTransactionOptions(options.transactionOptions);\n\tconst contract = validatePostgresContract(options.contract);\n\tconst stack = createSqlExecutionStack({\n\t\ttarget: postgresTarget,\n\t\tadapter: postgresAdapter,\n\t\tdriver: postgresDriver,\n\t\textensions: options.extensions ?? []\n\t});\n\tconst context = createExecutionContext({\n\t\tcontract,\n\t\tstack,\n\t\tdriver: postgresDriver\n\t});\n\tconst { sql, raw, enums, nativeEnums, toSql } = buildPostgresStaticContext(contract, context, stack);\n\tconst buildRuntimeBoundMembers = (getRuntime, getRuntimeForWork) => buildPostgresRuntimeBoundMembers({\n\t\tcontext,\n\t\tcollections: options.collections,\n\t\tsql,\n\t\traw,\n\t\tenums,\n\t\tnativeEnums,\n\t\ttoSql,\n\t\tgetRuntime,\n\t\tgetRuntimeForWork,\n\t\ttransactionOptions\n\t});\n\tconst noRuntime = () => {\n\t\tthrow new InternalError(\"The serverless client has no runtime\");\n\t};\n\tbuildRuntimeBoundMembers(noRuntime, noRuntime);\n\tconst createConnection = (runtime) => {\n\t\tlet closing;\n\t\tconst close = () => {\n\t\t\tclosing ??= runtime.close();\n\t\t\treturn closing;\n\t\t};\n\t\tconst runtimeBoundMembers = buildRuntimeBoundMembers(() => {\n\t\t\tif (closing !== void 0) throw closedConnectionError();\n\t\t\treturn runtime;\n\t\t}, () => runtime);\n\t\treturn {\n\t\t\tsql,\n\t\t\traw,\n\t\t\tenums,\n\t\t\tnativeEnums,\n\t\t\ttoSql,\n\t\t\tcontext,\n\t\t\tcontract,\n\t\t\tstack,\n\t\t\t...runtimeBoundMembers,\n\t\t\tclose,\n\t\t\t[Symbol.asyncDispose]: close\n\t\t};\n\t};\n\treturn {\n\t\tsql,\n\t\traw,\n\t\tenums,\n\t\tnativeEnums,\n\t\ttoSql,\n\t\tcontext,\n\t\tstack,\n\t\tcontract,\n\t\tasync connect(binding) {\n\t\t\tconst url = validatePostgresUrl(binding.url);\n\t\t\tconst driverDescriptor = stack.driver;\n\t\t\tconst adapter = stack.adapter.create(stack);\n\t\t\tconst driver = driverDescriptor.create({ cursor: toDriverCursorOptions(cursor) });\n\t\t\tconst pgClient = suppressIdleConnectionErrors(createPgClient({\n\t\t\t\tconnectionString: url,\n\t\t\t\tconnectionTimeoutMillis: DEFAULT_CONNECT_TIMEOUT_MILLIS\n\t\t\t}, stack.target.sessionSettings ?? {}));\n\t\t\tawait driver.connect({\n\t\t\t\tkind: \"pgClient\",\n\t\t\t\tclient: pgClient,\n\t\t\t\townedByDriver: true\n\t\t\t});\n\t\t\tconst runtime = new PostgresRuntimeImpl({\n\t\t\t\tcontext,\n\t\t\t\tadapter,\n\t\t\t\tdriver,\n\t\t\t\t...toRuntimeOptions(options),\n\t\t\t\tcloseRefusal: \"when-idle\"\n\t\t\t});\n\t\t\tconst connection = createConnection(runtime);\n\t\t\ttry {\n\t\t\t\tawait (await driver.acquireConnection()).release();\n\t\t\t} catch (err) {\n\t\t\t\tawait driver.close().catch(() => void 0);\n\t\t\t\tthrow connectionFailedError(url, err);\n\t\t\t}\n\t\t\treturn connection;\n\t\t}\n\t};\n}\n//#endregion\nexport { IsolationLevel, postgresServerless as default };\n\n//# sourceMappingURL=serverless.mjs.map"],"mappings":";;;;;;;;;;;;;;AAcA,SAAS,wBAAwB;CAChC,OAAO,cAAc,wBAAwB,iCAAiC;EAC7E,KAAK;EACL,KAAK;EACL,MAAM,EAAE,WAAW,WAAW;CAC/B,CAAC;AACF;AACA,SAAS,sBAAsB,KAAK,OAAO;CAC1C,OAAO,cAAc,4BAA4B,8BAA8B;EAC9E,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAC1D,KAAK;EACL,MAAM;GACL,WAAW;GACX,GAAG,kBAAkB,GAAG;EACzB;EACA;CACD,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,mBAAmB,SAAS;CACpC,MAAM,SAAS,sBAAsB,QAAQ,QAAQ,oBAAoB;CACzE,MAAM,qBAAqB,2BAA2B,QAAQ,kBAAkB;CAChF,MAAM,WAAW,yBAAyB,QAAQ,QAAQ;CAC1D,MAAM,QAAQ,wBAAwB;EACrC,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,YAAY,QAAQ,cAAc,CAAC;CACpC,CAAC;CACD,MAAM,UAAU,uBAAuB;EACtC;EACA;EACA,QAAQ;CACT,CAAC;CACD,MAAM,EAAE,KAAK,KAAK,OAAO,aAAa,UAAU,2BAA2B,UAAU,SAAS,KAAK;CACnG,MAAM,4BAA4B,YAAY,sBAAsB,iCAAiC;EACpG;EACA,aAAa,QAAQ;EACrB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC;CACD,MAAM,kBAAkB;EACvB,MAAM,IAAI,cAAc,sCAAsC;CAC/D;CACA,yBAAyB,WAAW,SAAS;CAC7C,MAAM,oBAAoB,YAAY;EACrC,IAAI;EACJ,MAAM,cAAc;GACnB,YAAY,QAAQ,MAAM;GAC1B,OAAO;EACR;EACA,MAAM,sBAAsB,+BAA+B;GAC1D,IAAI,YAAY,KAAK,GAAG,MAAM,sBAAsB;GACpD,OAAO;EACR,SAAS,OAAO;EAChB,OAAO;GACN;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,GAAG;GACH;IACC,OAAO,eAAe;EACxB;CACD;CACA,OAAO;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAM,QAAQ,SAAS;GACtB,MAAM,MAAM,oBAAoB,QAAQ,GAAG;GAC3C,MAAM,mBAAmB,MAAM;GAC/B,MAAM,UAAU,MAAM,QAAQ,OAAO,KAAK;GAC1C,MAAM,SAAS,iBAAiB,OAAO,EAAE,QAAQ,sBAAsB,MAAM,EAAE,CAAC;GAChF,MAAM,WAAW,6BAA6B,eAAe;IAC5D,kBAAkB;IAClB,yBAAyB;GAC1B,GAAG,MAAM,OAAO,mBAAmB,CAAC,CAAC,CAAC;GACtC,MAAM,OAAO,QAAQ;IACpB,MAAM;IACN,QAAQ;IACR,eAAe;GAChB,CAAC;GACD,MAAM,UAAU,IAAI,oBAAoB;IACvC;IACA;IACA;IACA,GAAG,iBAAiB,OAAO;IAC3B,cAAc;GACf,CAAC;GACD,MAAM,aAAa,iBAAiB,OAAO;GAC3C,IAAI;IACH,OAAO,MAAM,OAAO,kBAAkB,EAAA,CAAG,QAAQ;GAClD,SAAS,KAAK;IACb,MAAM,OAAO,MAAM,CAAC,CAAC,YAAY,KAAK,CAAC;IACvC,MAAM,sBAAsB,KAAK,GAAG;GACrC;GACA,OAAO;EACR;CACD;AACD"}
|
package/dist/static.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as contractFromJson } from "./contract-from-json-
|
|
2
|
-
import { r as postgresStatic } from "./postgres-static-
|
|
1
|
+
import { t as contractFromJson } from "./contract-from-json-B5HzTVcl-ndoIqEHE.mjs";
|
|
2
|
+
import { r as postgresStatic } from "./postgres-static-D6D18p5D-Bwj0XxHU.mjs";
|
|
3
3
|
export { contractFromJson, postgresStatic as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/orm-postgres",
|
|
3
|
-
"version": "8.0.0-rc.
|
|
3
|
+
"version": "8.0.0-rc.24-dev.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"skills"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@prisma/orm-family-sql": "8.0.0-rc.
|
|
14
|
-
"@prisma/orm-framework": "8.0.0-rc.
|
|
15
|
-
"@prisma/orm-target-postgres": "8.0.0-rc.
|
|
16
|
-
"@prisma/orm-toolchain": "8.0.0-rc.
|
|
13
|
+
"@prisma/orm-family-sql": "8.0.0-rc.24-dev.2",
|
|
14
|
+
"@prisma/orm-framework": "8.0.0-rc.24-dev.2",
|
|
15
|
+
"@prisma/orm-target-postgres": "8.0.0-rc.24-dev.2",
|
|
16
|
+
"@prisma/orm-toolchain": "8.0.0-rc.24-dev.2",
|
|
17
17
|
"@types/node": "26.1.2",
|
|
18
18
|
"@types/pg": "8.20.4",
|
|
19
19
|
"arktype": "^2.2.2",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"tinyglobby": "^0.2.17"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@internal/postgres": "8.0.0-rc.
|
|
27
|
-
"@repo/tsconfig": "8.0.0-rc.
|
|
28
|
-
"@repo/tsdown": "8.0.0-rc.
|
|
26
|
+
"@internal/postgres": "8.0.0-rc.24-dev.2",
|
|
27
|
+
"@repo/tsconfig": "8.0.0-rc.24-dev.2",
|
|
28
|
+
"@repo/tsdown": "8.0.0-rc.24-dev.2",
|
|
29
29
|
"tsdown": "0.22.14",
|
|
30
30
|
"typescript": "5.9.3"
|
|
31
31
|
},
|
package/skills/prisma-8/SKILL.md
CHANGED
|
@@ -96,12 +96,13 @@ If `contract:` ends in `.prisma`, the source is PSL; if it ends in `.ts`, the so
|
|
|
96
96
|
|
|
97
97
|
## Workflow — Edit a model / field / relation (PSL)
|
|
98
98
|
|
|
99
|
-
The concept: PSL models lower to tables (or collections, on Mongo); fields lower to columns; `@relation(...)` declares the FK side.
|
|
99
|
+
The concept: PSL models lower to tables (or collections, on Mongo); fields lower to columns; `@relation(...)` declares the FK side. The other model gets a relation, and something to `include` from, only when it declares the back-reference itself with no `fields`/`references`: a list field (`posts Post[]`), or an optional singular field for a one-to-one (`profile Profile?`). A singular back-reference needs the FK fields to be unique (`@unique`, or `@@unique([...])` on the FK side); otherwise emit fails with `PSL_NON_UNIQUE_BACKRELATION`.
|
|
100
100
|
|
|
101
101
|
```prisma
|
|
102
102
|
model User {
|
|
103
103
|
id Int @id @default(autoincrement())
|
|
104
104
|
email String @unique
|
|
105
|
+
posts Post[]
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
model Post {
|
|
@@ -525,6 +526,7 @@ Infer captures indexes at full fidelity — expression, partial (`where:`), uniq
|
|
|
525
526
|
- **Lifecycle callbacks** (`beforeSave`, `afterCreate`, etc.). Not supported. Use middleware (`references/runtime.md`) or app code. The maintainers decided it stays out of the core; an extension may provide it (prisma/orm ADR 293).
|
|
526
527
|
- **Soft delete / `paranoid: true`.** No built-in soft-delete column. Add a nullable `deletedAt DateTime?` and filter explicitly in queries (or in middleware). The maintainers decided it stays out of the core; an extension may provide it (prisma/orm ADR 293).
|
|
527
528
|
- **Scopes / default filters.** No ActiveRecord-style scopes. Compose query helpers yourself. To request scopes, file via `references/feedback.md`.
|
|
529
|
+
- **Derived back-references.** A model has a relation back only when it declares the field itself (`posts Post[]`); nothing adds it for you, and it is optional. The maintainers decided this (prisma/orm ADR 319). `prisma contract infer` writes both sides when it reads an existing database.
|
|
528
530
|
- **Implicit Prisma-ORM many-to-many.** List navigation on both sides without an explicit join model is rejected. Author the join model explicitly. To request implicit M2M, file via `references/feedback.md`.
|
|
529
531
|
|
|
530
532
|
## Reference
|
|
@@ -593,7 +593,7 @@ In a terminal the command asks each question in turn; type `delete`, `allow`, or
|
|
|
593
593
|
9. **Planning with no `db` ref and no `--from` in a project that already has migrations.** The origin falls through to the empty database, which would make the plan a full-create migration; `migration plan` refuses with `MIGRATION.PLAN_ORIGIN_UNKNOWN` rather than writing it. Pick the exit that matches your intent — the error lists them, and `references/migration-model.md` § *The trap* explains which to choose.
|
|
594
594
|
10. **Hand-authoring `migration.ts` from a blank file, or rewriting the rendered import line.** Migration files are framework-rendered — let `prisma migration plan` (or `migration new`) render the package, then edit only the holes the framework leaves for you. On Postgres leave the rendered `@internal/postgres/migration` (or `@internal/sqlite/migration`) import path alone; on Mongo leave `@prisma/orm-mongo/target/migration` as rendered. Add symbols to the existing import line rather than introducing new import paths.
|
|
595
595
|
12. **Replaying migrations onto a database that is already ahead.** `db migrate` on a database with no marker runs every migration, skipping operations already applied. When the database is already past a migration (it has `x int8` where the migration adds `x int4`), the run stops at that migration's precheck with `MIGRATION.PRECHECK_FAILED`. Adopt such a database with `prisma db sign` (after `contract infer` if needed), not by replaying history.
|
|
596
|
-
13. **Running Prisma 7 `migrate` commands against Prisma 8.** Each one answers `CLI.
|
|
596
|
+
13. **Running Prisma 7 `migrate` commands against Prisma 8.** Each one answers `CLI.V7_COMMAND` with its Prisma 8 command: `migrate dev` is `contract emit`, `migration plan --name <name>`, then `db migrate --advance-ref db`; `migrate deploy` is `db migrate`; `migrate reset` has no equivalent, because Prisma 8 has no reset: `db update` brings the database to the contract instead, asking before it loses data, but it keeps existing rows and runs no seed steps or data transforms (a database that changes only through migrations is moved with `db migrate`); `migrate status` is `migration status`; `migrate diff` is `db update --dry-run`, or `migration plan` to write a migration package; `migrate resolve` is `db sign <migration>`, which moves the database marker to that migration after checking its schema, but leaves `migration status` without an applied mark. While Prisma 7 still owns the migrations, install Prisma 7's CLI with `npm install --save-dev @prisma/prisma7@7` and run every one of them except `migrate diff`, whose replacement only reads, as `prisma7 migrate <command>` instead; `migrate resolve` runs as `prisma7 migrate resolve --applied <migration>`.
|
|
597
597
|
|
|
598
598
|
## What Prisma 8 doesn't do yet
|
|
599
599
|
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
---
|
|
2
|
+
from: "8.0.0-rc.23"
|
|
3
|
+
to: "8.0.0-rc.24"
|
|
4
|
+
changes:
|
|
5
|
+
- id: engine-pin-moves-to-0-10-0
|
|
6
|
+
summary: |
|
|
7
|
+
The toolchain now requires `@prisma/cli-engine@0.10.0` (up from 0.9.0). A project that depends on `@prisma/cli-engine` itself must move to `0.10.0`.
|
|
8
|
+
detection:
|
|
9
|
+
glob: "**/{package.json,pnpm-workspace.yaml}"
|
|
10
|
+
matches:
|
|
11
|
+
- '"@prisma/cli-engine":\s*"[^"]*(?<![\d.])0\.\d(?!\d)'
|
|
12
|
+
- '[''"]?@prisma/cli-engine[''"]?:\s*[''"]?[\^~]?0\.\d(?![\d])'
|
|
13
|
+
- id: prisma-7-commands-answer-v7-command
|
|
14
|
+
summary: |
|
|
15
|
+
A Prisma 7 command the ORM answers, such as `prisma migrate dev`, now fails with `CLI.V7_COMMAND` instead of `CLI.COMMAND_MOVED`, still with exit code 2.
|
|
16
|
+
- id: planner-warnings-json-field
|
|
17
|
+
summary: |
|
|
18
|
+
In `--json` output, `db update` and `db init` list the planner's warnings under `plannerWarnings` instead of `warnings`, as `migration plan` does.
|
|
19
|
+
- id: mongo-fields-take-a-type
|
|
20
|
+
summary: |
|
|
21
|
+
The MongoDB TypeScript builder writes a field as `field.scalar(type.X())`, where `type` holds the type constructors the target and extension packs contribute, as PSL names them: `field.objectId()` is now `field.scalar(type.ObjectId())`, `field.date()` is `field.scalar(type.DateTime())` (on MongoDB `Date` is now a calendar date), `field.vector({ typeParams: { length: 3 } })` is `field.scalar(type.Vector(3))`, and `field.scalar('mongo/string@1')` is `field.scalar(type.String())`. `field.objectId()`, `field.string()`, `field.double()`, `field.int32()`, `field.bool()`, `field.date()`, `field.int64()`, `field.int64Number()`, `field.decimal128()`, `field.binary()`, `field.json()`, `field.bson()`, `field.vector()` and `field.scalar(codecId)` are removed. `type` comes from the `defineContract` callback, or from `@prisma/orm-mongo/contract-builder`. Run `scripts/mongo-type-helpers/rewrite-mongo-field-types.ts` to rewrite them. The contract does not change. The detection matches MongoDB contract sources that call a removed helper.
|
|
22
|
+
detection:
|
|
23
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
24
|
+
matches:
|
|
25
|
+
- '(?<![\s\S])(?=[\s\S]*@prisma/orm-(?:mongo|family-mongo/contract-ts)/contract-builder[\x27"])[\s\S]*(?<![\w$])field\s*\.\s*(?:(?:objectId|string|double|int32|bool|date|int64|int64Number|decimal128|binary|json|bson|vector)\s*\(|scalar\s*\(\s*[\x27"])'
|
|
26
|
+
- '(?<![\s\S])(?=[\s\S]*@prisma/orm-(?:mongo|family-mongo/contract-ts)/contract-builder[\x27"])(?=[\s\S]*\bfield\s*(?:as\s+|:\s*)[A-Za-z_$][\w$]*)[\s\S]*\.\s*(?:(?:objectId|string|double|int32|bool|date|int64|int64Number|decimal128|binary|json|bson|vector)\s*\(|scalar\s*\(\s*[\x27"])'
|
|
27
|
+
script: ./scripts/mongo-type-helpers/rewrite-mongo-field-types.ts
|
|
28
|
+
- id: mongo-date-is-a-calendar-date
|
|
29
|
+
summary: |
|
|
30
|
+
On MongoDB, `Date` is now a calendar date, stored as a BSON date at midnight UTC and read as a string such as `"2024-02-29"`. `DateTime` with no arguments is what `Date` was: an instant read as a JavaScript `Date` (`mongo/date@1`). Rewrite `Date` to `DateTime` in MongoDB schemas and `type.Date()` to `type.DateTime()` in MongoDB TypeScript contracts with `scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts`. The contract does not change.
|
|
31
|
+
detection:
|
|
32
|
+
glob: "**/*.{prisma,ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
33
|
+
matches:
|
|
34
|
+
- '(?<![\s\S])(?![\s\S]*(?<![\w$])datasource[ \t]+\w+[ \t]*\{)(?=[\s\S]*(?:(?<![\w$])ObjectId(?![\w$])|@map\("_id"\)))[\s\S]*\n[ \t]+[A-Za-z_]\w*[ \t]+(?:=[ \t]*)?Date(?![\w$])'
|
|
35
|
+
- '(?<![\s\S])(?=[\s\S]*@(?:prisma/orm-(?:mongo|family-mongo/contract-ts)|internal/mongo)/contract-builder[\x27"])[\s\S]*(?<![\w$])[A-Za-z_$][\w$]*\s*\.\s*Date\s*\('
|
|
36
|
+
- '(?<![\s\S])(?=[\s\S]*[\x27"]@prisma/orm-mongo/config[\x27"])[\s\S]*(?<![\w$])contract\s*:\s*[\x27"][^\x27"]+?(?<!\.ts)[\x27"]'
|
|
37
|
+
script: ./scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts
|
|
38
|
+
- id: temporal-polyfill-is-a-peer-dependency-of-mongo
|
|
39
|
+
summary: |
|
|
40
|
+
`temporal-polyfill` is now a required peer dependency of `@prisma/orm-mongo` and `@prisma/orm-target-mongo`. The MongoDB control plane imports it, because `DateTime(as: temporal)`, `Date(as: temporal)` and `Time(as: temporal)` read `Temporal` values. npm, pnpm and bun install it automatically (npm with `legacy-peer-deps` set does not: see `temporal-polyfill-with-legacy-peer-deps`). A project that installs with Yarn must add `temporal-polyfill` (`^1.0.4`) to its own dependencies.
|
|
41
|
+
detection:
|
|
42
|
+
glob: "**/yarn.lock"
|
|
43
|
+
contains:
|
|
44
|
+
- "@prisma/orm-mongo@"
|
|
45
|
+
- "@prisma/orm-target-mongo@"
|
|
46
|
+
anyMatch: true
|
|
47
|
+
- id: temporal-polyfill-with-legacy-peer-deps
|
|
48
|
+
summary: |
|
|
49
|
+
npm does not install peer dependencies when `legacy-peer-deps` is set, so a MongoDB project that installs with npm and that setting must add `temporal-polyfill` (`^1.0.4`) to its own dependencies, as a Yarn project must. The MongoDB control plane imports it. The setting can come from an `.npmrc`, the user's npm config or the environment, which no file shows, so the detection matches every `package.json` that depends on `@prisma/orm-mongo` or `@prisma/orm-target-mongo`, and the step checks the setting npm uses.
|
|
50
|
+
detection:
|
|
51
|
+
glob: "**/package.json"
|
|
52
|
+
contains:
|
|
53
|
+
- '"@prisma/orm-mongo"'
|
|
54
|
+
- '"@prisma/orm-target-mongo"'
|
|
55
|
+
anyMatch: true
|
|
56
|
+
- id: mongo-validator-change-checks-documents
|
|
57
|
+
summary: |
|
|
58
|
+
A MongoDB validator change that `migration plan` or `db update` writes now checks the documents first, and the apply stops while a document does not fit the new validator. Existing `migration.ts` files are unchanged.
|
|
59
|
+
- id: mongo-type-change-is-asked
|
|
60
|
+
summary: |
|
|
61
|
+
A MongoDB field type change that can lose values is now a question, answered with `--convert` or `--delete`, as on SQL. A cast that keeps every value, such as `Int` to `Int64`, is planned with nothing asked.
|
|
62
|
+
- id: mongo-new-required-field-gets-temporary-value
|
|
63
|
+
summary: |
|
|
64
|
+
A new required MongoDB field is now filled with a temporary value in the documents that lack it, as on SQL, unless `--backfill` names it.
|
|
65
|
+
- id: create-extension-not-exported
|
|
66
|
+
summary: |
|
|
67
|
+
`@prisma/orm-postgres/migration` no longer exports the free function `createExtension`, which a `migration.ts` could not call correctly since 8.0.0-rc.22. A `migration.ts` that imports it now fails at once with `does not provide an export named 'createExtension'`. Call the method on the migration class instead: `createExtension('btree_gist')` becomes `this.createExtension({ extension: 'btree_gist' })`. The migration's `ops.json` does not change, so there is no need to run `node migration.ts` again.
|
|
68
|
+
detection:
|
|
69
|
+
glob: "**/migration.{ts,mts}"
|
|
70
|
+
matches:
|
|
71
|
+
- '(?<![\w$.])createExtension\s*\('
|
|
72
|
+
- '\bimport\s*\{[^}]*(?<![\w$])createExtension(?![\w$])[^}]*\}\s*from\s*[\x27"]@prisma/orm-postgres/migration[\x27"]'
|
|
73
|
+
- id: data-transform-not-exported
|
|
74
|
+
summary: |
|
|
75
|
+
`@prisma/orm-postgres/migration` no longer exports the free function `dataTransform`, which took an internal fourth argument a `migration.ts` cannot pass. A `migration.ts` that imports it now fails at once with `does not provide an export named 'dataTransform'`. Call the method on the migration class instead: `this.dataTransform(endContract, name, { check, run })`. The planner writes the method. The types `DataTransformClosure` and `DataTransformOptions` are still exported.
|
|
76
|
+
detection:
|
|
77
|
+
glob: "**/migration.{ts,mts}"
|
|
78
|
+
matches:
|
|
79
|
+
- '\bimport\s*\{[^}]*(?<![\w$])dataTransform(?![\w$])[^}]*\}\s*from\s*[\x27"]@prisma/orm-postgres/migration[\x27"]'
|
|
80
|
+
- id: raw-parts-hold-statement-asts
|
|
81
|
+
summary: |
|
|
82
|
+
The `parts` of `RawExpr` and `RawQueryAst` (from `@prisma/orm-family-sql/relational-core/ast`) are now `ReadonlyArray<RawPart>`, where `RawPart = string | AnyExpression | SelectAst | InsertAst | UpdateAst | DeleteAst`. A raw template places a builder query, or a builder mutation after `.returning()`, as one statement part. Code that walks `parts` and treats every non-string part as an expression must handle the four statement kinds. The detection matches files that import these nodes and read `.parts`.
|
|
83
|
+
detection:
|
|
84
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
85
|
+
matches:
|
|
86
|
+
- '(?<![\s\S])(?=[\s\S]*@prisma/orm-family-sql/relational-core/(?:ast|expression)[\x27"])(?=[\s\S]*(?<![\w$])(?:RawExpr|RawQueryAst|RawPart)(?![\w$]))[\s\S]*\.parts(?![\w$])'
|
|
87
|
+
- id: mysql-explicit-isolation-default
|
|
88
|
+
summary: Configure ReadCommitted explicitly if MySQL callbacks relied on the previous session-wide override.
|
|
89
|
+
- id: contract-artifacts-restamp
|
|
90
|
+
summary: |
|
|
91
|
+
An extension that writes its own package version into the contracts it emits, such as the Supabase extension, now writes 8.0.0-rc.24. Run `contract emit` once after upgrading so the emitted `contract.json` and `contract.d.ts` match the installed extension.
|
|
92
|
+
detection:
|
|
93
|
+
glob: "**/contract.json"
|
|
94
|
+
contains:
|
|
95
|
+
- '"version": "8.0.0-rc.23"'
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
# 8.0.0-rc.23 → 8.0.0-rc.24 — User upgrade instructions
|
|
99
|
+
|
|
100
|
+
## Order of the steps
|
|
101
|
+
|
|
102
|
+
Do the steps in this order, and skip a step that does not apply to the project:
|
|
103
|
+
|
|
104
|
+
1. Upgrade the Prisma packages. A project that depends on `@prisma/cli-engine` itself moves it to `0.10.0` (`engine-pin-moves-to-0-10-0`). A MongoDB project that installs with Yarn, or with npm and `legacy-peer-deps`, adds `temporal-polyfill` to its dependencies (`temporal-polyfill-is-a-peer-dependency-of-mongo`, `temporal-polyfill-with-legacy-peer-deps`).
|
|
105
|
+
2. Change the MongoDB contract sources. Run the field-types script first (`mongo-fields-take-a-type`), then the date-types script (`mongo-date-is-a-calendar-date`). The first script writes `field.date()` as `field.scalar(type.DateTime())`, so the second has nothing left to do for it; the second rewrites `Date` to `DateTime` in MongoDB schemas.
|
|
106
|
+
3. Run `prisma contract emit` and commit what it writes. The MongoDB contracts must not change; the only change to expect is the extension version stamp (`contract-artifacts-restamp`).
|
|
107
|
+
4. In PostgreSQL `migration.ts` files, call `this.createExtension(...)` and `this.dataTransform(...)` instead of the free functions (`create-extension-not-exported`, `data-transform-not-exported`). Existing `ops.json` files do not change.
|
|
108
|
+
5. Change the remaining code: MySQL callback transactions that relied on READ COMMITTED (`mysql-explicit-isolation-default`), code that walks the `parts` of a raw SQL node (`raw-parts-hold-statement-asts`), and scripts that read the CLI's `--json` planner warnings or check for `CLI.COMMAND_MOVED` (`planner-warnings-json-field`, `prisma-7-commands-answer-v7-command`).
|
|
109
|
+
6. On MongoDB, the next `migration plan` or `db update` checks documents against a changed validator, asks about field type changes that can lose values, and fills new required fields with a temporary value. Read those three entries before planning the next schema change (`mongo-validator-change-checks-documents`, `mongo-type-change-is-asked`, `mongo-new-required-field-gets-temporary-value`).
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## The CLI moves to `@prisma/cli-engine` 0.10.0 and answers Prisma 7 commands with `CLI.V7_COMMAND`
|
|
113
|
+
|
|
114
|
+
### `engine-pin-moves-to-0-10-0`
|
|
115
|
+
|
|
116
|
+
For every file matched by `detection`, change the `@prisma/cli-engine` version (`0.9.0`, `^0.9.0` or any other 0.x below 0.10) to `0.10.0` and reinstall. Projects assembled by the `prisma` CLI resolve the engine automatically.
|
|
117
|
+
|
|
118
|
+
### `prisma-7-commands-answer-v7-command`
|
|
119
|
+
|
|
120
|
+
`prisma generate`, `validate`, `format`, `studio`, `db pull`, `db push`, `db seed`, `db execute` and the six `prisma migrate` commands fail with `CLI.V7_COMMAND`. The error names the Prisma 8 commands to run instead and their `--help`, or links the CLI docs when Prisma 8 has no equivalent. A script that checks for `CLI.COMMAND_MOVED` after running one of these commands checks for `CLI.V7_COMMAND` instead.
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
## The CLI's `--json` output lists planner warnings under `plannerWarnings`
|
|
124
|
+
|
|
125
|
+
### `planner-warnings-json-field`
|
|
126
|
+
|
|
127
|
+
A script that reads the planner's warnings from the `--json` result of `db update` or `db init` reads `plannerWarnings` instead of `warnings`. Each entry is unchanged: `kind`, `summary` and `why`. `migration plan --json` lists them under `plannerWarnings` too, and its `warnings` keeps its own messages, such as a default origin that forks the migration graph.
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
## MongoDB fields take a type from `type`
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
// Before
|
|
134
|
+
export const contract = defineContract({}, ({ field, model }) => ({
|
|
135
|
+
models: {
|
|
136
|
+
Doc: model('Doc', {
|
|
137
|
+
fields: {
|
|
138
|
+
_id: field.objectId(),
|
|
139
|
+
embedding: field.vector({ typeParams: { length: 3 } }),
|
|
140
|
+
raw: field.scalar('mongo/bson@1'),
|
|
141
|
+
},
|
|
142
|
+
}),
|
|
143
|
+
},
|
|
144
|
+
}));
|
|
145
|
+
|
|
146
|
+
// After
|
|
147
|
+
export const contract = defineContract({}, ({ field, model, type }) => ({
|
|
148
|
+
models: {
|
|
149
|
+
Doc: model('Doc', {
|
|
150
|
+
fields: {
|
|
151
|
+
_id: field.scalar(type.ObjectId()),
|
|
152
|
+
embedding: field.scalar(type.Vector(3)),
|
|
153
|
+
raw: field.scalar(type.Bson()),
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
},
|
|
157
|
+
}));
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### `mongo-fields-take-a-type`
|
|
161
|
+
|
|
162
|
+
Commit your work first. The script reads your code with the TypeScript compiler, so the project needs `typescript` installed; a JavaScript project adds it as a dev dependency for the run. From the project root, run:
|
|
163
|
+
|
|
164
|
+
```sh
|
|
165
|
+
node <path-to-this-guide>/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Pass files or directories to limit it. The script prints a line for each call it leaves. Rewrite each one by hand, except where the line says the script cannot tell the `field` is the MongoDB builder's and it is not. Then type-check the project. The script neither changes nor reports a `field.scalar` call whose argument is computed, such as `field.scalar(codecIdOf(kind))`, because it cannot tell a codec id from a type there; the type check reports each one that passes a codec id, since `field.scalar` takes only a type now. Where the type check cannot see it, in plain JavaScript or with an argument typed `any`, `contract emit` refuses the call with `CONTRACT.ARGUMENT_INVALID`. Write those with `type.X()`.
|
|
169
|
+
|
|
170
|
+
A field written with an extension's codec id, such as `field.scalar('shout/text@1')`, is one the script reports: write the type constructor the extension contributes, such as `field.scalar(type.shout.Text())`.
|
|
171
|
+
|
|
172
|
+
MongoDB PSL gains `Vector` and `Vector(length)` for `mongo/vector@1`, which had no PSL name before. It now reads the arguments of a type call, so `Vector(3)` keeps its length. A type that takes no arguments, written with one, such as `String(5)`, used to have the argument ignored and is now refused with a message naming the argument; remove the argument.
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
## MongoDB: `Date` is a calendar date, and `temporal-polyfill` is a peer dependency
|
|
176
|
+
|
|
177
|
+
### `mongo-date-is-a-calendar-date`
|
|
178
|
+
|
|
179
|
+
```prisma
|
|
180
|
+
// Before: an instant
|
|
181
|
+
model Order {
|
|
182
|
+
id ObjectId @id @map("_id")
|
|
183
|
+
paidAt Date
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// After: the same instant, the same contract
|
|
187
|
+
model Order {
|
|
188
|
+
id ObjectId @id @map("_id")
|
|
189
|
+
paidAt DateTime
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
MongoDB now has the convenience date and time types PostgreSQL, SQLite and MySQL have. `Date` is the calendar date, so a field that holds an instant must be written `DateTime`. Commit your work first, then from the project root run:
|
|
194
|
+
|
|
195
|
+
```sh
|
|
196
|
+
node <path-to-this-guide>/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
It rewrites `Date` to `DateTime` in MongoDB schemas, including in `types {}` aliases, and `type.Date()` to `type.DateTime()` in MongoDB TypeScript contracts. No release had `type.Date()` for an instant, because MongoDB's `type` helpers ship in this release too; the script rewrites it for a contract written against an unreleased build that already had them. Pass files or directories to limit it. Fix by hand each line it reports, then run `prisma contract emit`: the contract must not change.
|
|
200
|
+
|
|
201
|
+
A field you miss still compiles. Its TypeScript type becomes `string`, and reading a document whose value has a time of day fails with an error that names the field. Worse, `@onCreate(now())` or `@onUpdate(now())` on it writes today's date at midnight UTC, losing the time, with no error, so check every generated timestamp field. A field that really holds a calendar date can stay `Date`, if every stored value is at midnight UTC; it then reads `"2024-02-29"` instead of a `Date`. A Prisma 6 schema read with `prisma6Schema` is not rewritten: its `DateTime` and `DateTime @db.Date` stay instants read as a JavaScript `Date`.
|
|
202
|
+
|
|
203
|
+
### `temporal-polyfill-is-a-peer-dependency-of-mongo`
|
|
204
|
+
|
|
205
|
+
For each Yarn project that `detection` matches, add `"temporal-polyfill": "^1.0.4"` to `dependencies` in the `package.json` that depends on `@prisma/orm-mongo` or `@prisma/orm-target-mongo`, then reinstall.
|
|
206
|
+
|
|
207
|
+
### `temporal-polyfill-with-legacy-peer-deps`
|
|
208
|
+
|
|
209
|
+
Skip this if the project installs with Yarn (see `temporal-polyfill-is-a-peer-dependency-of-mongo`), pnpm or bun. For a project that installs with npm, run `npm config get legacy-peer-deps` in the folder of each `package.json` that `detection` matches. It reports the setting npm uses there, from any `.npmrc`, the user's npm config or the `npm_config_legacy_peer_deps` environment variable. Where it prints `true`, or the project's install command passes `--legacy-peer-deps`, add `"temporal-polyfill": "^1.0.4"` to that `package.json`'s `dependencies`, then reinstall.
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
## MongoDB plans rewrite the documents a schema change touches
|
|
213
|
+
|
|
214
|
+
### `mongo-validator-change-checks-documents`
|
|
215
|
+
|
|
216
|
+
Every validator change a new plan writes is `collMod(..., { ..., checkDocuments: true })`: as its own precheck, after the plan's rewrites, it checks that every document fits the new validator. When `db migrate` or `db update` stops with `MIGRATION.PRECHECK_FAILED` because documents do not fit:
|
|
217
|
+
|
|
218
|
+
1. Find them with the `mongosh` query the error prints, and change them so they fit the new validator. The old validator is still in place and may reject a document changed to the new shape, so an update that fixes one can skip document validation: write a `dataTransform` in `migration.ts`, or in `mongosh` run an update command with `bypassDocumentValidation: true`, such as `db.runCommand({ update: "users", updates: [{ q: { _id: … }, u: { $set: { … } } }], bypassDocumentValidation: true })`. Run the command again. For a field the change makes required, `migration plan --backfill Model.field` writes a step to fill it instead.
|
|
219
|
+
2. Or, under `db migrate`, apply the validator over them as before: set `checkDocuments` to `false` on that `collMod` in the migration's `migration.ts`, run the file with `node`, and run `db migrate` again. Those documents then fail their next update until they fit. `db update` writes no `migration.ts`, so there the documents must be fixed first.
|
|
220
|
+
|
|
221
|
+
Operations of the migration that ran before the validator change stay applied; a re-run skips them.
|
|
222
|
+
|
|
223
|
+
A database adopted from Prisma 6 has no validator, so its first plan adds one and checks every collection.
|
|
224
|
+
|
|
225
|
+
### `mongo-type-change-is-asked`
|
|
226
|
+
|
|
227
|
+
Where a plan now asks about a field, answer with `--delete Model.field`, which casts the values with `$convert` and fails on a value it cannot cast (a change such as `String` to `Boolean`, where `$convert` would turn `"false"` into `true`, has no cast and offers `--convert` only), or plan it with `migration plan --convert Model.field` and write the update in the `placeholder('Model.field:update')` slot of the data transform it writes.
|
|
228
|
+
|
|
229
|
+
### `mongo-new-required-field-gets-temporary-value`
|
|
230
|
+
|
|
231
|
+
To write your own value instead of the temporary one, plan the change with `migration plan --backfill Model.field` and write the update in the `placeholder('Model.field:update')` slot of the data transform it writes. A new required field under a unique index gets no temporary value, since every document would get the same one: on a collection with documents, the unique index build stops the apply first, because the documents that lack the field all hold `null`, and its error names `--backfill`. Plan it with `--backfill`.
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
## `createExtension` and `dataTransform` are no longer free functions
|
|
235
|
+
|
|
236
|
+
### `create-extension-not-exported`
|
|
237
|
+
|
|
238
|
+
`@prisma/orm-postgres/migration` no longer exports `createExtension`. Since 8.0.0-rc.22 the free function took an internal argument that only the migration class can supply, so a `migration.ts` that called it failed with `Cannot read properties of undefined (reading 'lowerToExecuteRequest')`. Now the import fails at once instead.
|
|
239
|
+
|
|
240
|
+
In every `migration.ts` the detection matches, call the method and remove `createExtension` from the import:
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
// Before
|
|
244
|
+
import { createExtension, Migration, MigrationCLI } from '@prisma/orm-postgres/migration';
|
|
245
|
+
|
|
246
|
+
override get operations() {
|
|
247
|
+
return [createExtension('btree_gist'), ...];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// After
|
|
251
|
+
import { Migration, MigrationCLI } from '@prisma/orm-postgres/migration';
|
|
252
|
+
|
|
253
|
+
override get operations() {
|
|
254
|
+
return [this.createExtension({ extension: 'btree_gist' }), ...];
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Without `schema`, the method creates the extension where the old function did: in the connection's current schema, unless the extension's control file names one. The migration's `ops.json` does not change, and there is no need to run `node migration.ts` again: `prisma db migrate` applies `ops.json` and does not load `migration.ts`.
|
|
259
|
+
|
|
260
|
+
### `data-transform-not-exported`
|
|
261
|
+
|
|
262
|
+
`@prisma/orm-postgres/migration` no longer exports the free function `dataTransform`. It took an internal fourth argument that only the migration class can supply, so a `migration.ts` could not call it correctly. Remove `dataTransform` from the import and call `this.dataTransform(endContract, name, { check, run })`, as the planner writes it. The types `DataTransformClosure` and `DataTransformOptions` are still exported.
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
## Raw parts can hold a statement AST
|
|
266
|
+
|
|
267
|
+
### `raw-parts-hold-statement-asts`
|
|
268
|
+
|
|
269
|
+
`RawExpr.parts` and `RawQueryAst.parts` used to hold strings and expression nodes. They now hold `RawPart`, which adds `SelectAst`, `InsertAst`, `UpdateAst` and `DeleteAst`: a builder query interpolated into `db.raw.sql` or `fns.raw` lands in the parts as its statement AST. A `RawQueryAst` interpolated into another raw template is still spread into the outer parts, so it never appears as a part.
|
|
270
|
+
|
|
271
|
+
In every file the detection matches, find each walk over `parts` that sends a non-string part to an expression handler, and give the statement kinds their own branch. Each statement AST has `kind` `'select'`, `'insert'`, `'update'` or `'delete'`, which no expression kind uses. A renderer renders a statement part with the function it uses for that statement at top level, with no parentheses:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
// Before
|
|
275
|
+
parts.map((part) => (typeof part === 'string' ? part : renderExpr(part, ctx))).join('');
|
|
276
|
+
|
|
277
|
+
// After
|
|
278
|
+
parts
|
|
279
|
+
.map((part) => {
|
|
280
|
+
if (typeof part === 'string') {
|
|
281
|
+
return part;
|
|
282
|
+
}
|
|
283
|
+
switch (part.kind) {
|
|
284
|
+
case 'select':
|
|
285
|
+
return renderSelect(part, ctx);
|
|
286
|
+
case 'insert':
|
|
287
|
+
return renderInsert(part, ctx);
|
|
288
|
+
case 'update':
|
|
289
|
+
return renderUpdate(part, ctx);
|
|
290
|
+
case 'delete':
|
|
291
|
+
return renderDelete(part, ctx);
|
|
292
|
+
default:
|
|
293
|
+
return renderExpr(part, ctx);
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
.join('');
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
A walker that only needs parameters can call `part.collectParamRefs()` on every non-string part, since the statement ASTs have it too. `RawQueryAst.collectParamRefs()` and `rewrite()` already reach into statement parts.
|
|
300
|
+
|
|
301
|
+
`ExpressionFolder` has a new optional `mutation` arm, called for an INSERT, UPDATE or DELETE part of a `RawExpr`, beside the `select` arm called for a SELECT part. A folder that leaves it out gets `empty` for a mutation part, so existing folders compile unchanged; add the arm where a mutation's contents matter.
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
## Preserve an intentional MySQL callback isolation choice
|
|
305
|
+
|
|
306
|
+
### `mysql-explicit-isolation-default`
|
|
307
|
+
|
|
308
|
+
MySQL no longer sets every session to READ COMMITTED. Unconfigured explicit callback transactions now use the server/session default. If application code relied on the previous override, add `transactionOptions: { isolationLevel: 'ReadCommitted' }` to its MySQL client factory, or pass `{ isolationLevel: 'ReadCommitted' }` as the second argument to the relevant `transaction(callback, options)` calls.
|
|
309
|
+
|
|
310
|
+
You can also import `{ IsolationLevel }` from `@prisma/orm-mysql/runtime` and use `IsolationLevel.ReadCommitted` in either position. This optional constant syntax does not require migrating existing strings.
|
|
311
|
+
|
|
312
|
+
A defined per-call level overrides the factory level. An omitted or undefined level inherits it; null does not reset defaults and is rejected. ORM-owned implicit transactions continue to use ReadCommitted, independently of callback options. Manual lower-level transactions do not inherit factory defaults.
|
|
313
|
+
|
|
314
|
+
Verify behavior against the deployment's configured database default and concurrent transactions. Do not assume the server default is RepeatableRead. This change does not introduce batch transactions, timeout/maxWait options, P2028 handling or retry behavior.
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
## `contract-artifacts-restamp`
|
|
318
|
+
|
|
319
|
+
For every `contract.json` matched by `detection`, run the project's emit command (`prisma contract emit`, or the project's `contract:emit` script) once after upgrading. This entry accounts for the extension's embedded `version` moving to `8.0.0-rc.24`; any other difference in the emitted files comes from an earlier entry in this guide.
|