@prisma/orm-mongo 8.0.1-dev.44 → 8.0.1-dev.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/dist/{mongo-static-Dudm8H_X-DUUqqcta.mjs → mongo-static-DXgxqad2-EexeYfrg.mjs} +3 -3
  2. package/dist/{mongo-static-Dudm8H_X-DUUqqcta.mjs.map → mongo-static-DXgxqad2-EexeYfrg.mjs.map} +1 -1
  3. package/dist/runtime.mjs +1 -1
  4. package/dist/runtime.mjs.map +1 -1
  5. package/dist/static.mjs +1 -1
  6. package/package.json +12 -12
  7. package/skills/prisma-8/SKILL.md +3 -3
  8. package/skills/prisma-8/references/scripts/find-detection-hits.ts +57 -0
  9. package/skills/prisma-8/references/upgrade-app.md +29 -10
  10. package/skills/prisma-8/references/upgrade-extension.md +24 -7
  11. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +14 -10
  12. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +78 -3
  13. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +2 -2
  14. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +2 -2
  15. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.26-to-8.0.0-rc.27/instructions.md +4 -2
  16. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.27-to-8.0.0-rc.28/instructions.md +5 -0
  17. package/skills/prisma-8/upgrading/extension/upgrades/0.10-to-0.11/instructions.md +2 -1
  18. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +6 -6
  19. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +78 -3
  20. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +2 -2
  21. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +2 -2
  22. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.26-to-8.0.0-rc.27/instructions.md +1 -1
  23. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.27-to-8.0.0-rc.28/instructions.md +5 -0
@@ -9,8 +9,8 @@ import { buildNamespacedEnums } from "@prisma/orm-framework/contract/enum-access
9
9
  import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
10
10
  import { mongoQuery } from "@prisma/orm-family-mongo/query-builder";
11
11
  import { assertDefined } from "@prisma/orm-framework/utils/assertions";
12
- //#region ../../../3-targets/mongo/9-facade/dist/mongo-static-Dudm8H_X.mjs
13
- var version = "8.0.1-dev.44";
12
+ //#region ../../../3-targets/mongo/9-facade/dist/mongo-static-DXgxqad2.mjs
13
+ var version = "8.0.1-dev.45";
14
14
  const serializer = new MongoContractSerializer();
15
15
  const validator = `${mongoRuntimeTarget.targetId}@${version}`;
16
16
  /**
@@ -71,4 +71,4 @@ function mongoStatic(options) {
71
71
  //#endregion
72
72
  export { validateMongoContract as i, contractFromJson as n, mongoStatic as r, buildMongoStaticContext as t };
73
73
 
74
- //# sourceMappingURL=mongo-static-Dudm8H_X-DUUqqcta.mjs.map
74
+ //# sourceMappingURL=mongo-static-DXgxqad2-EexeYfrg.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"mongo-static-Dudm8H_X-DUUqqcta.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/mongo-static-Dudm8H_X.mjs"],"sourcesContent":["import mongoRuntimeAdapter from \"@internal/adapter-mongo/runtime\";\nimport { mongoRaw } from \"@internal/mongo-orm\";\nimport { createMongoExecutionContext, createMongoExecutionStack, enumMemberCodecFor } from \"@internal/mongo-runtime\";\nimport mongoRuntimeTarget from \"@internal/target-mongo/runtime\";\nimport { isContractBuiltInMemory } from \"@internal/contract/stored-format\";\nimport { validateContractOnce } from \"@internal/contract/validate-once\";\nimport { MongoContractSerializer } from \"@internal/family-mongo/ir\";\nimport { buildNamespacedEnums } from \"@internal/contract/enum-accessor\";\nimport { UNBOUND_NAMESPACE_ID } from \"@internal/framework-components/ir\";\nimport { mongoQuery } from \"@internal/mongo-query-builder\";\nimport { assertDefined } from \"@internal/utils/assertions\";\n//#region package.json\nvar version = \"8.0.1-dev.44\";\n//#endregion\n//#region src/static/contract-from-json.ts\nconst serializer = new MongoContractSerializer();\nconst validator = `${mongoRuntimeTarget.targetId}@${version}`;\n/**\n* Validates an emitted Mongo `contract.json` and returns it as the contract type the application\n* names, ready to pass to `mongo({ contract })` and `mongoStatic({ contract })`. Clients built from\n* the result do not validate it again.\n*\n* The returned value's top level is frozen; its nested objects are not. Do not change `json` or the\n* returned value after the call: clients built from the value later do not validate it again.\n*\n* @example\n* ```ts\n* import type { Contract } from './contract.d';\n* import contractJson from './contract.json' with { type: 'json' };\n*\n* export const contract = contractFromJson<Contract>(contractJson);\n* ```\n*/\nfunction contractFromJson(json) {\n\treturn validateContractOnce(json, validator, (input) => serializer.deserializeContract(input));\n}\n/** Validates a contract value for a Mongo client, once per value. */\nfunction validateMongoContract(contract) {\n\treturn validateContractOnce(contract, validator, () => serializer.deserializeContract(isContractBuiltInMemory(contract) ? serializer.serializeContract(contract) : contract));\n}\n//#endregion\n//#region src/static/mongo-static.ts\nfunction buildMongoStaticContext(contract, stack) {\n\tconst context = createMongoExecutionContext({\n\t\tcontract,\n\t\tstack\n\t});\n\tconst enums = Object.freeze(buildNamespacedEnums(context.contract.domain, enumMemberCodecFor(context.codecs)))[UNBOUND_NAMESPACE_ID];\n\tassertDefined(enums, \"the unbound namespace always exists on a mongo builder output\");\n\treturn {\n\t\tcontext,\n\t\tcontract,\n\t\tenums,\n\t\tquery: mongoQuery({ context }),\n\t\traw: mongoRaw({ context })\n\t};\n}\n/**\n* The query surfaces of a Mongo client without a driver: `query`, `raw` and `enums`. Use it where\n* loading `mongodb` is not wanted.\n*\n* @example\n* ```ts\n* const { enums } = mongoStatic({ contract: contractFromJson<Contract>(contractJson) });\n* ```\n*/\nfunction mongoStatic(options) {\n\tconst stack = createMongoExecutionStack({\n\t\ttarget: mongoRuntimeTarget,\n\t\tadapter: mongoRuntimeAdapter,\n\t\textensions: options.extensions ?? []\n\t});\n\treturn buildMongoStaticContext(validateMongoContract(options.contract), stack);\n}\n//#endregion\nexport { validateMongoContract as i, mongoStatic as n, contractFromJson as r, buildMongoStaticContext as t };\n\n//# sourceMappingURL=mongo-static-Dudm8H_X.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,IAAI,UAAU;AAGd,MAAM,aAAa,IAAI,wBAAwB;AAC/C,MAAM,YAAY,GAAG,mBAAmB,SAAS,GAAG;;;;;;;;;;;;;;;;;AAiBpD,SAAS,iBAAiB,MAAM;CAC/B,OAAO,qBAAqB,MAAM,YAAY,UAAU,WAAW,oBAAoB,KAAK,CAAC;AAC9F;;AAEA,SAAS,sBAAsB,UAAU;CACxC,OAAO,qBAAqB,UAAU,iBAAiB,WAAW,oBAAoB,wBAAwB,QAAQ,IAAI,WAAW,kBAAkB,QAAQ,IAAI,QAAQ,CAAC;AAC7K;AAGA,SAAS,wBAAwB,UAAU,OAAO;CACjD,MAAM,UAAU,4BAA4B;EAC3C;EACA;CACD,CAAC;CACD,MAAM,QAAQ,OAAO,OAAO,qBAAqB,QAAQ,SAAS,QAAQ,mBAAmB,QAAQ,MAAM,CAAC,CAAC,CAAC,CAAC;CAC/G,cAAc,OAAO,+DAA+D;CACpF,OAAO;EACN;EACA;EACA;EACA,OAAO,WAAW,EAAE,QAAQ,CAAC;EAC7B,KAAK,SAAS,EAAE,QAAQ,CAAC;CAC1B;AACD;;;;;;;;;;AAUA,SAAS,YAAY,SAAS;CAC7B,MAAM,QAAQ,0BAA0B;EACvC,QAAQ;EACR,SAAS;EACT,YAAY,QAAQ,cAAc,CAAC;CACpC,CAAC;CACD,OAAO,wBAAwB,sBAAsB,QAAQ,QAAQ,GAAG,KAAK;AAC9E"}
1
+ {"version":3,"file":"mongo-static-DXgxqad2-EexeYfrg.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/mongo-static-DXgxqad2.mjs"],"sourcesContent":["import mongoRuntimeAdapter from \"@internal/adapter-mongo/runtime\";\nimport { mongoRaw } from \"@internal/mongo-orm\";\nimport { createMongoExecutionContext, createMongoExecutionStack, enumMemberCodecFor } from \"@internal/mongo-runtime\";\nimport mongoRuntimeTarget from \"@internal/target-mongo/runtime\";\nimport { isContractBuiltInMemory } from \"@internal/contract/stored-format\";\nimport { validateContractOnce } from \"@internal/contract/validate-once\";\nimport { MongoContractSerializer } from \"@internal/family-mongo/ir\";\nimport { buildNamespacedEnums } from \"@internal/contract/enum-accessor\";\nimport { UNBOUND_NAMESPACE_ID } from \"@internal/framework-components/ir\";\nimport { mongoQuery } from \"@internal/mongo-query-builder\";\nimport { assertDefined } from \"@internal/utils/assertions\";\n//#region package.json\nvar version = \"8.0.1-dev.45\";\n//#endregion\n//#region src/static/contract-from-json.ts\nconst serializer = new MongoContractSerializer();\nconst validator = `${mongoRuntimeTarget.targetId}@${version}`;\n/**\n* Validates an emitted Mongo `contract.json` and returns it as the contract type the application\n* names, ready to pass to `mongo({ contract })` and `mongoStatic({ contract })`. Clients built from\n* the result do not validate it again.\n*\n* The returned value's top level is frozen; its nested objects are not. Do not change `json` or the\n* returned value after the call: clients built from the value later do not validate it again.\n*\n* @example\n* ```ts\n* import type { Contract } from './contract.d';\n* import contractJson from './contract.json' with { type: 'json' };\n*\n* export const contract = contractFromJson<Contract>(contractJson);\n* ```\n*/\nfunction contractFromJson(json) {\n\treturn validateContractOnce(json, validator, (input) => serializer.deserializeContract(input));\n}\n/** Validates a contract value for a Mongo client, once per value. */\nfunction validateMongoContract(contract) {\n\treturn validateContractOnce(contract, validator, () => serializer.deserializeContract(isContractBuiltInMemory(contract) ? serializer.serializeContract(contract) : contract));\n}\n//#endregion\n//#region src/static/mongo-static.ts\nfunction buildMongoStaticContext(contract, stack) {\n\tconst context = createMongoExecutionContext({\n\t\tcontract,\n\t\tstack\n\t});\n\tconst enums = Object.freeze(buildNamespacedEnums(context.contract.domain, enumMemberCodecFor(context.codecs)))[UNBOUND_NAMESPACE_ID];\n\tassertDefined(enums, \"the unbound namespace always exists on a mongo builder output\");\n\treturn {\n\t\tcontext,\n\t\tcontract,\n\t\tenums,\n\t\tquery: mongoQuery({ context }),\n\t\traw: mongoRaw({ context })\n\t};\n}\n/**\n* The query surfaces of a Mongo client without a driver: `query`, `raw` and `enums`. Use it where\n* loading `mongodb` is not wanted.\n*\n* @example\n* ```ts\n* const { enums } = mongoStatic({ contract: contractFromJson<Contract>(contractJson) });\n* ```\n*/\nfunction mongoStatic(options) {\n\tconst stack = createMongoExecutionStack({\n\t\ttarget: mongoRuntimeTarget,\n\t\tadapter: mongoRuntimeAdapter,\n\t\textensions: options.extensions ?? []\n\t});\n\treturn buildMongoStaticContext(validateMongoContract(options.contract), stack);\n}\n//#endregion\nexport { validateMongoContract as i, mongoStatic as n, contractFromJson as r, buildMongoStaticContext as t };\n\n//# sourceMappingURL=mongo-static-DXgxqad2.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,IAAI,UAAU;AAGd,MAAM,aAAa,IAAI,wBAAwB;AAC/C,MAAM,YAAY,GAAG,mBAAmB,SAAS,GAAG;;;;;;;;;;;;;;;;;AAiBpD,SAAS,iBAAiB,MAAM;CAC/B,OAAO,qBAAqB,MAAM,YAAY,UAAU,WAAW,oBAAoB,KAAK,CAAC;AAC9F;;AAEA,SAAS,sBAAsB,UAAU;CACxC,OAAO,qBAAqB,UAAU,iBAAiB,WAAW,oBAAoB,wBAAwB,QAAQ,IAAI,WAAW,kBAAkB,QAAQ,IAAI,QAAQ,CAAC;AAC7K;AAGA,SAAS,wBAAwB,UAAU,OAAO;CACjD,MAAM,UAAU,4BAA4B;EAC3C;EACA;CACD,CAAC;CACD,MAAM,QAAQ,OAAO,OAAO,qBAAqB,QAAQ,SAAS,QAAQ,mBAAmB,QAAQ,MAAM,CAAC,CAAC,CAAC,CAAC;CAC/G,cAAc,OAAO,+DAA+D;CACpF,OAAO;EACN;EACA;EACA;EACA,OAAO,WAAW,EAAE,QAAQ,CAAC;EAC7B,KAAK,SAAS,EAAE,QAAQ,CAAC;CAC1B;AACD;;;;;;;;;;AAUA,SAAS,YAAY,SAAS;CAC7B,MAAM,QAAQ,0BAA0B;EACvC,QAAQ;EACR,SAAS;EACT,YAAY,QAAQ,cAAc,CAAC;CACpC,CAAC;CACD,OAAO,wBAAwB,sBAAsB,QAAQ,QAAQ,GAAG,KAAK;AAC9E"}
package/dist/runtime.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as validateMongoContract, t as buildMongoStaticContext } from "./mongo-static-Dudm8H_X-DUUqqcta.mjs";
1
+ import { i as validateMongoContract, t as buildMongoStaticContext } from "./mongo-static-DXgxqad2-EexeYfrg.mjs";
2
2
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
3
3
  import mongoRuntimeAdapter from "@prisma/orm-target-mongo/adapter/runtime";
4
4
  import { mongoOrm } from "@prisma/orm-family-mongo/orm";
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/runtime.mjs"],"sourcesContent":["import { i as validateMongoContract, t as buildMongoStaticContext } from \"./mongo-static-Dudm8H_X.mjs\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { isStructuredError, structuredError } from \"@internal/utils/structured-error\";\nimport mongoRuntimeAdapter from \"@internal/adapter-mongo/runtime\";\nimport mongoRuntimeDriver from \"@internal/driver-mongo/runtime\";\nimport { AsyncIterableResult } from \"@internal/framework-components/runtime\";\nimport { mongoOrm } from \"@internal/mongo-orm\";\nimport { createMongoExecutionStack, createMongoRuntime } from \"@internal/mongo-runtime\";\nimport mongoRuntimeTarget from \"@internal/target-mongo/runtime\";\nimport { InvariantError } from \"@internal/utils/invariant-error\";\nimport { ConnectionString } from \"mongodb-connection-string-url\";\nimport { blindCast } from \"@internal/utils/casts\";\n//#region src/runtime/mongo-errors.ts\nfunction mongoError(code, message, options) {\n\treturn structuredError(code, message, {\n\t\t...options,\n\t\tmeta: {\n\t\t\t...options?.meta,\n\t\t\textension: \"mongo\"\n\t\t}\n\t});\n}\n//#endregion\n//#region src/runtime/binding.ts\nconst URL_SCHEME_PATTERN = /^([a-z][a-z\\d+.-]*):\\/\\//i;\nconst MONGO_SCHEMES = /* @__PURE__ */ new Set([\"mongodb\", \"mongodb+srv\"]);\nfunction validateMongoUrl(url) {\n\tconst trimmed = url.trim();\n\tif (trimmed.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a non-empty string\");\n\tconst scheme = URL_SCHEME_PATTERN.exec(trimmed)?.[1];\n\tif (scheme === void 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\tif (!MONGO_SCHEMES.has(scheme)) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must use mongodb:// or mongodb+srv://\");\n\ttry {\n\t\treturn new ConnectionString(trimmed);\n\t} catch {\n\t\tthrow mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\t}\n}\nfunction extractDbNameFromUrl(parsed) {\n\tconst [encodedDbName = \"\"] = parsed.pathname.slice(1).split(\"/\");\n\tif (encodedDbName.length === 0) return;\n\ttry {\n\t\treturn decodeURIComponent(encodedDbName);\n\t} catch {\n\t\tthrow mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\t}\n}\nfunction resolveMongoBinding(options) {\n\tconst providedCount = Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.uri !== void 0) + Number(options.mongoClient !== void 0);\n\tif (providedCount !== 1) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Provide one binding input: binding, url, uri+dbName, or mongoClient+dbName\", { meta: { received: providedCount } });\n\tif (options.binding !== void 0) return options.binding;\n\tif (options.url !== void 0) {\n\t\tconst parsed = validateMongoUrl(options.url);\n\t\tif (options.dbName !== void 0 && options.dbName.trim().length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { url, dbName } requires a non-empty dbName\");\n\t\tconst explicitDbName = options.dbName?.trim();\n\t\tconst dbName = explicitDbName !== void 0 && explicitDbName.length > 0 ? explicitDbName : extractDbNameFromUrl(parsed);\n\t\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must include a database name in its path (e.g. mongodb://host:27017/mydb), or pass dbName explicitly\");\n\t\treturn {\n\t\t\tkind: \"url\",\n\t\t\turl: options.url.trim(),\n\t\t\tdbName\n\t\t};\n\t}\n\tif (options.uri !== void 0) {\n\t\tvalidateMongoUrl(options.uri);\n\t\tconst dbName = options.dbName?.trim();\n\t\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { uri, dbName } requires a non-empty dbName\");\n\t\treturn {\n\t\t\tkind: \"url\",\n\t\t\turl: options.uri.trim(),\n\t\t\tdbName\n\t\t};\n\t}\n\tconst mongoClient = options.mongoClient;\n\tif (mongoClient === void 0) throw new InvariantError(\"Invariant violation: expected mongo binding after validation\");\n\tconst dbName = options.dbName?.trim();\n\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { mongoClient, dbName } requires a non-empty dbName\");\n\treturn {\n\t\tkind: \"mongoClient\",\n\t\tclient: mongoClient,\n\t\tdbName\n\t};\n}\nfunction resolveOptionalMongoBinding(options) {\n\tconst providedCount = Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.uri !== void 0) + Number(options.mongoClient !== void 0);\n\tif (providedCount === 0) return;\n\tif (providedCount !== 1) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Provide one binding input: binding, url, uri+dbName, or mongoClient+dbName\", { meta: { received: providedCount } });\n\tif (options.binding !== void 0) return resolveMongoBinding({ binding: options.binding });\n\tif (options.url !== void 0) return resolveMongoBinding(options.dbName !== void 0 ? {\n\t\turl: options.url,\n\t\tdbName: options.dbName\n\t} : { url: options.url });\n\tif (options.uri !== void 0) return resolveMongoBinding({\n\t\turi: options.uri,\n\t\tdbName: options.dbName ?? \"\"\n\t});\n\tif (options.mongoClient !== void 0) return resolveMongoBinding({\n\t\tmongoClient: options.mongoClient,\n\t\tdbName: options.dbName ?? \"\"\n\t});\n\tthrow new InvariantError(\"Invariant violation: expected one mongo binding branch\");\n}\n//#endregion\n//#region src/runtime/prepared-row-query.ts\nasync function prepareMongoQuery(runtime, declaration, callback) {\n\tlet description;\n\tconst statement = await runtime.prepare(declaration, (placeholders) => {\n\t\tconst authored = callback(placeholders);\n\t\tif (\"plan\" in authored) {\n\t\t\tdescription = authored;\n\t\t\treturn authored.plan;\n\t\t}\n\t\treturn authored;\n\t});\n\treturn blindCast(description ? createMongoPreparedRowQuery(description, statement) : statement);\n}\nfunction createMongoPreparedRowQuery(description, statement) {\n\treturn Object.freeze({ query(target, params, options) {\n\t\treturn description.consume(statement.query(target, params, options));\n\t} });\n}\n//#endregion\n//#region src/runtime/mongo.ts\n/**\n* Creates a lazy Mongo client. The client infers its contract type from `contract`: a value from\n* `contractFromJson` for an emitted contract, or a TypeScript-authored contract. A contract is\n* validated once, however many clients are built from it. The `orm` and `query` surfaces are\n* available at once; the driver connects on the first query or `connect()`.\n*\n* @example\n* ```ts\n* import { contractFromJson } from '@prisma/orm-mongo/static';\n* import mongo from '@prisma/orm-mongo/runtime';\n* import type { Contract } from './contract.d';\n* import contractJson from './contract.json' with { type: 'json' };\n*\n* export const contract = contractFromJson<Contract>(contractJson);\n* export const db = mongo({ contract, url: process.env['MONGODB_URL']! });\n* ```\n*/\nfunction mongo(options) {\n\tconst contract = validateMongoContract(options.contract);\n\tlet binding = resolveOptionalMongoBinding(options);\n\tconst stack = createMongoExecutionStack({\n\t\ttarget: mongoRuntimeTarget,\n\t\tadapter: mongoRuntimeAdapter,\n\t\tdriver: mongoRuntimeDriver,\n\t\textensions: options.extensions ?? []\n\t});\n\tconst { context, query, enums, raw } = buildMongoStaticContext(contract, stack);\n\tlet runtimePromise;\n\tlet closed = false;\n\tlet runtimeInstance;\n\tconst closedError = () => mongoError(\"DRIVER.NOT_CONNECTED\", \"Mongo client is closed\");\n\tconst createRuntime = () => {\n\t\tif (runtimeInstance !== void 0) return runtimeInstance;\n\t\tconst driver = stack.driver.create();\n\t\truntimeInstance = {\n\t\t\truntime: createMongoRuntime({\n\t\t\t\tcontext,\n\t\t\t\tadapter: stack.adapter.create(stack),\n\t\t\t\tdriver,\n\t\t\t\t...ifDefined(\"mode\", options.mode),\n\t\t\t\t...ifDefined(\"middleware\", options.middleware),\n\t\t\t\t...ifDefined(\"log\", options.log)\n\t\t\t}),\n\t\t\tdriver\n\t\t};\n\t\treturn runtimeInstance;\n\t};\n\tconst buildRuntime = async (resolvedBinding) => {\n\t\tconst { runtime, driver } = createRuntime();\n\t\tawait driver.connect(resolvedBinding);\n\t\treturn runtime;\n\t};\n\tconst getRuntime = () => {\n\t\tif (closed) return Promise.reject(closedError());\n\t\tif (runtimePromise !== void 0) return runtimePromise;\n\t\tif (binding === void 0) return Promise.reject(mongoError(\"RUNTIME.BINDING_MISSING\", \"Mongo binding not configured. Pass url/uri+dbName/mongoClient+dbName/binding to mongo(...) or call db.connect({ ... }).\"));\n\t\truntimePromise = buildRuntime(binding).catch((err) => {\n\t\t\truntimePromise = void 0;\n\t\t\tthrow err;\n\t\t});\n\t\treturn runtimePromise;\n\t};\n\tfunction queryRows(plan) {\n\t\tasync function* iterate() {\n\t\t\tyield* (await getRuntime()).query(plan);\n\t\t}\n\t\treturn new AsyncIterableResult(iterate());\n\t}\n\tasync function executeStats(plan) {\n\t\treturn (await getRuntime()).execute(plan);\n\t}\n\treturn {\n\t\torm: mongoOrm({\n\t\t\tcontext,\n\t\t\truntime: {\n\t\t\t\tquery: queryRows,\n\t\t\t\texecute: executeStats\n\t\t\t}\n\t\t}),\n\t\tquery,\n\t\traw,\n\t\tcontract,\n\t\tenums,\n\t\tcontext,\n\t\tasync connect(bindingInput) {\n\t\t\tif (closed) throw closedError();\n\t\t\tif (runtimePromise !== void 0) {\n\t\t\t\tif (bindingInput !== void 0) throw mongoError(\"DRIVER.ALREADY_CONNECTED\", \"Mongo client is already bound\", {\n\t\t\t\t\twhy: \"connect() was given options after the client was bound to a database.\",\n\t\t\t\t\tfix: \"Call connect() without options, or create a new client for another database.\"\n\t\t\t\t});\n\t\t\t\tconst runtime = await runtimePromise;\n\t\t\t\tif (closed) throw closedError();\n\t\t\t\treturn runtime;\n\t\t\t}\n\t\t\tif (bindingInput !== void 0) binding = resolveMongoBinding(bindingInput);\n\t\t\tif (binding === void 0) throw mongoError(\"RUNTIME.BINDING_MISSING\", \"Mongo binding not configured. Pass url/uri+dbName/mongoClient+dbName/binding to mongo(...) or call db.connect({ ... }).\");\n\t\t\tconst runtime = await getRuntime();\n\t\t\tif (closed) throw closedError();\n\t\t\treturn runtime;\n\t\t},\n\t\truntime() {\n\t\t\treturn getRuntime();\n\t\t},\n\t\tasync prepare(declaration, callback) {\n\t\t\tif (closed) throw closedError();\n\t\t\treturn prepareMongoQuery(createRuntime().runtime, declaration, callback);\n\t\t},\n\t\tasync close() {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\tawait runtimePromise?.catch(() => void 0);\n\t\t\tawait runtimeInstance?.runtime.close();\n\t\t},\n\t\t[Symbol.asyncDispose]() {\n\t\t\treturn this.close();\n\t\t}\n\t};\n}\n//#endregion\nexport { mongo as default, isStructuredError };\n\n//# sourceMappingURL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,MAAM,QAAQ,cAAc;GAC3B,IAAI,QAAQ,MAAM,YAAY;GAC9B,IAAI,mBAAmB,KAAK,GAAG;IAC9B,IAAI,iBAAiB,KAAK,GAAG,MAAM,WAAW,4BAA4B,iCAAiC;KAC1G,KAAK;KACL,KAAK;IACN,CAAC;IACD,MAAM,UAAU,MAAM;IACtB,IAAI,QAAQ,MAAM,YAAY;IAC9B,OAAO;GACR;GACA,IAAI,iBAAiB,KAAK,GAAG,UAAU,oBAAoB,YAAY;GACvE,IAAI,YAAY,KAAK,GAAG,MAAM,WAAW,2BAA2B,yHAAyH;GAC7L,MAAM,UAAU,MAAM,WAAW;GACjC,IAAI,QAAQ,MAAM,YAAY;GAC9B,OAAO;EACR;EACA,UAAU;GACT,OAAO,WAAW;EACnB;EACA,MAAM,QAAQ,aAAa,UAAU;GACpC,IAAI,QAAQ,MAAM,YAAY;GAC9B,OAAO,kBAAkB,cAAc,CAAC,CAAC,SAAS,aAAa,QAAQ;EACxE;EACA,MAAM,QAAQ;GACb,IAAI,QAAQ;GACZ,SAAS;GACT,MAAM,gBAAgB,YAAY,KAAK,CAAC;GACxC,MAAM,iBAAiB,QAAQ,MAAM;EACtC;EACA,CAAC,OAAO,gBAAgB;GACvB,OAAO,KAAK,MAAM;EACnB;CACD;AACD"}
1
+ {"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/runtime.mjs"],"sourcesContent":["import { i as validateMongoContract, t as buildMongoStaticContext } from \"./mongo-static-DXgxqad2.mjs\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { isStructuredError, structuredError } from \"@internal/utils/structured-error\";\nimport mongoRuntimeAdapter from \"@internal/adapter-mongo/runtime\";\nimport mongoRuntimeDriver from \"@internal/driver-mongo/runtime\";\nimport { AsyncIterableResult } from \"@internal/framework-components/runtime\";\nimport { mongoOrm } from \"@internal/mongo-orm\";\nimport { createMongoExecutionStack, createMongoRuntime } from \"@internal/mongo-runtime\";\nimport mongoRuntimeTarget from \"@internal/target-mongo/runtime\";\nimport { InvariantError } from \"@internal/utils/invariant-error\";\nimport { ConnectionString } from \"mongodb-connection-string-url\";\nimport { blindCast } from \"@internal/utils/casts\";\n//#region src/runtime/mongo-errors.ts\nfunction mongoError(code, message, options) {\n\treturn structuredError(code, message, {\n\t\t...options,\n\t\tmeta: {\n\t\t\t...options?.meta,\n\t\t\textension: \"mongo\"\n\t\t}\n\t});\n}\n//#endregion\n//#region src/runtime/binding.ts\nconst URL_SCHEME_PATTERN = /^([a-z][a-z\\d+.-]*):\\/\\//i;\nconst MONGO_SCHEMES = /* @__PURE__ */ new Set([\"mongodb\", \"mongodb+srv\"]);\nfunction validateMongoUrl(url) {\n\tconst trimmed = url.trim();\n\tif (trimmed.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a non-empty string\");\n\tconst scheme = URL_SCHEME_PATTERN.exec(trimmed)?.[1];\n\tif (scheme === void 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\tif (!MONGO_SCHEMES.has(scheme)) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must use mongodb:// or mongodb+srv://\");\n\ttry {\n\t\treturn new ConnectionString(trimmed);\n\t} catch {\n\t\tthrow mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\t}\n}\nfunction extractDbNameFromUrl(parsed) {\n\tconst [encodedDbName = \"\"] = parsed.pathname.slice(1).split(\"/\");\n\tif (encodedDbName.length === 0) return;\n\ttry {\n\t\treturn decodeURIComponent(encodedDbName);\n\t} catch {\n\t\tthrow mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\t}\n}\nfunction resolveMongoBinding(options) {\n\tconst providedCount = Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.uri !== void 0) + Number(options.mongoClient !== void 0);\n\tif (providedCount !== 1) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Provide one binding input: binding, url, uri+dbName, or mongoClient+dbName\", { meta: { received: providedCount } });\n\tif (options.binding !== void 0) return options.binding;\n\tif (options.url !== void 0) {\n\t\tconst parsed = validateMongoUrl(options.url);\n\t\tif (options.dbName !== void 0 && options.dbName.trim().length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { url, dbName } requires a non-empty dbName\");\n\t\tconst explicitDbName = options.dbName?.trim();\n\t\tconst dbName = explicitDbName !== void 0 && explicitDbName.length > 0 ? explicitDbName : extractDbNameFromUrl(parsed);\n\t\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must include a database name in its path (e.g. mongodb://host:27017/mydb), or pass dbName explicitly\");\n\t\treturn {\n\t\t\tkind: \"url\",\n\t\t\turl: options.url.trim(),\n\t\t\tdbName\n\t\t};\n\t}\n\tif (options.uri !== void 0) {\n\t\tvalidateMongoUrl(options.uri);\n\t\tconst dbName = options.dbName?.trim();\n\t\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { uri, dbName } requires a non-empty dbName\");\n\t\treturn {\n\t\t\tkind: \"url\",\n\t\t\turl: options.uri.trim(),\n\t\t\tdbName\n\t\t};\n\t}\n\tconst mongoClient = options.mongoClient;\n\tif (mongoClient === void 0) throw new InvariantError(\"Invariant violation: expected mongo binding after validation\");\n\tconst dbName = options.dbName?.trim();\n\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { mongoClient, dbName } requires a non-empty dbName\");\n\treturn {\n\t\tkind: \"mongoClient\",\n\t\tclient: mongoClient,\n\t\tdbName\n\t};\n}\nfunction resolveOptionalMongoBinding(options) {\n\tconst providedCount = Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.uri !== void 0) + Number(options.mongoClient !== void 0);\n\tif (providedCount === 0) return;\n\tif (providedCount !== 1) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Provide one binding input: binding, url, uri+dbName, or mongoClient+dbName\", { meta: { received: providedCount } });\n\tif (options.binding !== void 0) return resolveMongoBinding({ binding: options.binding });\n\tif (options.url !== void 0) return resolveMongoBinding(options.dbName !== void 0 ? {\n\t\turl: options.url,\n\t\tdbName: options.dbName\n\t} : { url: options.url });\n\tif (options.uri !== void 0) return resolveMongoBinding({\n\t\turi: options.uri,\n\t\tdbName: options.dbName ?? \"\"\n\t});\n\tif (options.mongoClient !== void 0) return resolveMongoBinding({\n\t\tmongoClient: options.mongoClient,\n\t\tdbName: options.dbName ?? \"\"\n\t});\n\tthrow new InvariantError(\"Invariant violation: expected one mongo binding branch\");\n}\n//#endregion\n//#region src/runtime/prepared-row-query.ts\nasync function prepareMongoQuery(runtime, declaration, callback) {\n\tlet description;\n\tconst statement = await runtime.prepare(declaration, (placeholders) => {\n\t\tconst authored = callback(placeholders);\n\t\tif (\"plan\" in authored) {\n\t\t\tdescription = authored;\n\t\t\treturn authored.plan;\n\t\t}\n\t\treturn authored;\n\t});\n\treturn blindCast(description ? createMongoPreparedRowQuery(description, statement) : statement);\n}\nfunction createMongoPreparedRowQuery(description, statement) {\n\treturn Object.freeze({ query(target, params, options) {\n\t\treturn description.consume(statement.query(target, params, options));\n\t} });\n}\n//#endregion\n//#region src/runtime/mongo.ts\n/**\n* Creates a lazy Mongo client. The client infers its contract type from `contract`: a value from\n* `contractFromJson` for an emitted contract, or a TypeScript-authored contract. A contract is\n* validated once, however many clients are built from it. The `orm` and `query` surfaces are\n* available at once; the driver connects on the first query or `connect()`.\n*\n* @example\n* ```ts\n* import { contractFromJson } from '@prisma/orm-mongo/static';\n* import mongo from '@prisma/orm-mongo/runtime';\n* import type { Contract } from './contract.d';\n* import contractJson from './contract.json' with { type: 'json' };\n*\n* export const contract = contractFromJson<Contract>(contractJson);\n* export const db = mongo({ contract, url: process.env['MONGODB_URL']! });\n* ```\n*/\nfunction mongo(options) {\n\tconst contract = validateMongoContract(options.contract);\n\tlet binding = resolveOptionalMongoBinding(options);\n\tconst stack = createMongoExecutionStack({\n\t\ttarget: mongoRuntimeTarget,\n\t\tadapter: mongoRuntimeAdapter,\n\t\tdriver: mongoRuntimeDriver,\n\t\textensions: options.extensions ?? []\n\t});\n\tconst { context, query, enums, raw } = buildMongoStaticContext(contract, stack);\n\tlet runtimePromise;\n\tlet closed = false;\n\tlet runtimeInstance;\n\tconst closedError = () => mongoError(\"DRIVER.NOT_CONNECTED\", \"Mongo client is closed\");\n\tconst createRuntime = () => {\n\t\tif (runtimeInstance !== void 0) return runtimeInstance;\n\t\tconst driver = stack.driver.create();\n\t\truntimeInstance = {\n\t\t\truntime: createMongoRuntime({\n\t\t\t\tcontext,\n\t\t\t\tadapter: stack.adapter.create(stack),\n\t\t\t\tdriver,\n\t\t\t\t...ifDefined(\"mode\", options.mode),\n\t\t\t\t...ifDefined(\"middleware\", options.middleware),\n\t\t\t\t...ifDefined(\"log\", options.log)\n\t\t\t}),\n\t\t\tdriver\n\t\t};\n\t\treturn runtimeInstance;\n\t};\n\tconst buildRuntime = async (resolvedBinding) => {\n\t\tconst { runtime, driver } = createRuntime();\n\t\tawait driver.connect(resolvedBinding);\n\t\treturn runtime;\n\t};\n\tconst getRuntime = () => {\n\t\tif (closed) return Promise.reject(closedError());\n\t\tif (runtimePromise !== void 0) return runtimePromise;\n\t\tif (binding === void 0) return Promise.reject(mongoError(\"RUNTIME.BINDING_MISSING\", \"Mongo binding not configured. Pass url/uri+dbName/mongoClient+dbName/binding to mongo(...) or call db.connect({ ... }).\"));\n\t\truntimePromise = buildRuntime(binding).catch((err) => {\n\t\t\truntimePromise = void 0;\n\t\t\tthrow err;\n\t\t});\n\t\treturn runtimePromise;\n\t};\n\tfunction queryRows(plan) {\n\t\tasync function* iterate() {\n\t\t\tyield* (await getRuntime()).query(plan);\n\t\t}\n\t\treturn new AsyncIterableResult(iterate());\n\t}\n\tasync function executeStats(plan) {\n\t\treturn (await getRuntime()).execute(plan);\n\t}\n\treturn {\n\t\torm: mongoOrm({\n\t\t\tcontext,\n\t\t\truntime: {\n\t\t\t\tquery: queryRows,\n\t\t\t\texecute: executeStats\n\t\t\t}\n\t\t}),\n\t\tquery,\n\t\traw,\n\t\tcontract,\n\t\tenums,\n\t\tcontext,\n\t\tasync connect(bindingInput) {\n\t\t\tif (closed) throw closedError();\n\t\t\tif (runtimePromise !== void 0) {\n\t\t\t\tif (bindingInput !== void 0) throw mongoError(\"DRIVER.ALREADY_CONNECTED\", \"Mongo client is already bound\", {\n\t\t\t\t\twhy: \"connect() was given options after the client was bound to a database.\",\n\t\t\t\t\tfix: \"Call connect() without options, or create a new client for another database.\"\n\t\t\t\t});\n\t\t\t\tconst runtime = await runtimePromise;\n\t\t\t\tif (closed) throw closedError();\n\t\t\t\treturn runtime;\n\t\t\t}\n\t\t\tif (bindingInput !== void 0) binding = resolveMongoBinding(bindingInput);\n\t\t\tif (binding === void 0) throw mongoError(\"RUNTIME.BINDING_MISSING\", \"Mongo binding not configured. Pass url/uri+dbName/mongoClient+dbName/binding to mongo(...) or call db.connect({ ... }).\");\n\t\t\tconst runtime = await getRuntime();\n\t\t\tif (closed) throw closedError();\n\t\t\treturn runtime;\n\t\t},\n\t\truntime() {\n\t\t\treturn getRuntime();\n\t\t},\n\t\tasync prepare(declaration, callback) {\n\t\t\tif (closed) throw closedError();\n\t\t\treturn prepareMongoQuery(createRuntime().runtime, declaration, callback);\n\t\t},\n\t\tasync close() {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\tawait runtimePromise?.catch(() => void 0);\n\t\t\tawait runtimeInstance?.runtime.close();\n\t\t},\n\t\t[Symbol.asyncDispose]() {\n\t\t\treturn this.close();\n\t\t}\n\t};\n}\n//#endregion\nexport { mongo as default, isStructuredError };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;;;;;;;;;;AAaA,SAAS,WAAW,MAAM,SAAS,SAAS;CAC3C,OAAO,gBAAgB,MAAM,SAAS;EACrC,GAAG;EACH,MAAM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AAW,4BAA4B,iCAAiC;KAC1G,KAAK;KACL,KAAK;IACN,CAAC;IACD,MAAM,UAAU,MAAM;IACtB,IAAI,QAAQ,MAAM,YAAY;IAC9B,OAAO;GACR;GACA,IAAI,iBAAiB,KAAK,GAAG,UAAU,oBAAoB,YAAY;GACvE,IAAI,YAAY,KAAK,GAAG,MAAM,WAAW,2BAA2B,yHAAyH;GAC7L,MAAM,UAAU,MAAM,WAAW;GACjC,IAAI,QAAQ,MAAM,YAAY;GAC9B,OAAO;EACR;EACA,UAAU;GACT,OAAO,WAAW;EACnB;EACA,MAAM,QAAQ,aAAa,UAAU;GACpC,IAAI,QAAQ,MAAM,YAAY;GAC9B,OAAO,kBAAkB,cAAc,CAAC,CAAC,SAAS,aAAa,QAAQ;EACxE;EACA,MAAM,QAAQ;GACb,IAAI,QAAQ;GACZ,SAAS;GACT,MAAM,gBAAgB,YAAY,KAAK,CAAC;GACxC,MAAM,iBAAiB,QAAQ,MAAM;EACtC;EACA,CAAC,OAAO,gBAAgB;GACvB,OAAO,KAAK,MAAM;EACnB;CACD;AACD"}
package/dist/static.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as contractFromJson, r as mongoStatic } from "./mongo-static-Dudm8H_X-DUUqqcta.mjs";
1
+ import { n as contractFromJson, r as mongoStatic } from "./mongo-static-DXgxqad2-EexeYfrg.mjs";
2
2
  export { contractFromJson, mongoStatic as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/orm-mongo",
3
- "version": "8.0.1-dev.44",
3
+ "version": "8.0.1-dev.45",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -19,21 +19,21 @@
19
19
  "temporal-spec": "1.0.1"
20
20
  },
21
21
  "devDependencies": {
22
- "@internal/mongo": "8.0.1-dev.44",
23
- "@prisma/orm-family-mongo": "8.0.1-dev.44",
24
- "@prisma/orm-framework": "8.0.1-dev.44",
25
- "@prisma/orm-target-mongo": "8.0.1-dev.44",
26
- "@prisma/orm-toolchain": "8.0.1-dev.44",
27
- "@repo/tsconfig": "8.0.1-dev.44",
28
- "@repo/tsdown": "8.0.1-dev.44",
22
+ "@internal/mongo": "8.0.1-dev.45",
23
+ "@prisma/orm-family-mongo": "8.0.1-dev.45",
24
+ "@prisma/orm-framework": "8.0.1-dev.45",
25
+ "@prisma/orm-target-mongo": "8.0.1-dev.45",
26
+ "@prisma/orm-toolchain": "8.0.1-dev.45",
27
+ "@repo/tsconfig": "8.0.1-dev.45",
28
+ "@repo/tsdown": "8.0.1-dev.45",
29
29
  "tsdown": "0.22.14",
30
30
  "typescript": "5.9.3"
31
31
  },
32
32
  "peerDependencies": {
33
- "@prisma/orm-family-mongo": "8.0.1-dev.44",
34
- "@prisma/orm-framework": "8.0.1-dev.44",
35
- "@prisma/orm-target-mongo": "8.0.1-dev.44",
36
- "@prisma/orm-toolchain": "8.0.1-dev.44",
33
+ "@prisma/orm-family-mongo": "8.0.1-dev.45",
34
+ "@prisma/orm-framework": "8.0.1-dev.45",
35
+ "@prisma/orm-target-mongo": "8.0.1-dev.45",
36
+ "@prisma/orm-toolchain": "8.0.1-dev.45",
37
37
  "mongodb": "^7.0.0",
38
38
  "temporal-polyfill": "^1.0.8",
39
39
  "typescript": ">=5.9"
@@ -15,7 +15,7 @@ description: >-
15
15
  ORM 7 or earlier (schema.prisma + @prisma/client).
16
16
  metadata:
17
17
  library: '@prisma/orm-mongo'
18
- library_version: '8.0.1-dev.44'
18
+ library_version: '8.0.1-dev.45'
19
19
  version: '2026-09-12'
20
20
  ---
21
21
 
@@ -30,10 +30,10 @@ Prisma 8 moves fast, and your training data about it is very likely outdated. Th
30
30
  Check these before acting on anything below. Halt on the first one that fails and tell the user what is missing. Pre-conditions 1 and 3 describe an application that is already set up. Check only pre-condition 2 in a package that builds a target or is a Prisma extension, and when setting up a new project, which creates what 1 and 3 check.
31
31
 
32
32
  1. **The project is on Prisma 8.** `prisma.config.ts` exports `definePrismaConfig({ orm: ... })`, and `package.json` depends on the package for its database: `@prisma/orm-postgres`, `@prisma/orm-mongo`, `@prisma/orm-sqlite`, `@prisma/orm-mysql`, `@prisma/orm-mariadb`, or another package that `prisma.config.ts` imports `defineConfig` from. A project with `schema.prisma` and `@prisma/client` is Prisma 7 or earlier; this skill does not apply to it, and its instructions will break such a project.
33
- 2. **The skill matches the installed version.** Compare `metadata.library_version` in this file's frontmatter with the installed `@prisma/orm-*` version in `package.json`. If they differ, run `prisma skills sync` and re-read this file before continuing. If no `@prisma/orm-*` package is installed, as in a project not set up yet, this check passes.
33
+ 2. **The skill matches the installed version.** Compare `metadata.library_version` in this file's frontmatter with the installed `@prisma/orm-*` version in `package.json`. If they differ, run `prisma skills sync` and re-read this file before continuing. If no `@prisma/orm-*` package is installed, as in a project not set up yet, this check passes. During an upgrade it does not apply: the upgrade references have you read the skill of the newest published release, which is meant to be newer than the installed packages, and sync only when the upgrade is done ([`references/upgrade-app.md`](references/upgrade-app.md#step-0--read-the-newest-releases-skill), [`references/upgrade-extension.md`](references/upgrade-extension.md#step-0--read-the-newest-releases-skill)).
34
34
  3. **The contract artefacts exist.** `contract.json` and `contract.d.ts` sit next to the contract source named by `prisma.config.ts`. If they are missing or older than the source, run `prisma contract emit` first; every query and migration instruction below assumes current artefacts.
35
35
 
36
- **Import paths in the references.** The reference files name the published packages an application installs: `@prisma/orm-<target>/<subpath>` (`@prisma/orm-postgres/runtime`, `@prisma/orm-mongo/config`, `@prisma/orm-sqlite/runtime`) and `@prisma/orm-extension-<name>/<subpath>` (`@prisma/orm-extension-pgvector/control`). Some older per-transition instructions under `upgrading/` name a package by the Prisma repository's workspace name, which is not published; find the `@prisma/orm-*` entry that carries the same module before writing it into user code. The `metadata.library_version` in this file's frontmatter is the version it was published with; if it does not match the project's installed Prisma packages, run `prisma skills sync` and re-read.
36
+ **Import paths in the references.** The reference files name the published packages an application installs: `@prisma/orm-<target>/<subpath>` (`@prisma/orm-postgres/runtime`, `@prisma/orm-mongo/config`, `@prisma/orm-sqlite/runtime`) and `@prisma/orm-extension-<name>/<subpath>` (`@prisma/orm-extension-pgvector/control`). Some older per-transition instructions under `upgrading/` name a package by the Prisma repository's workspace name, which is not published; find the `@prisma/orm-*` entry that carries the same module before writing it into user code. The `metadata.library_version` in this file's frontmatter is the version it was published with; if it does not match the project's installed Prisma packages, run `prisma skills sync` and re-read, except during an upgrade, as pre-condition 2 says.
37
37
 
38
38
  ## Never reset or drop a database
39
39
 
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Prints the files of the project that a change's `detection` block of an upgrade guide finds, one path per line, relative to the working directory, which is the project root.
4
+ *
5
+ * Usage: node find-detection-hits.ts [--all] <glob> [<pattern>...] [--contains <text>...]
6
+ *
7
+ * A file is a hit when `glob` matches its path and any pattern, compiled with `new RegExp(pattern)` and no flags, matches its whole content, or its content contains any `--contains` text. With `--all`, for a detection with `anyMatch: false`, every pattern must match and every text be contained. Pass each pattern and text as it reads once decoded from the guide's YAML.
8
+ *
9
+ * It skips `node_modules` and `.git`, and does not follow symbolic links: a link to a file in the project is found through that file. A `**` in the glob does not enter a folder whose name starts with a dot, but a glob that names one, such as `.github/workflows/*.yml`, does.
10
+ */
11
+ import { readdirSync, readFileSync } from 'node:fs';
12
+ import { join, matchesGlob } from 'node:path';
13
+
14
+ const SKIPPED = new Set(['node_modules', '.git']);
15
+
16
+ function* projectFiles(dir: string, prefix: string): Generator<string> {
17
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
18
+ const path = prefix === '' ? entry.name : `${prefix}/${entry.name}`;
19
+ if (entry.isDirectory() && !SKIPPED.has(entry.name))
20
+ yield* projectFiles(join(dir, entry.name), path);
21
+ else if (entry.isFile()) yield path;
22
+ }
23
+ }
24
+
25
+ function main(args: readonly string[]): number {
26
+ const all = args[0] === '--all';
27
+ const [glob, ...rest] = all ? args.slice(1) : args;
28
+ if (glob === undefined || glob === '' || glob.startsWith('--')) {
29
+ process.stderr.write(
30
+ 'Usage: node find-detection-hits.ts [--all] <glob> [<pattern>...] [--contains <text>...]\n',
31
+ );
32
+ return 1;
33
+ }
34
+ const split = rest.includes('--contains') ? rest.indexOf('--contains') : rest.length;
35
+ const patterns = rest.slice(0, split).map((pattern) => new RegExp(pattern));
36
+ const texts = rest.slice(split + 1);
37
+ const root = process.cwd();
38
+ const hits: string[] = [];
39
+ for (const path of projectFiles(root, '')) {
40
+ if (!matchesGlob(path, glob)) continue;
41
+ const content = readFileSync(join(root, path), 'utf8');
42
+ const results = [
43
+ ...patterns.map((pattern) => pattern.test(content)),
44
+ ...texts.map((text) => content.includes(text)),
45
+ ];
46
+ if (all ? results.every(Boolean) : results.some(Boolean)) hits.push(path);
47
+ }
48
+ process.stdout.write(
49
+ hits
50
+ .sort()
51
+ .map((path) => `${path}\n`)
52
+ .join(''),
53
+ );
54
+ return 0;
55
+ }
56
+
57
+ process.exitCode = main(process.argv.slice(2));
@@ -4,11 +4,22 @@ This reference upgrades a project that **consumes** Prisma 8 via the public pack
4
4
 
5
5
  The per-transition instructions this reference reads live under [`../upgrading/app/upgrades/`](../upgrading/app/upgrades/).
6
6
 
7
- ## Step 0 — Upgrade to the newest instructions, then re-read
7
+ ## Step 0 — Read the newest release's skill
8
8
 
9
- The upgrade instructions ship inside the installed Prisma packages, so the copy on disk describes the version currently installed — not the version being upgraded *to*. Bug fixes to *old* per-transition instructions ship with each release as part of the cumulative set, so the newest copy is the one to run.
9
+ The skill in the project describes the release installed now. Each release carries the guide of every earlier step, with the corrections made to it since, such as a fixed script, or an instruction to install a later release in place of a step's own `<to>`. An earlier copy lacks the corrections made after it. So read this reference and every step's guide from the skill of the newest published release, even when the user's target is older, and run the guides' scripts from that copy:
10
10
 
11
- Do the version bump first (step 1 of the per-step flow below), re-sync the skills from the newly installed packages (`prisma skills sync`), and re-read this reference and the per-transition instructions before applying any code translation. If the agent runtime supports an in-session refresh, perform it after the sync; otherwise finish the session's reasoning against the re-read files.
11
+ 1. **Find the newest published release.** Run `pnpm view <database package> dist-tags.latest dist-tags.next`, with the project's database package, such as `@prisma/orm-postgres`. Take the greater of the two versions: `8.0.0-rc.27` is greater than `8.0.0-rc.25`, so compare the numbers after `rc.`, not the text, and `8.0.1` is greater than every `8.0.0-rc.N`.
12
+ 2. **Download its skill.** Unpack that release's package in a new, empty folder outside the project and outside every agent skills folder (`.agents/skills/`, `.claude/skills/`, `.cursor/skills/`, `.windsurf/skills/`), which `prisma skills sync` writes:
13
+
14
+ ```sh
15
+ dir="$(mktemp -d)"
16
+ curl -fsSL "$(pnpm view <database package>@<newest> dist.tarball)" | tar -xz -C "$dir"
17
+ echo "$dir/package/skills/prisma-8"
18
+ ```
19
+
20
+ The folder it prints is the skill's folder, which this reference and the guides call `<skill>`. If the download fails, stop and tell the user: the upgrade's installs need the same registry.
21
+ 3. **Read from that copy.** Read this reference again from `<skill>/references/upgrade-app.md`, unless that is the copy you are reading, and follow it from here. Read each step's guide from `<skill>/upgrading/app/upgrades/<from>-to-<to>/instructions.md`. Where a guide runs a script from the project's skill copy, such as `node .agents/skills/prisma-8/upgrading/...`, run the same path under `<skill>`, still from the project root: `node <skill>/upgrading/...`.
22
+ 4. **Do not sync the skill until the chain is done.** During the upgrade, do not run `prisma skills sync`, and ignore the line a `prisma` command prints when the project's skill copy differs from the installed packages: a sync would bring back the installed release's copy. Sync once, when the chain is done.
12
23
 
13
24
  ## Pre-flight — extension compatibility
14
25
 
@@ -78,21 +89,23 @@ If the from-to delta spans more than one release (e.g. `0.6 → 0.8`), build the
78
89
 
79
90
  The [`../upgrading/app/upgrades/`](../upgrading/app/upgrades/) directories name the steps — read the chain off the directory names rather than deriving it arithmetically. Each directory is `<from>-to-<to>`. A step normally spans one stable minor (`0.7-to-0.8`) or one release candidate (`8.0.0-rc.1-to-8.0.0-rc.2`). When intermediate versions were not published, a guide may span a larger hop; follow the available directory chain rather than inventing missing steps. Moving onto the RC line from the last stable minor is a single step of its own (`0.17-to-8.0.0-rc.1`).
80
91
 
81
- Apply each step in order, fully: bump, install, run instructions, validate, commit — before moving to the next. The one exception is [steps taken together](#steps-taken-together), which the pre-flight decides. Halt the chain on the first failed step; do not skip ahead.
92
+ Apply each step in order, fully: bump, install, run instructions, validate, commit — before moving to the next. The one exception is [steps taken together](#steps-taken-together), which the pre-flight, or a step's own guide, decides. Halt the chain on the first failed step; do not skip ahead.
82
93
 
83
- The chain order does not depend on which extensions are installed; the pre-flight has already worked out how far it can go, and which steps are taken together.
94
+ The chain order does not depend on which extensions are installed; the pre-flight works out how far it can go and which steps are taken together, and a step's own guide can add to that.
84
95
 
85
96
  ### Steps taken together
86
97
 
87
98
  An extension with versions of its own may have no release for some steps of the chain and a release for a later one. A release candidate cut after the extension's last release is one such step. The extension at its old release names the old Prisma versions, so the project cannot install those steps with it. The `prisma` command-line tool is the same: for some steps no `prisma` version fits, and a `prisma` command must run on the toolchain of the packages installed at that time. Take those steps, and the later step, together, using the per-step flow's own parts:
88
99
 
89
100
  - Do the bump once, to the later step's versions: the first later step for which every extension has a release and a `prisma` version fits.
90
- - Install once, and re-sync the skills.
101
+ - Install once.
91
102
  - Read and apply the upgrade instructions of every step from the first of them to that later step, in the chain's order, with no install in between.
92
103
  - Validate once, after the last of them, then commit. Name every step the commit covers in its message.
93
104
 
94
105
  The `prisma` commands that the earlier steps' instructions run, such as `prisma contract emit`, `prisma db sign` and `prisma migration plan`, run on the installed toolchain, which is the later step's. So where an earlier step's guide says what such a command must or must not change, read that against the later step: the command writes the later step's format. If validation fails, report every step taken together, and the change ids whose files the failure names, because the failure can come from any of them.
95
106
 
107
+ A step's own guide can also tell you to install a later release in place of its own `<to>`, as the `8.0.0-rc.25` to `8.0.0-rc.26` app guide does in step 2 of its "Order of the steps"; the guide gives its reason. The pre-flight can read this in the newest guides before installing anything, and take the steps together from the start, so that the bump happens once. If you find it after installing `<to>`, do as the guide says at the point in its order where it says it: bump again, to the newest release up to the user's target that every extension and a `prisma` version fit, choose `prisma` for that release, and install. Then read this step's guide again, from the skill of the newest published release as [Step 0](#step-0--read-the-newest-releases-skill) describes (fetch it again if a later release has been published since), and continue from the same point in its order. The steps from this one to that release are taken together: apply this guide and each later step's guide in order, and validate and commit once, as above. If no later release fits, or the user's target is this step itself, take the step alone and tell the user; when the project later reaches the step that fixes the fault, that step's guide says how to repair what the fault left.
108
+
96
109
  ## Per-step flow
97
110
 
98
111
  For each `(from, to)` step in the chain:
@@ -118,15 +131,21 @@ For each `(from, to)` step in the chain:
118
131
 
119
132
  **The `prisma` command-line tool.** Move `prisma` too, or add it as a development dependency if the project does not list it, at a version chosen as [Choosing the `prisma` version](#choosing-the-prisma-version) describes. Write the project's `@prisma/orm-toolchain` and `@prisma/orm-framework` lines exactly at the versions that `prisma` depends on, with no caret or tilde, in place of the caret or tilde the rules above give them, so that the install cannot take a later patch. `prisma` runs the ORM commands from its own copy of the toolchain, and that copy must be the application's, so the application's `@prisma/orm-toolchain` and `@prisma/orm-framework` must resolve to the versions `prisma` depends on. The pre-flight has already found the version for this step. A step no `prisma` version fits is taken together with a later one, or is past where the chain stops.
120
133
 
121
- The skill itself ships inside the Prisma packages, so bumping them is what updates it. There is no separate skill package to bump.
134
+ The skill itself ships inside the Prisma packages, so bumping them is what updates the project's copy, which you sync when the chain is done. There is no separate skill package to bump.
122
135
 
123
136
  2. **Install.** Run `pnpm install` (or the project's lockfile-managing command). The project's code is now broken against the new types — the upgrade instructions for `<from> → <to>` exist to fix it.
124
137
 
125
- 3. **Read the upgrade instructions.** Re-sync the skills (`prisma skills sync`) so the tree matches the version just installed, then load `../upgrading/app/upgrades/<from>-to-<to>/instructions.md`. Parse the YAML frontmatter and pay particular attention to its `changes[]` array.
138
+ 3. **Read the upgrade instructions.** Load `<skill>/upgrading/app/upgrades/<from>-to-<to>/instructions.md`, from the newest release's skill ([Step 0](#step-0--read-the-newest-releases-skill)). Parse the YAML frontmatter and pay particular attention to its `changes[]` array.
126
139
 
127
140
  4. **Apply each change.** When the guide's body has a section that orders the steps, such as `Order of the steps`, apply the changes in that order: it says which script runs before which, and when to sign the databases and when to plan and apply a migration. Where an entry's prose says to sign or migrate, do it at the step that section names. Otherwise take the entries in the order of `changes[]`. For each entry in `changes[]`:
128
141
  - If the entry has a `detection` block (glob + content predicate), run it; skip the change if no files match. No `detection` → apply unconditionally. Run the glob over the project's own files: skip `node_modules`, and build output such as `dist`, `build`, `.next` or `out` (whatever directories the project's build writes). A match there is generated code, which the next build rewrites; editing it changes nothing. Migration snapshots under `migrations/snapshots/` are committed files, not build output, so keep them.
129
- - How a `detection` block runs: `glob` selects files relative to the project root. Each `matches` entry, once read from the YAML, is a JavaScript regular expression, built as `new RegExp(pattern)` with no flags and tested against the whole content of one file at a time; each `contains` entry is a plain substring. A file is a hit when any entry matches it. Patterns may span lines, and some look at the whole file (for example, to skip a file that declares something elsewhere in it), so a line-by-line search such as `grep` or `rg` without `-U` is not the same test and can report files the pattern excludes. From a shell, `rg -U --pcre2 -l -e '<pattern>' <files>` tests whole files and gives the same hits.
142
+ - How a `detection` block runs: `glob` selects files relative to the project root. Each `matches` entry, once read from the YAML, is a JavaScript regular expression, built as `new RegExp(pattern)` with no flags and tested against the whole content of one file at a time; some older guides call these entries `regex`, which means the same. Each `contains` entry is a plain substring. A file is a hit when any entry matches it, or, when the block sets `anyMatch: false`, only when every entry matches it; `anyMatch: true` changes nothing. Patterns may span lines, and some look at the whole file (for example, to skip a file that declares something elsewhere in it), so a line-by-line search such as `grep` or `rg` without `-U` is not the same test and can report files the pattern excludes. Do not use `rg --pcre2` either: some patterns have a lookbehind of unbounded length, such as `(?<!\b(?:import|export)\s+(?:type\s+)?\{[^}]*)`, which PCRE2 refuses with "length of lookbehind assertion is not limited". From a shell, run the detection with the skill's script, with Node 24 or later, from the project root. For example, for the `boolean-codec-type-takes-codec-types` change of the `8.0.0-rc.26` to `8.0.0-rc.27` guide:
143
+
144
+ ```sh
145
+ node <skill>/references/scripts/find-detection-hits.ts '**/*.{ts,tsx,mts,cts}' '(?<!\b(?:import|export)\s+(?:type\s+)?\{[^}]*)\bBooleanCodecType\b(?!\s*<)'
146
+ ```
147
+
148
+ After the script's path, give `--all` if the block sets `anyMatch: false`, then the change's `glob`, then each of its `matches` or `regex` entries; if it has `contains` entries, add `--contains` and then each of them. Pass each entry as it reads once decoded from the YAML: in a single-quoted YAML entry, `''` stands for one `'`; in a double-quoted one, `\\` stands for one `\` and `\"` for one `"`, so `"(['\"])x\\1"` decodes to `(['"])x\1`. Put each argument in single quotes, so that the shell does not expand the glob or change the pattern, and write each `'` inside one as `'\''`. So the YAML entry `'[''"]'` becomes the argument `'['\''"]'`. The script prints each file that is a hit, relative to the project root. It skips `node_modules` and `.git`, and does not follow symbolic links; a `**` does not enter a folder whose name starts with a dot, but a glob that names one, such as `.github/workflows/*.yml`, does. Leave out the hits in build output yourself.
130
149
  - If the entry names a `script:` (a relative path next to `instructions.md`), invoke it from the project root:
131
150
  - `*.ts` → the command the guide's prose gives, such as `node <script>` (Node 24 or later runs TypeScript directly); with no command in the prose, `pnpm exec tsx <skill>/upgrading/app/upgrades/<from>-to-<to>/<script>`
132
151
  - `*.sh` → `bash <skill>/upgrading/app/upgrades/<from>-to-<to>/<script>`
@@ -165,7 +184,7 @@ Its version numbers are its own, though they look like the ORM's: `prisma@8.0.0-
165
184
 
166
185
  ## When the chain is done
167
186
 
168
- Report back to the user: the number of steps applied, the SHAs of the commits you made, and any open follow-ups (e.g. tests that were already red before the upgrade and still are). If the chain stopped short of the user's target because no `prisma` version carries a later step, say so, and say which step to re-run from once one is published.
187
+ Run `prisma skills sync`, so the project's copy of the skill matches the release now installed, and commit it if the project tracks it. Report back to the user: the number of steps applied, the SHAs of the commits you made, and any open follow-ups (e.g. tests that were already red before the upgrade and still are). If the chain stopped short of the user's target because no `prisma` version carries a later step, say so, and say which step to re-run from once one is published.
169
188
 
170
189
  ## Failure surfaces
171
190
 
@@ -6,11 +6,22 @@ If the project you are upgrading is a consumer **app** (it depends on a database
6
6
 
7
7
  The per-transition instructions this reference reads live under [`../upgrading/extension/upgrades/`](../upgrading/extension/upgrades/).
8
8
 
9
- ## Step 0 — Upgrade to the newest instructions, then re-read
9
+ ## Step 0 — Read the newest release's skill
10
10
 
11
- The upgrade instructions ship inside the installed Prisma packages, so the copy on disk describes the version currently installed — not the version being upgraded *to*. Bug fixes to *old* per-transition instructions ship with each release as part of the cumulative set, so the newest copy is the one to run.
11
+ The skill in the project describes the release installed now. Each release carries the guide of every earlier step, with the corrections made to it since, such as a fixed script, or an instruction to install a later release in place of a step's own `<to>`. An earlier copy lacks the corrections made after it. So read this reference and every step's guide from the skill of the newest published release, even when the user's target is older, and run the guides' scripts from that copy:
12
12
 
13
- Do the version bump first (step 1 of the per-step flow below), re-sync the skills from the newly installed packages (`prisma skills sync`), and re-read this reference and the per-transition instructions before applying any code translation.
13
+ 1. **Find the newest published release.** Run `pnpm view @prisma/orm-postgres dist-tags.latest dist-tags.next`. The skill ships only in the database packages, such as `@prisma/orm-postgres`, and each carries the same skill, so take it from `@prisma/orm-postgres` whatever database the extension serves. Take the greater of the two versions: `8.0.0-rc.27` is greater than `8.0.0-rc.25`, so compare the numbers after `rc.`, not the text, and `8.0.1` is greater than every `8.0.0-rc.N`.
14
+ 2. **Download its skill.** Unpack that release's package in a new, empty folder outside the project and outside every agent skills folder (`.agents/skills/`, `.claude/skills/`, `.cursor/skills/`, `.windsurf/skills/`), which `prisma skills sync` writes:
15
+
16
+ ```sh
17
+ dir="$(mktemp -d)"
18
+ curl -fsSL "$(pnpm view @prisma/orm-postgres@<newest> dist.tarball)" | tar -xz -C "$dir"
19
+ echo "$dir/package/skills/prisma-8"
20
+ ```
21
+
22
+ The folder it prints is the skill's folder, which this reference and the guides call `<skill>`. If the download fails, stop and tell the user: the upgrade's installs need the same registry.
23
+ 3. **Read from that copy.** Read this reference again from `<skill>/references/upgrade-extension.md`, unless that is the copy you are reading, and follow it from here. Read each step's guide from `<skill>/upgrading/extension/upgrades/<from>-to-<to>/instructions.md`. Where a guide runs a script from the project's skill copy, such as `node .agents/skills/prisma-8/upgrading/...`, run the same path under `<skill>`, still from the project root: `node <skill>/upgrading/...`.
24
+ 4. **Do not sync the skill until the chain is done.** During the upgrade, do not run `prisma skills sync`, and ignore the line a `prisma` command prints when the project's skill copy differs from the installed packages: a sync would bring back the installed release's copy. Sync once, when the chain is done.
14
25
 
15
26
  ## Role detection
16
27
 
@@ -46,7 +57,7 @@ If the from-to delta spans more than one release (e.g. `0.6 → 0.8`), build the
46
57
 
47
58
  The [`../upgrading/extension/upgrades/`](../upgrading/extension/upgrades/) directories name the steps — read the chain off the directory names rather than deriving it arithmetically. Each directory is `<from>-to-<to>`. A step normally spans one stable minor (`0.7-to-0.8`) or one release candidate (`8.0.0-rc.1-to-8.0.0-rc.2`). When intermediate versions were not published, a guide may span a larger hop; follow the available directory chain rather than inventing missing steps. Moving onto the RC line from the last stable minor is a single step of its own (`0.17-to-8.0.0-rc.1`).
48
59
 
49
- Apply each step in order, fully: bump, install, run instructions, check pins, validate, commit — before moving to the next. The one exception is a step that a package with versions of its own, or `prisma`, has no release for; the bump step says when to take steps together. Halt the chain on the first failed step.
60
+ Apply each step in order, fully: bump, install, run instructions, check pins, validate, commit — before moving to the next. The one exception is a step that a package with versions of its own, or `prisma`, has no release for; the bump step says when to take steps together. A step's own guide can also tell you to take it together with a later step; do so, as [Steps taken together](upgrade-app.md#steps-taken-together) describes for an application and the bump step below describes for this flow. Halt the chain on the first failed step.
50
61
 
51
62
  ## Per-step flow
52
63
 
@@ -103,11 +114,17 @@ For each `(from, to)` step in the chain:
103
114
 
104
115
  If it fails, the bump step did not rewrite every entry. Fix the entries it printed and run it again before going on.
105
116
 
106
- 4. **Read the upgrade instructions.** Re-sync the skills (`prisma skills sync`) so the tree matches the version just installed, then load `../upgrading/extension/upgrades/<from>-to-<to>/instructions.md`. Parse the YAML frontmatter and pay particular attention to its `changes[]` array.
117
+ 4. **Read the upgrade instructions.** Load `<skill>/upgrading/extension/upgrades/<from>-to-<to>/instructions.md`, from the newest release's skill ([Step 0](#step-0--read-the-newest-releases-skill)). Parse the YAML frontmatter and pay particular attention to its `changes[]` array.
107
118
 
108
119
  5. **Apply each change.** When the guide's body has a section that orders the steps, such as `Order of the steps`, apply the changes in that order: it says which script runs before which, and when to sign the databases and when to plan and apply a migration. Where an entry's prose says to sign or migrate, do it at the step that section names. Otherwise take the entries in the order of `changes[]`. For each entry in `changes[]`:
109
120
  - If the entry has a `detection` block (a glob + content predicate), run it. If no files match, skip this change. Run the glob over the project's own files: skip `node_modules`, and build output such as `dist`, `build`, `.next` or `out` (whatever directories the project's build writes). A match there is generated code, which the next build rewrites; editing it changes nothing. Migration snapshots under `migrations/snapshots/` are committed files, not build output, so keep them.
110
- - How a `detection` block runs: `glob` selects files relative to the project root. Each `matches` entry, once read from the YAML, is a JavaScript regular expression, built as `new RegExp(pattern)` with no flags and tested against the whole content of one file at a time; each `contains` entry is a plain substring. A file is a hit when any entry matches it. Patterns may span lines, and some look at the whole file (for example, to skip a file that declares something elsewhere in it), so a line-by-line search such as `grep` or `rg` without `-U` is not the same test and can report files the pattern excludes. From a shell, `rg -U --pcre2 -l -e '<pattern>' <files>` tests whole files and gives the same hits.
121
+ - How a `detection` block runs: `glob` selects files relative to the project root. Each `matches` entry, once read from the YAML, is a JavaScript regular expression, built as `new RegExp(pattern)` with no flags and tested against the whole content of one file at a time; some older guides call these entries `regex`, which means the same. Each `contains` entry is a plain substring. A file is a hit when any entry matches it, or, when the block sets `anyMatch: false`, only when every entry matches it; `anyMatch: true` changes nothing. Patterns may span lines, and some look at the whole file (for example, to skip a file that declares something elsewhere in it), so a line-by-line search such as `grep` or `rg` without `-U` is not the same test and can report files the pattern excludes. Do not use `rg --pcre2` either: some patterns have a lookbehind of unbounded length, such as `(?<!\b(?:import|export)\s+(?:type\s+)?\{[^}]*)`, which PCRE2 refuses with "length of lookbehind assertion is not limited". From a shell, run the detection with the skill's script, with Node 24 or later, from the project root. For example, for the `boolean-codec-type-takes-codec-types` change of the `8.0.0-rc.26` to `8.0.0-rc.27` guide:
122
+
123
+ ```sh
124
+ node <skill>/references/scripts/find-detection-hits.ts '**/*.{ts,tsx,mts,cts}' '(?<!\b(?:import|export)\s+(?:type\s+)?\{[^}]*)\bBooleanCodecType\b(?!\s*<)'
125
+ ```
126
+
127
+ After the script's path, give `--all` if the block sets `anyMatch: false`, then the change's `glob`, then each of its `matches` or `regex` entries; if it has `contains` entries, add `--contains` and then each of them. Pass each entry as it reads once decoded from the YAML: in a single-quoted YAML entry, `''` stands for one `'`; in a double-quoted one, `\\` stands for one `\` and `\"` for one `"`, so `"(['\"])x\\1"` decodes to `(['"])x\1`. Put each argument in single quotes, so that the shell does not expand the glob or change the pattern, and write each `'` inside one as `'\''`. So the YAML entry `'[''"]'` becomes the argument `'['\''"]'`. The script prints each file that is a hit, relative to the project root. It skips `node_modules` and `.git`, and does not follow symbolic links; a `**` does not enter a folder whose name starts with a dot, but a glob that names one, such as `.github/workflows/*.yml`, does. Leave out the hits in build output yourself.
111
128
  - If the entry has no `detection`, apply unconditionally.
112
129
  - If the entry names a `script:` (a relative path next to `instructions.md`), invoke it from the project root:
113
130
  - `*.ts` → the command the guide's prose gives, such as `node <script>` (Node 24 or later runs TypeScript directly); with no command in the prose, `pnpm exec tsx <skill>/upgrading/extension/upgrades/<from>-to-<to>/<script>`
@@ -166,7 +183,7 @@ The convention has two costs. A feature of yours that needs no newer Prisma rele
166
183
 
167
184
  ## When the chain is done
168
185
 
169
- Report back to the user: the number of steps applied, the SHAs of the commits you made, and any open follow-ups. If the overrides for `prisma` are in place, say so: do not publish a release built with them. Once a `prisma` version that fits is published, move `prisma` to it, remove the overrides, and install and validate again.
186
+ Run `prisma skills sync`, so the project's copy of the skill matches the release now installed, and commit it if the project tracks it. Report back to the user: the number of steps applied, the SHAs of the commits you made, and any open follow-ups. If the overrides for `prisma` are in place, say so: do not publish a release built with them. Once a `prisma` version that fits is published, move `prisma` to it, remove the overrides, and install and validate again.
170
187
 
171
188
  ## Failure surfaces
172
189
 
@@ -400,13 +400,15 @@ This release changes every hash Prisma stores, moves Prisma's own tables, and re
400
400
  Do the steps in this order, and skip a step that does not apply to the project:
401
401
 
402
402
  1. Before you upgrade, write down every database the project uses, as `contract-hash-inputs` says in its step 1 under "Which databases this means". Then, with the release you are on now, deploy every pending migration, the application's and every extension's, to each of them (`contract-hash-inputs`, its step 1). On PostgreSQL, check that every database runs PostgreSQL 15 or later (`postgres-signing-refuses-servers-older-than-15`). Tell the user that every service, deploy script and pipeline that runs a `prisma` command against a database must move to this release at the same time (`prisma-tables-move-to-prisma-schema` on PostgreSQL, `sqlite-prisma-tables-renamed` on SQLite). If the contract declares a namespace `prisma` or `prisma_contract`, settle its new name with the user before anything else (`rename-a-namespace-named-prisma`). Check every database for what would stop the move of Prisma's own tables in the deploy, with the read-only queries `prisma-tables-move-to-prisma-schema` gives under "Check each database before the deploy", and fix what they find. If an extension the project uses has no release for `8.0.0-rc.26`, such as `@prisma/orm-extension-paradedb`, stop and tell the user: the project cannot upgrade until the extension publishes one. On MongoDB, if a relation or a member of a composite type or value object is named `__proto__`, rename it and move its values with the release you are on (`mongo-proto-field-and-relation-names-refused`), so the upgrade carries no change of its own to what is stored.
403
- 2. Upgrade Prisma in a release of the application that carries no new migration of its own. Move `prisma`, the package that provides the `prisma` command, to the version whose `@prisma/orm-toolchain` dependency is exactly the ORM version this step installs, and write that version exactly, as [Choosing the `prisma` version](../../../../references/upgrade-app.md#choosing-the-prisma-version) describes. Read its dependencies, not its own number: `prisma` `8.0.0-rc.37` depends on `@prisma/orm-toolchain` `8.0.0-rc.26`, so it runs with `8.0.0-rc.26` and not with `8.0.0-rc.27`. `prisma` `8.0.0-rc.36` runs the toolchain of `8.0.0-rc.25`, but loads this release's database package through the project's config. The old toolchain passes this release's contract reader a contract with no format version it recognises, and reports the reader's `CONTRACT.FORMAT_VERSION_MISSING` error under its own code. So once the guide's scripts have upgraded the project, its commands fail with `CONTRACT.VALIDATION_FAILED` and "The contract file has no format version". If a `prisma` command fails that way, the `prisma` the project runs is still an earlier one: choose its version again as above and install. Before you run the install, fix `package.json`: list the platform packages beside the database package (`list-the-platform-packages`), and change the config to import `prisma/config` and remove the `@prisma/cli-engine` line where its section says so (`config-imports-prisma-config`). Put each other required peer dependency, such as `temporal-polyfill`, `pg` and `@types/pg`, where `list-the-platform-packages` says. Then move every `@prisma/orm-*` package, and each extension released with the ORM, to `8.0.0-rc.26` and install. This is the only step that upgrades the extensions. If `8.0.0-rc.27` or later is published, take this step together with the steps up to it, as [Steps taken together](../../../../references/upgrade-app.md#steps-taken-together) describes, and install that release here instead: its `prisma contract emit` brings the application's snapshot of the emitted contract up to date, which `8.0.0-rc.26`'s does not (`contract-hash-inputs`, under "A database created during or after the deploy").
403
+ 2. Upgrade Prisma in a release of the application that carries no new migration of its own. Move `prisma`, the package that provides the `prisma` command, to the version whose `@prisma/orm-toolchain` dependency is exactly the ORM version this step installs, and write that version exactly, as [Choosing the `prisma` version](../../../../references/upgrade-app.md#choosing-the-prisma-version) describes. Read its dependencies, not its own number: `prisma` `8.0.0-rc.37` depends on `@prisma/orm-toolchain` `8.0.0-rc.26`, so it runs with `8.0.0-rc.26` and not with `8.0.0-rc.27`. `prisma` `8.0.0-rc.36` runs the toolchain of `8.0.0-rc.25`, but loads this release's database package through the project's config. The old toolchain passes this release's contract reader a contract with no format version it recognises, and reports the reader's `CONTRACT.FORMAT_VERSION_MISSING` error under its own code. So once the guide's scripts have upgraded the project, its commands fail with `CONTRACT.VALIDATION_FAILED` and "The contract file has no format version". If a `prisma` command fails that way, the `prisma` the project runs is still an earlier one: choose its version again as above and install. Before you run the install, fix `package.json`: list the platform packages beside the database package (`list-the-platform-packages`), and change the config to import `prisma/config` and remove the `@prisma/cli-engine` line where its section says so (`config-imports-prisma-config`). Put each other required peer dependency, such as `temporal-polyfill`, `pg` and `@types/pg`, where `list-the-platform-packages` says. Then move every `@prisma/orm-*` package, and each extension released with the ORM, to `8.0.0-rc.26` and install. This is the only step that upgrades the extensions. If `8.0.0-rc.27` or later is published, take this step together with the steps up to it, as [Steps taken together](../../../../references/upgrade-app.md#steps-taken-together) describes, and install that release here instead, with the `prisma` version that fits it: its `prisma contract emit` brings the application's snapshot of the emitted contract up to date, which `8.0.0-rc.26`'s does not (`contract-hash-inputs`, under "A database created during or after the deploy").
404
404
  3. Run the three scripts that rewrite import paths and names, in this order, and make the changes by hand that each one lists: `facade-paths-an-application-uses`, then `platform-paths-an-extension-uses`, then `contract-signature-names` (`contract-signature-flag` and the entries after it). Each later script reads what the earlier one wrote. Then change any value imported from a database package's `contract-types` (`contract-types-exports-types-only`). A type check at this step finds the imports to fix (`TS2307`, `TS2305`, `TS1361`, `TS1362`). Until step 5 emits the contract, `contract.d.ts` still has the old shape, so code that uses the client can report errors that do not name the contract. Besides errors that name the contract's `capabilities` or `requiredCapabilities`, expect, for example, `TS2349` "This expression is not callable" on a method that a capability enables, such as `.returning()`, `TS2339` "Property 'title' does not exist on type '{}'" on the row such a query returns, `TS2769` "No overload matches this call" on `.distinctOn()`, and `TS2345` on a `transaction` callback, whose message says the contract declares no dependency on `conn.interactiveTransactions`. Do not fix these by hand. Type-check again after step 5's `prisma contract emit`, and fix only what is left then. Some of that is for step 6, such as `TS2339` for `fragment` on the ORM client (`fragment-on-the-client`).
405
405
  4. Change the code that reads a contract's capabilities (`code-reads-required-capabilities`, `required-capabilities-as-list`, `postgres-hand-built-contract-lists-capabilities`, `postgres-capability-flags-removed`, `postgres-capability-exports-moved`). On PostgreSQL, write the list of capabilities the contract requires where the contract is written (`postgres-contract-lists-required-capabilities`, `postgres-config-without-define-config-passes-capabilities`, `postgres-transaction-needs-interactive-transactions`). Do not run `prisma contract emit` yet.
406
406
  5. Bring the stored files up to date: run the `stored-files-format-version` script, then the `contract-hash-inputs` script, then run `prisma contract emit` once, as `contract-hash-inputs` says in its steps 2 and 4 (step 2 of this order already upgraded the extensions, which is its step 3). That one emit also covers `stored-contract-needs-the-upgrade-script`, `stored-required-capabilities-as-list` and `postgres-emitted-contract-is-emitted-again`. Run each of the two scripts once per Prisma project folder, giving it the folder, as `contract-hash-inputs` says in its step 2. Commit the result. If the emitted contract's storage hash differs from the one the script printed, plan the one migration `contract-hash-inputs` describes in its step 4. From here on, do not run a planned `migration.ts` again (`contract-hash-inputs`, under "Do not run a planned `migration.ts` again").
407
407
  6. Change the rest of the application code: `fragment()` on the client (`fragment-on-the-client`), `fns` comparisons (`orm-fns-comparison-takes-field-input-type`), `updateAll` and `updateAndCount` with a type argument (`update-all-explicit-type-argument`), SQL builder joins (`sql-builder-shared-join-column-name-needs-table`), list columns in the PostgreSQL SQL builder (`sql-builder-list-column-in-a-one-value-position`), code generic over a prepared declaration (`prepared-declaration-param-spec-can-be-a-list`), tests that count the SQL statements a call sends (see the paragraph below), a check of `char(n)[]` values written with 8.0.0-rc.25 (`postgres-char-bit-list-values-check`), sets of values that may grow (`app-middleware-handles-later-activities`, `app-switches-over-later-values`, `app-geometry-may-gain-types`), the console logger (`default-logger-console`), and code that caught the signature read errors (`runtime-signature-check-only-warns`). On MongoDB, read what the planner now does with a changed stored name before you plan any migration (`mongo-stored-name-change-is-a-rename` and the entries after it). Then type-check and test the application.
408
408
 
409
409
  On PostgreSQL and SQLite, `deleteAll()` and `updateAll()` with more than one `.where()` call send one statement again, a `DELETE … RETURNING` or an `UPDATE … RETURNING`, as `8.0.0-rc.23` did. `8.0.0-rc.24` and `8.0.0-rc.25` sent a `SELECT` of the matching rows first and then the write, so a call could return a row that another connection had changed or deleted in between. A test that counts the statements such a call sends now sees one fewer for each such call: lower its expected count by one. On MySQL the statements do not change.
410
+
411
+ On PostgreSQL, when the driver takes a connection from its pool that was last used a second or more ago, it first checks that the connection still answers, and replaces it if it does not, for example because the server closed it ([prisma/orm#31229](https://github.com/prisma/orm/pull/31229)). Nothing needs to change. An application that checks for dead pooled connections itself, such as with a `SELECT 1` before each use, may remove that check for the queries Prisma runs; tell the user rather than removing it unasked. Keep it where the application calls `pool.query()` or `pool.connect()` directly on the pool it gave Prisma: the driver does not check those connections. A Prisma client built on a single `pg.Client`, or on the serverless entry, sends no such check: it has one connection and nothing to swap to.
410
412
  7. Change the project's own text that names Prisma's tables or the old commands: SQL, scripts, grants, tests and docs that name `prisma_contract`, the `marker` table, `_prisma_marker` or `_prisma_ledger` (`name-the-prisma-schema`, `marker-table-is-signatures`, `sqlite-prisma-tables-renamed`), CI commands that run `db init` or `db update` (`db-init-db-update-ref-rule`), and scripts that pass a contract argument or match on its error codes, or resolve one through the control API (`contract-argument-one-parser`, `control-api-ref-resolution-takes-migration-dir`). Do not edit planned migrations by hand. The scripts of steps 3 and 5 change `migration.ts` files, which is expected (`facade-paths-an-application-uses`, `contract-hash-inputs`).
411
413
  8. Where the project has a staging database set up like production, with the same roles, deploy the upgrade there first, as below. That run moves the staging database's tables for good: from then on, every tool that changes the staging database must be on this release or a later one, as `prisma-tables-move-to-prisma-schema` says for every database. Then deploy. Against every database that existed before the deploy, run `prisma db sign --no-advance-ref` and then `prisma db migrate`, as `contract-hash-inputs` says in its step 5, which gives a form of the first command that signs only a database that still needs it, and, for a deploy that does not sign, the order to follow when CI deploys on every merge. The same step lists two CI changes the upgrade's pull request may need: an exception for a check that runs `migration.ts` files, and making read-only checks against shared databases non-blocking during the switch. That first command also moves Prisma's own tables (`prisma-tables-move-to-prisma-schema`, `sqlite-prisma-tables-renamed`); if it stops, its section says why and what to do. On PostgreSQL, right after it and before the application on the new release runs, grant a role other than the one that ran the command `SELECT` on `prisma.signatures`, and on `prisma.config` where the role runs Prisma's commands (`name-the-prisma-schema`).
412
414
 
@@ -511,7 +513,7 @@ This guide's script rewrites each import of a removed path. Files Prisma generat
511
513
 
512
514
  #### Where the guide and its script are
513
515
 
514
- This guide is part of the `prisma-8` skill. The skill ships inside the database package; after you install the new version, `prisma skills sync` copies it into the agent skills folder of each harness the project uses: `.agents/skills/prisma-8/`, `.claude/skills/prisma-8/`, `.cursor/skills/prisma-8/` or `.windsurf/skills/prisma-8/`. Any one of these copies will do. The script sits beside this guide in that copy, for example:
516
+ This guide is part of the `prisma-8` skill. Read it, and run its scripts, from the skill of the newest published release, which [Step 0 of the upgrade reference](../../../../references/upgrade-app.md#step-0--read-the-newest-releases-skill) unpacks in a folder outside the project. The commands in this guide name the copy that `prisma skills sync` writes into the project, `.agents/skills/prisma-8/` (or `.claude/skills/prisma-8/`, `.cursor/skills/prisma-8/` or `.windsurf/skills/prisma-8/`); put the newest release's folder in its place. The script sits beside this guide in that copy, for example:
515
517
 
516
518
  ```text
517
519
  .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts
@@ -803,8 +805,8 @@ node .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/s
803
805
 
804
806
  As with the other script, run it from the skills copy, not from `node_modules`, with Node.js 24 or later. It reads each file with the project's own TypeScript compiler, so run it in a project whose `typescript` package is installed; if it finds none, it says so and stops without changing any file. It needs TypeScript 5 or 6: the `typescript` package of TypeScript 7 has no compiler API that a script can call. The script tries the project's `typescript` first, then one installed beside the script, and uses the first that has a compiler API. If neither has one, it changes no file, says that it needs TypeScript 5 or 6, and exits with code 1. Then do one of the two things its message offers:
805
807
 
806
- - Install TypeScript 5 in the project for the run, for example with `pnpm add -D typescript@5` (add `-w` at the root of a pnpm workspace), run the script, and put the project's own TypeScript version back afterwards.
807
- - Install `typescript@5` in an empty folder, copy the script's `.ts` file into that folder, and run the copy with the project folder as its argument: `node <folder>/<script>.ts <project folder>`.
808
+ - Leave the project unchanged: make an empty folder outside the project, write a `package.json` in it that holds `{"type": "module"}`, run `pnpm add typescript@5` in that folder, copy the script's `.ts` file into it, and run the copy with the project folder as its argument: `node <folder>/<script>.ts <project folder>`. Without that `package.json`, Node prints a `MODULE_TYPELESS_PACKAGE_JSON` warning, which is harmless.
809
+ - Install TypeScript 5 in the project for the run: `pnpm add -D typescript@5`, with `-w` added at the root of a pnpm workspace. This changes `package.json` and the lockfile, so after the run put back the `typescript` version you had, with `pnpm add -D typescript@<your version>` (with `-w` again where you used it), or `pnpm remove typescript` if the project had none; do not use `git checkout` on those files, which would also undo the other uncommitted changes the upgrade made to them.
808
810
 
809
811
  If the script fails on an error it did not expect, it says "The script failed on an unexpected error, before it changed any file. This is a fault in the script; report it to Prisma with this output", prints the stack trace, and exits with code 1.
810
812
 
@@ -1429,7 +1431,7 @@ node .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/s
1429
1431
 
1430
1432
  Do not give it a folder that holds more than Prisma projects, such as the root of a monorepo whose projects are in packages: it would also reach files that look like Prisma's but are not, such as test fixtures copied from another project. If one of them cannot be read as Prisma's, the script changes no file at all and exits with code 1. The script takes one argument at most, the folder, and no option; given more, it prints its usage line and exits with code 1.
1431
1433
 
1432
- The path names the copy of the `prisma-8` skill in `.agents/skills/`. Where the project has no `.agents` folder, use the copy in the agent's own skills folder instead: `.claude/skills/`, `.cursor/skills/` or `.windsurf/skills/`.
1434
+ The path names the copy of the `prisma-8` skill in `.agents/skills/`. Put the folder of the newest release's skill in its place, as [Step 0 of the upgrade reference](../../../../references/upgrade-app.md#step-0--read-the-newest-releases-skill) says.
1433
1435
 
1434
1436
  Node 24 or later runs the TypeScript script directly; it needs no `tsx`. It reads and writes files only and needs no database. It walks the folder you gave it, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot, and, in a git repository, the files and folders git ignores other than a migrations folder and what is in it, and:
1435
1437
 
@@ -1489,11 +1491,11 @@ node .agents/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/s
1489
1491
 
1490
1492
  Do not give it a folder that holds more than Prisma projects, such as the root of a monorepo whose projects are in packages. The script checks every stored file below the folder before it changes anything. A hand-written `migration.json` whose `migrationHash` does not match its migration, or a snapshot with hashes no release wrote, such as in a test fixture written to look like another project, makes it change no file at all and exit with code 1. The script takes one argument at most, the folder, and no option; given more, it prints its usage line and exits with code 1. It skips a file git ignores, such as an emitted `contract.json` the project does not commit; the `prisma contract emit` of step 4 writes that file again.
1491
1493
 
1492
- The path names the copy of the `prisma-8` skill in `.agents/skills/`. Where the project has no `.agents` folder, use the copy in the agent's own skills folder instead: `.claude/skills/`, `.cursor/skills/` or `.windsurf/skills/`.
1494
+ The path names the copy of the `prisma-8` skill in `.agents/skills/`. Put the folder of the newest release's skill in its place, as [Step 0 of the upgrade reference](../../../../references/upgrade-app.md#step-0--read-the-newest-releases-skill) says.
1493
1495
 
1494
1496
  Node 24 or later runs the TypeScript script directly. It reads and writes files only and needs no database. It walks the folder you gave it, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot, and, in a git repository, the files and folders git ignores other than a migrations folder and what is in it, and finds the same files the format version script does: every contract (any `*.json` file with `targetFamily` and `storage`, so the emitted `contract.json` and each snapshot), every `migration.json` with an `ops.json` beside it, and every ref file.
1495
1497
 
1496
- First it checks every contract: each stored hash, and each snapshot directory's name, must be the hash the old rules or the new rules give the contract's content. A storage hash that matches neither means the file was edited by hand or comes from another release. The script then changes no file, names each such file, and exits 1. The one exception is a contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture: the script leaves that file alone, prints the hashes its content gives, still upgrades the rest of the project, and exits 1. Restore the file from version control, or emit it again if it is the emitted contract (`prisma contract emit` rewrites only the head snapshot of each extension, not the application's snapshots), and run the script again. It does the same for a `migration.json` whose `migrationHash` does not match the migration. Two kinds of snapshot are accepted although a stored hash does not match. An earlier release may have written a snapshot's profile or execution hash by other rules, and no version of the file has the right one; `prisma db sign <contract reference>` copies a snapshot's profile hash into the database's contract signature, so the script gives such a snapshot the hashes its content gives, before any database is signed, and lists it. And the upgrade steps that renamed MongoDB indexes and field storage names rewrote snapshots in place and kept their storage hashes, because contract signatures, the ledger and migrations name a snapshot by its hash; such a MongoDB snapshot, whose directory name and stored hash agree, takes the new hash of its content, every file that names it follows, and the script lists it.
1498
+ First it checks every contract: each stored hash, and each snapshot directory's name, must be the hash the old rules or the new rules give the contract's content. A storage hash that matches neither means the file was edited by hand or comes from another release. The script then changes no file, names each such file, and exits 1. The one exception is a contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture: the script leaves that file alone, prints the hashes its content gives, still upgrades the rest of the project, and exits 1. Restore the file from version control, or emit it again if it is the emitted contract (`prisma contract emit` rewrites only the head snapshot of each extension, not the application's snapshots), and run the script again. It does the same for a `migration.json` whose `migrationHash` does not match the migration. An intermediate contract beside a migration's `migration.ts` is left alone the same way, but does not make the script exit 1 and is not to be restored or emitted, as "An intermediate contract" below says. Two kinds of snapshot are accepted although a stored hash does not match. An earlier release may have written a snapshot's profile or execution hash by other rules, and no version of the file has the right one; `prisma db sign <contract reference>` copies a snapshot's profile hash into the database's contract signature, so the script gives such a snapshot the hashes its content gives, before any database is signed, and lists it. And the upgrade steps that renamed MongoDB indexes and field storage names rewrote snapshots in place and kept their storage hashes, because contract signatures, the ledger and migrations name a snapshot by its hash; such a MongoDB snapshot, whose directory name and stored hash agree, takes the new hash of its content, every file that names it follows, and the script lists it.
1497
1499
 
1498
1500
  Then it computes each contract's new hashes and rewrites, keeping every other byte of each file:
1499
1501
 
@@ -1515,11 +1517,13 @@ The script exits 1 without changing that file when it cannot finish one:
1515
1517
  - A `migration.json` or ref file names a storage hash that no contract or snapshot in the project has, so the script cannot tell its new value. Prisma copies an extension's migrations into `migrations/<extension>/`, without a snapshot of every contract in between. For a migration there, delete its folder: after you upgrade the extension, `prisma contract emit` writes it again from the extension's new version, with the new hashes, and the script accepts it from then on, because those migrations lead to the extension's head, which already has its new hash. Restore anything else from version control, or set a ref again with `prisma migration ref set` after the upgrade.
1516
1518
 
1517
1519
  This happens in many projects that use an extension, such as pgvector, whose earlier releases shipped migrations the project's snapshots do not cover. The run has then rewritten every other file, often hundreds, and exits with code 1 although it did its work. That exit is expected: delete the folders it names, as above, and go on to step 3 and step 4, whose `prisma contract emit` writes them again.
1518
- - An intermediate contract is a contract emitted into a migration's directory, such as `intermediate.json`, that its `migration.ts` imports to type the queries of a data migration against a state between its two contracts. When its stored hashes are the ones the earlier release gave its content, the script rewrites it like any other contract. When they are not, for example because a release before 8.0.0-rc.25 emitted it, or it was edited by hand, nothing names its storage hash, so the script leaves it alone, prints the hashes its content gives, and exits with code 1, as for a test fixture below. Leave such a file as it is, and do not set its hashes. It keeps its old `capabilities`, so running that `migration.ts` again would fail with `CONTRACT.VALIDATION_FAILED`. The file is read only when that `migration.ts` runs, and after this upgrade you do not run it again (see "Do not run a planned `migration.ts` again" below). That exit 1 is expected; the rest of the project is upgraded.
1519
1520
  - A contract file that is not a snapshot, and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture, has a hash its content does not give. The script leaves it alone and prints the hashes its content gives; set them, or emit it again if Prisma writes it. The rest of the project is still upgraded.
1520
1521
  - A `contract.json` has neither `formatVersion` nor `schemaVersion`, so no release of Prisma wrote it. The script leaves it alone.
1521
1522
  - A `contract.d.ts` names a hash that is not one of its contract's. Emit the contract again with `prisma contract emit` (or, for a snapshot, restore both files from version control) and run the script again.
1522
1523
  - A contract's capabilities cannot be renamed: two old keys become one key with different values (such as `sql.distinctOn: false` beside `postgres.distinctOn: true`, which both become `db.distinctOn`), the file has both `capabilities` and `requiredCapabilities`, `requiredCapabilities` is neither a list of strings nor an object, or a `sql` or `postgres` namespace of `capabilities`, or a provider of a grouped `requiredCapabilities`, is not an object. The script changes no file and names the contract and the reason. Emit the contract again with `prisma contract emit` if Prisma writes it, or fix the file by hand (for a snapshot, keep one value per key and one of the two fields), and run the script again.
1524
+ - A contract's `execution.mutations.defaults` refs still have the keys `table` and `column`, which 8.0.0-rc.13 renamed to `entry` and `field`. When the contract is a snapshot, or a migration, ref or snapshot names its storage hash, the script changes no file, exits 1, and names the contract and its refs under "Changed no file, because:". For such a contract under a `migrations` folder, run the command the message gives from the project root. It runs the script of the 8.0.0-rc.12 to 8.0.0-rc.13 step `execution-ref-entry-field` from the same skill copy, which renames the keys in every contract under `migrations/`: `node <skill>/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts`, where `<skill>` is the folder of the `prisma-8` skill copy, such as `.agents/skills/prisma-8`. For any other such contract, emit it again with `prisma contract emit`, as that step says. Then run this script again. A contract with such refs that nothing names, and that is not a snapshot, does not stop the run: an intermediate contract is listed as one, as below, and any other, such as a hand-made test fixture, is listed under "Left unchanged:" and makes the script exit 1. Emit that one again if Prisma writes it, or rename the keys by hand.
1525
+
1526
+ An intermediate contract is a contract emitted into a migration's directory, such as `intermediate.json`, that its `migration.ts` imports to type the queries of a data migration against a state between its two contracts. When its stored hashes are the ones the earlier release gave its content, the script rewrites it like any other contract. When they are not, for example because a release before 8.0.0-rc.25 emitted it, or it was edited by hand, or when its execution default refs still have the keys from before 8.0.0-rc.13, the script leaves it alone and lists it last, under "Intermediate contracts, left as they are". Such a file does not make the script exit with code 1: when it is all that is left, the script exits with code 0, and a second run lists it again and still exits with code 0. Leave such a file as it is, and do not set its hashes. It keeps its old `capabilities`, so running that `migration.ts` again would fail with `CONTRACT.VALIDATION_FAILED`. The file is read only when that `migration.ts` runs, and after this upgrade you do not run it again (see "Do not run a planned `migration.ts` again" below). The script takes a contract for an intermediate one only when its directory also holds the migration's `migration.json`, `ops.json` and `migration.ts`. A contract with wrong hashes elsewhere, whose storage hash nothing names, is listed under "Left unchanged:" as in the list above, and makes the script exit with code 1. A contract with wrong hashes whose storage hash a migration, ref or snapshot names, in a migration's directory or not, stops the run as described above.
1523
1527
 
1524
1528
  #### 3. Upgrade every extension with Prisma
1525
1529
 
@@ -1673,7 +1677,7 @@ prisma db migrate
1673
1677
 
1674
1678
  Add `--force` to the first line where the change policy permits only migrations. `db sign` takes the directory name of a migration as its contract and signs the contract that migration leads to; `db migrate` then applies the migrations after it. Give its name, for example `prisma db sign --no-advance-ref 20261128T0807_add_post_meta`. A path to the directory, such as `migrations/app/20261128T0807_add_post_meta`, works too (`contract-argument-one-parser`).
1675
1679
 
1676
- The directory must be that of the migration that brought the database to the contract it is at, usually the last one it applied. On PostgreSQL, a database a release candidate set up keeps Prisma's own tables in the schema `prisma_contract`, and until a command that changes the database has moved them to `prisma` (see `prisma-tables-move-to-prisma-schema`), `migration status` and `migration log` stop with `CONTRACT.PRISMA_SPACE_BEHIND`. Run `prisma db migrate` once first: it moves Prisma's tables, then stops with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` and changes nothing else. That error's advice does not apply here; follow this route. To find the directory, run two commands against the database:
1680
+ The directory must be that of the migration that brought the database to the contract it is at, usually the last one it applied. On PostgreSQL, a database a release candidate set up keeps Prisma's own tables in the schema `prisma_contract`, and until a command that changes the database has moved them to `prisma` (see `prisma-tables-move-to-prisma-schema`), `migration status` and `migration log` stop with `CONTRACT.PRISMA_SPACE_BEHIND`. Run `prisma db migrate` once first: it moves Prisma's tables, then stops with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` and changes nothing else. From `8.0.0-rc.28`, when the database's ledger shows that an earlier release migrated it, that error says so and points to this step; it prints no command. Whatever that error advises, sign the database as this section says. To find the directory, run two commands against the database:
1677
1681
 
1678
1682
  - `prisma migration status` warns "The database's contract signature <hash> is not in the on-disk migration graph". That hash, shortened, is the contract the database is at, under the old hash rules.
1679
1683
  - `prisma migration log` lists the migrations the database applied, oldest first, each with its directory name and the contracts it moved the database from and to, under the old hashes and shortened to their first 7 characters. It shows a Space column only when more than one space has run migrations on the database; without it, every row is the application's. Take the directory of the last application row whose second hash is the first 7 characters of the signature's.
@@ -1690,7 +1694,7 @@ The route does not apply when an extension's migrations are pending on the datab
1690
1694
 
1691
1695
  The database stays usable, but the commands that compare it with the project see a contract they do not know:
1692
1696
 
1693
- - `prisma db migrate` stops before it applies any migration, with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` (on PostgreSQL it has first moved Prisma's own tables, as `prisma-tables-move-to-prisma-schema` describes): "The database is at a contract that is not in the migration graph". Its advice does not apply here; sign the database as this step says.
1697
+ - `prisma db migrate` stops before it applies any migration, with `MIGRATION.SIGNATURE_NOT_IN_GRAPH` (on PostgreSQL it has first moved Prisma's own tables, as `prisma-tables-move-to-prisma-schema` describes): "The database is at a contract that is not in the migration graph". From `8.0.0-rc.28`, when the ledger shows an earlier release migrated the database, the error says so and points to this step. Whatever it advises, such as `prisma db update`, authoring migrations or installing a version of an extension, sign the database as this step says.
1694
1698
  - `prisma migration status` warns with `MIGRATION.SIGNATURE_NOT_IN_GRAPH`: "Database was updated outside the migration system".
1695
1699
  - `prisma db verify` fails with `CONTRACT.SIGNATURE_MISMATCH`: "The database is signed with a different contract".
1696
1700
  - At runtime, queries still run. A SQL client logs one `CONTRACT.SIGNATURE_MISMATCH` warning, to the console unless the application passes its own `log` (`default-logger-console`); a MongoDB client does not check the signature.
@@ -12,7 +12,9 @@
12
12
  *
13
13
  * It reads a stored file whether or not it has a `formatVersion`, and leaves its format version as it is: a file a release candidate wrote keeps `"schemaVersion": "1"`, or no version field, and this release reads it as format version 0.
14
14
  *
15
- * A contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture, does not stop the upgrade when its hashes are wrong: it is reported, left unchanged, and makes the script exit 1.
15
+ * A contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture, does not stop the upgrade when its hashes are wrong: it is reported, left unchanged, and makes the script exit 1. An intermediate contract, one in a migration's directory beside its `migration.ts`, which reads it to type a data migration's queries, is the exception: when its hashes are wrong it is listed as an intermediate contract and left unchanged, and the script still exits 0, since that `migration.ts` is not run again after this upgrade.
16
+ *
17
+ * A contract whose `execution.mutations.defaults` refs still have the keys `table` and `column`, which 8.0.0-rc.13 renamed to `entry` and `field`, stops the run when it is a snapshot or something names its storage hash: the script changes no file and gives the command of the 8.0.0-rc.12 to 8.0.0-rc.13 step that renames them. Such a contract that nothing names is left alone like one with wrong hashes: an intermediate contract is listed as one, and any other is reported and makes the script exit 1.
16
18
  *
17
19
  * Otherwise it rewrites: the three hashes in every contract; the same hashes in the `contract.d.ts` beside it; each snapshot directory's name; `from`, `to` and `migrationHash` in every `migration.json`, and the storage hashes in the `ops.json` beside it; `hash` in every ref file; and every old storage hash in every `migration.ts` (snapshot import paths and hash literals). It edits each file's text, so every other byte stays, including a leading byte order mark, and replaces each file in one rename, so a run that stops partway can be run again to finish. It prints what it changed and each hash it replaced. A `contract.d.ts` whose hashes it cannot match with its contract, or a migration or ref naming a hash it cannot tell the new value of, is reported, left unchanged, and makes it exit 1. A second run changes nothing.
18
20
  *
@@ -32,7 +34,8 @@ import {
32
34
  statSync,
33
35
  writeFileSync,
34
36
  } from 'node:fs';
35
- import { basename, dirname, join, relative, resolve, sep } from 'node:path';
37
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
38
+ import { fileURLToPath } from 'node:url';
36
39
 
37
40
  type Json = null | boolean | number | string | Json[] | JsonRecord;
38
41
  interface JsonRecord {
@@ -1481,20 +1484,81 @@ function hashList(hashes: HashSet): string {
1481
1484
  }
1482
1485
 
1483
1486
  interface ContractChecks {
1487
+ /** The project root the script upgrades. */
1488
+ readonly root: string;
1484
1489
  readonly stops: string[];
1485
1490
  /** Contracts the script leaves unchanged and reports, without refusing the project. */
1486
1491
  readonly left: string[];
1487
1492
  /** Snapshots whose profile or execution hash an earlier release wrote by other rules. */
1488
1493
  readonly notes: string[];
1494
+ /** Stale intermediate contracts the script leaves unchanged without counting them as problems. */
1495
+ readonly intermediate: string[];
1489
1496
  /** Every storage hash a migration, ref or snapshot names. */
1490
1497
  readonly named: ReadonlySet<string>;
1491
1498
  }
1492
1499
 
1500
+ function oldExecutionRefs(value: JsonRecord): readonly string[] {
1501
+ const execution = value['execution'];
1502
+ const mutations = isRecord(execution) ? execution['mutations'] : undefined;
1503
+ const defaults = isRecord(mutations) ? mutations['defaults'] : undefined;
1504
+ if (!Array.isArray(defaults)) return [];
1505
+ return defaults.flatMap((entry) => {
1506
+ const ref = isRecord(entry) ? entry['ref'] : undefined;
1507
+ if (!isRecord(ref) || !('table' in ref || 'column' in ref)) return [];
1508
+ return [`${String(ref['table'])}.${String(ref['column'])}`];
1509
+ });
1510
+ }
1511
+
1512
+ function isIntermediateContract(path: string): boolean {
1513
+ const dir = dirname(path);
1514
+ return isMigrationPackage(dir) && existsSync(join(dir, 'migration.ts'));
1515
+ }
1516
+
1517
+ /** The `node` command that runs the 8.0.0-rc.12 to 8.0.0-rc.13 script of this skill copy from `root`: relative to `root` when the copy is inside it. */
1518
+ function renameExecutionRefKeysCommand(root: string): string {
1519
+ const upgrades = resolve(dirname(fileURLToPath(import.meta.url)), '../../..');
1520
+ const script = join(
1521
+ upgrades,
1522
+ '8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts',
1523
+ );
1524
+ const fromRoot = relative(realpathSync(root), script);
1525
+ const path = fromRoot.startsWith('..') || isAbsolute(fromRoot) ? script : fromRoot;
1526
+ return `node ${path.split(sep).join('/')}`;
1527
+ }
1528
+
1529
+ function planOldExecutionRefs(
1530
+ file: StoredText,
1531
+ shown: string,
1532
+ oldRefs: readonly string[],
1533
+ checks: ContractChecks,
1534
+ ): void {
1535
+ const refs = `its execution.mutations.defaults refs name "table" and "column" (${oldRefs.join(', ')}), the keys from before 8.0.0-rc.13, which "entry" and "field" replaced`;
1536
+ const storage = storedHashes(file.value).storage;
1537
+ const isNamed = typeof storage === 'string' && checks.named.has(storage);
1538
+ if (snapshotDirectoryHash(file.path) === undefined && !isNamed) {
1539
+ if (isIntermediateContract(file.path)) checks.intermediate.push(shown);
1540
+ else
1541
+ checks.left.push(
1542
+ `${shown}: ${refs}. It is not a snapshot, and no migration, ref or snapshot names its hashes, so the script leaves it alone. If Prisma emits it, emit it again with \`prisma contract emit\`; otherwise rename those keys to "entry" and "field"`,
1543
+ );
1544
+ return;
1545
+ }
1546
+ const remedy = shown.split('/').includes('migrations')
1547
+ ? `Run the script of the 8.0.0-rc.12 to 8.0.0-rc.13 step \`execution-ref-entry-field\`, which renames the keys in every contract under a \`migrations\` folder, from the project root: \`${renameExecutionRefKeysCommand(checks.root)}\`. Then run this script again`
1548
+ : 'Emit it again with `prisma contract emit`, as the 8.0.0-rc.12 to 8.0.0-rc.13 step `execution-ref-entry-field` says, then run this script again';
1549
+ checks.stops.push(`${shown}: ${refs}. ${remedy}`);
1550
+ }
1551
+
1493
1552
  function planContract(
1494
1553
  file: StoredText,
1495
1554
  shown: string,
1496
1555
  checks: ContractChecks,
1497
1556
  ): ContractPlan | undefined {
1557
+ const oldRefs = oldExecutionRefs(file.value);
1558
+ if (oldRefs.length > 0) {
1559
+ planOldExecutionRefs(file, shown, oldRefs, checks);
1560
+ return undefined;
1561
+ }
1498
1562
  const sections = sectionsOf(file.value);
1499
1563
  if (typeof sections === 'string') {
1500
1564
  checks.stops.push(`${shown}: ${sections}`);
@@ -1539,7 +1603,9 @@ function planContract(
1539
1603
  );
1540
1604
  if (problems.length > 0) {
1541
1605
  const isNamed = typeof stored.storage === 'string' && checks.named.has(stored.storage);
1542
- if (snapshotHash === undefined && !isNamed)
1606
+ if (snapshotHash === undefined && !isNamed && isIntermediateContract(file.path))
1607
+ checks.intermediate.push(shown);
1608
+ else if (snapshotHash === undefined && !isNamed)
1543
1609
  checks.left.push(
1544
1610
  `${shown}: ${problems.join('; ')}. It is not a snapshot, and no migration, ref or snapshot names its hashes, so the script leaves it alone. If Prisma emits it, emit it again with \`prisma contract emit\`; otherwise set its ${hashList(newHashes)}, the hashes its content gives`,
1545
1611
  );
@@ -1729,6 +1795,7 @@ interface Plan {
1729
1795
  readonly superseded: string[];
1730
1796
  /** Contracts whose capabilities the script writes as the list of keys `requiredCapabilities`. */
1731
1797
  readonly renamedCapabilities: string[];
1798
+ readonly intermediate: readonly string[];
1732
1799
  readonly problems: string[];
1733
1800
  }
1734
1801
 
@@ -1751,9 +1818,11 @@ function main(args: readonly string[]): number {
1751
1818
 
1752
1819
  const contracts: ContractPlan[] = [];
1753
1820
  const checks: ContractChecks = {
1821
+ root,
1754
1822
  stops,
1755
1823
  left: [...files.unversioned],
1756
1824
  notes: [],
1825
+ intermediate: [],
1757
1826
  named: namedHashes(files),
1758
1827
  };
1759
1828
  for (const file of files.contracts) {
@@ -1797,6 +1866,7 @@ function main(args: readonly string[]): number {
1797
1866
  merged: [],
1798
1867
  superseded: [],
1799
1868
  renamedCapabilities: [],
1869
+ intermediate: checks.intermediate,
1800
1870
  problems: checks.left,
1801
1871
  };
1802
1872
  const alreadyNew = unknownHashesAlreadyNew(files.migrations, hashes);
@@ -2119,6 +2189,11 @@ function report(
2119
2189
  'Snapshot directories whose new name already held a snapshot with the same storage hash, which `prisma contract emit` wrote with this release. The script kept that snapshot unchanged and removed the old directory:',
2120
2190
  ...plan.superseded.map((note) => ` ${note}`),
2121
2191
  );
2192
+ if (plan.intermediate.length > 0)
2193
+ lines.push(
2194
+ 'Intermediate contracts, left as they are. Each sits beside the `migration.ts` of a data migration, which reads it to type its queries. Their hashes are not the ones their content gives, or their execution default refs have the keys from before 8.0.0-rc.13, but only that `migration.ts` reads them, and it is not run again after this upgrade, so the script does not change them:',
2195
+ ...[...plan.intermediate].sort(compareCodeUnits).map((path) => ` ${path}`),
2196
+ );
2122
2197
  process.stdout.write(`${lines.join('\n')}\n`);
2123
2198
  }
2124
2199
 
@@ -22,7 +22,7 @@
22
22
  import { spawnSync } from 'node:child_process';
23
23
  import { readdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
24
24
  import { createRequire } from 'node:module';
25
- import { join, relative, resolve, sep } from 'node:path';
25
+ import { basename, join, relative, resolve, sep } from 'node:path';
26
26
  import { fileURLToPath, pathToFileURL } from 'node:url';
27
27
  import type * as TS from 'typescript';
28
28
 
@@ -684,7 +684,7 @@ export function loadTypeScript(root: string): TypeScript {
684
684
  }
685
685
  if (withoutCompiler.size > 0)
686
686
  throw new ScriptStop(
687
- `This script reads code with the TypeScript compiler, and the \`typescript\` package it found, version ${[...withoutCompiler].join(' and ')}, has no compiler: the \`typescript\` package of TypeScript 7 exports only its version. The script needs TypeScript 5 or 6. Either install TypeScript 5 in the project for the run, for example with \`pnpm add -D typescript@5\`, and put your version back afterwards; or install \`typescript@5\` in an empty folder, copy this script into that folder, and run the copy with the project folder as its argument: \`node <folder>/<script>.ts <project folder>\`.`,
687
+ `This script reads code with the TypeScript compiler, and the \`typescript\` package it found, version ${[...withoutCompiler].join(' and ')}, has no compiler: the \`typescript\` package of TypeScript 7 exports only its version. The script needs TypeScript 5 or 6. There are two ways to give it one. The first changes nothing in the project: make an empty folder outside the project, write a \`package.json\` in it that holds \`{"type": "module"}\`, run \`pnpm add typescript@5\` in that folder, copy this script into it, and run the copy with the project folder as its argument: \`node <folder>/${basename(fileURLToPath(import.meta.url))} <project folder>\`. Without that \`package.json\`, Node prints a \`MODULE_TYPELESS_PACKAGE_JSON\` warning, which is harmless. The second installs TypeScript 5 in the project for the run: \`pnpm add -D typescript@5\`, with \`-w\` added at the root of a pnpm workspace. It changes \`package.json\` and the lockfile, so after the run put back the \`typescript\` version you had, with \`pnpm add -D typescript@<your version>\` (with \`-w\` again where you used it), or \`pnpm remove typescript\` if the project had none; do not use \`git checkout\` on those files, which would also undo the other uncommitted changes the upgrade made to them.`,
688
688
  );
689
689
  throw new ScriptStop(
690
690
  'This script reads code that imports a renamed name with TypeScript, and found no `typescript` package in the project or beside the script. Prisma lists `typescript` as an optional peer dependency, so the project may not have it: install it in the project, for example as a development dependency, then run the script again.',
@@ -9,7 +9,7 @@
9
9
  import { spawnSync } from 'node:child_process';
10
10
  import { readdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
11
11
  import { createRequire } from 'node:module';
12
- import { join, relative, resolve, sep } from 'node:path';
12
+ import { basename, join, relative, resolve, sep } from 'node:path';
13
13
  import { fileURLToPath, pathToFileURL } from 'node:url';
14
14
  import type * as TS from 'typescript';
15
15
 
@@ -1954,7 +1954,7 @@ export function loadTypeScript(root: string): TypeScript {
1954
1954
  }
1955
1955
  if (withoutCompiler.size > 0)
1956
1956
  throw new ScriptStop(
1957
- `This script reads code with the TypeScript compiler, and the \`typescript\` package it found, version ${[...withoutCompiler].join(' and ')}, has no compiler: the \`typescript\` package of TypeScript 7 exports only its version. The script needs TypeScript 5 or 6. Either install TypeScript 5 in the project for the run, for example with \`pnpm add -D typescript@5\`, and put your version back afterwards; or install \`typescript@5\` in an empty folder, copy this script into that folder, and run the copy with the project folder as its argument: \`node <folder>/<script>.ts <project folder>\`.`,
1957
+ `This script reads code with the TypeScript compiler, and the \`typescript\` package it found, version ${[...withoutCompiler].join(' and ')}, has no compiler: the \`typescript\` package of TypeScript 7 exports only its version. The script needs TypeScript 5 or 6. There are two ways to give it one. The first changes nothing in the project: make an empty folder outside the project, write a \`package.json\` in it that holds \`{"type": "module"}\`, run \`pnpm add typescript@5\` in that folder, copy this script into it, and run the copy with the project folder as its argument: \`node <folder>/${basename(fileURLToPath(import.meta.url))} <project folder>\`. Without that \`package.json\`, Node prints a \`MODULE_TYPELESS_PACKAGE_JSON\` warning, which is harmless. The second installs TypeScript 5 in the project for the run: \`pnpm add -D typescript@5\`, with \`-w\` added at the root of a pnpm workspace. It changes \`package.json\` and the lockfile, so after the run put back the \`typescript\` version you had, with \`pnpm add -D typescript@<your version>\` (with \`-w\` again where you used it), or \`pnpm remove typescript\` if the project had none; do not use \`git checkout\` on those files, which would also undo the other uncommitted changes the upgrade made to them.`,
1958
1958
  );
1959
1959
  throw new ScriptStop(
1960
1960
  'This script reads code with TypeScript, and found no `typescript` package in the project or beside the script. Prisma lists `typescript` as an optional peer dependency, so the project may not have it: install it in the project, for example as a development dependency, then run the script again.',
@@ -21,7 +21,7 @@ changes:
21
21
  - '(?<!\b(?:import|export)\s+(?:type\s+)?\{[^}]*)\bFunctionCondition\b(?!\s*<)'
22
22
  - id: condition-codec-on-mysql-and-sqlite
23
23
  summary: |
24
- On MySQL, MariaDB and SQLite a condition from `fns` is an expression of the target's boolean codec, `mysql/boolean@1` or `sqlite/boolean@1`, not `pg/bool@1`.
24
+ Only for a MySQL, MariaDB or SQLite project: a PostgreSQL project changes nothing here, although the detection matches `pg/bool@1` in many of its files, such as the `contract.d.ts` of a contract with a boolean field, and its snapshots. On MySQL, MariaDB and SQLite a condition from `fns` is an expression of the target's boolean codec, `mysql/boolean@1` or `sqlite/boolean@1`, not `pg/bool@1`.
25
25
  detection:
26
26
  glob: "**/*.{ts,tsx,mts,cts}"
27
27
  matches:
@@ -73,7 +73,9 @@ expectTypeOf(condition).toExtend<Expression<BooleanCodecType<CodecTypes>>>();
73
73
 
74
74
  ## `condition-codec-on-mysql-and-sqlite`
75
75
 
76
- On MySQL, MariaDB and SQLite, a condition such as `fns.eq(...)` or `fns.and(...)` is typed with the target's boolean codec: `mysql/boolean@1` on MySQL and MariaDB, `sqlite/boolean@1` on SQLite. Where code on these targets names `'pg/bool@1'` for a condition, replace it with the target's id. This covers a type annotation such as `Expression<{ codecId: 'pg/bool@1'; nullable: boolean }>`, and `fns.raw` with `.returns('pg/bool@1')` used as the result of `where` or as an operand of `fns.and` or `fns.or`. A boolean column is now accepted wherever a condition is, so a `fns.raw` that only wrapped a boolean column can be replaced by the column. Leave `pg/bool@1` on Postgres as it is.
76
+ This change is only for a MySQL, MariaDB or SQLite project. On PostgreSQL, leave every `pg/bool@1` as it is, even in the files the detection lists.
77
+
78
+ On MySQL, MariaDB and SQLite, a condition such as `fns.eq(...)` or `fns.and(...)` is typed with the target's boolean codec: `mysql/boolean@1` on MySQL and MariaDB, `sqlite/boolean@1` on SQLite. Where code on these targets names `'pg/bool@1'` for a condition, replace it with the target's boolean codec id, `'mysql/boolean@1'` or `'sqlite/boolean@1'`. This covers a type annotation such as `Expression<{ codecId: 'pg/bool@1'; nullable: boolean }>`, and `fns.raw` with `.returns('pg/bool@1')` used as the result of `where` or as an operand of `fns.and` or `fns.or`. A boolean column is now accepted wherever a condition is, so a `fns.raw` that only wrapped a boolean column can be replaced by the column.
77
79
 
78
80
  ## `projected-condition-reads-as-boolean`
79
81
 
@@ -0,0 +1,5 @@
1
+ ---
2
+ from: "8.0.0-rc.27"
3
+ to: "8.0.0-rc.28"
4
+ changes: []
5
+ ---
@@ -3,7 +3,8 @@ from: "0.10"
3
3
  to: "0.11"
4
4
  changes:
5
5
  - id: namespace-kind-required-on-handcrafted-contract-literals
6
- summary: Add the `kind` discriminator (`'sql-namespace'` for SQL namespaces; `'mongo-namespace'` for Mongo namespaces) to every handcrafted `Contract<{ namespaces: { ... } }>` type literal in extension test-d files and inline-typed fixtures. The framework `Namespace` interface tightened `kind` from optional to required; emitted `contract.d.ts` literals carry it automatically, but anything you write by hand will fail typecheck without it.
6
+ summary: |
7
+ Add the `kind` discriminator (`'sql-namespace'` for SQL namespaces; `'mongo-namespace'` for Mongo namespaces) to every handcrafted `Contract<{ namespaces: { ... } }>` type literal in extension test-d files and inline-typed fixtures. The framework `Namespace` interface tightened `kind` from optional to required; emitted `contract.d.ts` literals carry it automatically, but anything you write by hand will fail typecheck without it.
7
8
  detection:
8
9
  glob: "**/*.test-d.ts"
9
10
  contains:
@@ -512,7 +512,7 @@ This guide's script rewrites each import of a removed path to the platform packa
512
512
 
513
513
  #### Where the guide and its script are
514
514
 
515
- This guide is part of the `prisma-8` skill. The skill ships inside the database package; after you install the new version, `prisma skills sync` copies it into the agent skills folder of each harness the project uses: `.agents/skills/prisma-8/`, `.claude/skills/prisma-8/`, `.cursor/skills/prisma-8/` or `.windsurf/skills/prisma-8/`. Any one of these copies will do. The script sits beside this guide in that copy, for example:
515
+ This guide is part of the `prisma-8` skill. Read it, and run its scripts, from the skill of the newest published release, which [Step 0 of the upgrade reference](../../../../references/upgrade-extension.md#step-0--read-the-newest-releases-skill) unpacks in a folder outside the project. The commands in this guide name the copy that `prisma skills sync` writes into the project, `.agents/skills/prisma-8/` (or `.claude/skills/prisma-8/`, `.cursor/skills/prisma-8/` or `.windsurf/skills/prisma-8/`); put the newest release's folder in its place. The script sits beside this guide in that copy, for example:
516
516
 
517
517
  ```text
518
518
  .agents/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts
@@ -825,8 +825,8 @@ node .agents/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-r
825
825
 
826
826
  As with the other script, run it from the skills copy, not from `node_modules`, with Node.js 24 or later. It reads each file with the project's own TypeScript compiler, so run it in a project whose `typescript` package is installed; if it finds none, it says so and stops without changing any file. It needs TypeScript 5 or 6: the `typescript` package of TypeScript 7 has no compiler API that a script can call. The script tries the project's `typescript` first, then one installed beside the script, and uses the first that has a compiler API. If neither has one, it changes no file, says that it needs TypeScript 5 or 6, and exits with code 1. Then do one of the two things its message offers:
827
827
 
828
- - Install TypeScript 5 in the project for the run, for example with `pnpm add -D typescript@5` (add `-w` at the root of a pnpm workspace), run the script, and put the project's own TypeScript version back afterwards.
829
- - Install `typescript@5` in an empty folder, copy the script's `.ts` file into that folder, and run the copy with the project folder as its argument: `node <folder>/<script>.ts <project folder>`.
828
+ - Leave the project unchanged: make an empty folder outside the project, write a `package.json` in it that holds `{"type": "module"}`, run `pnpm add typescript@5` in that folder, copy the script's `.ts` file into it, and run the copy with the project folder as its argument: `node <folder>/<script>.ts <project folder>`. Without that `package.json`, Node prints a `MODULE_TYPELESS_PACKAGE_JSON` warning, which is harmless.
829
+ - Install TypeScript 5 in the project for the run: `pnpm add -D typescript@5`, with `-w` added at the root of a pnpm workspace. This changes `package.json` and the lockfile, so after the run put back the `typescript` version you had, with `pnpm add -D typescript@<your version>` (with `-w` again where you used it), or `pnpm remove typescript` if the project had none; do not use `git checkout` on those files, which would also undo the other uncommitted changes the upgrade made to them.
830
830
 
831
831
  If the script fails on an error it did not expect, it says "The script failed on an unexpected error, before it changed any file. This is a fault in the script; report it to Prisma with this output", prints the stack trace, and exits with code 1.
832
832
 
@@ -1895,7 +1895,7 @@ node .agents/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-r
1895
1895
 
1896
1896
  Do not give it a folder that holds more than the package, such as the root of a monorepo: it would also reach files that look like Prisma's but are not, such as test fixtures. If one of them cannot be read as Prisma's, the script changes no file at all and exits with code 1. The script takes one argument at most, the folder, and no option.
1897
1897
 
1898
- The path names the copy of the `prisma-8` skill in `.agents/skills/`. Where the project has no `.agents` folder, use the copy in the agent's own skills folder instead: `.claude/skills/`, `.cursor/skills/` or `.windsurf/skills/`.
1898
+ The path names the copy of the `prisma-8` skill in `.agents/skills/`. Put the folder of the newest release's skill in its place, as [Step 0 of the upgrade reference](../../../../references/upgrade-extension.md#step-0--read-the-newest-releases-skill) says.
1899
1899
 
1900
1900
  Node 24 or later runs the TypeScript script directly. It reads and writes files only. It walks the folder you gave it, skipping `node_modules`, `dist`, `build`, directories whose name starts with a dot, and, in a git repository, the files and folders git ignores other than a migrations folder and what is in it. In every contract (any `*.json` file with `targetFamily`, `storage` and `schemaVersion` at the top level) it replaces `"schemaVersion": "1"` with `"formatVersion": 1`. In every `migration.json` that has an `ops.json` next to it, and every ref file under the package's `migrations/refs/` (or the migrations folder the package configures under another name; the script recognises a migrations folder by the contract snapshot store or the migrations in it, not by its name, and a ref in any other `refs` folder by its `hash` and `invariants`), it adds `"formatVersion": 1` as the first field. It keeps the rest of each file's bytes, prints each file it changed, and says so when nothing needed changing. A field a ref file does not have, which earlier releases ignored and dropped when they wrote the ref again, it drops and lists. It checks every file before it writes any. It changes no file, prints `Changed no file, because:` with what is wrong with each file and what to do, and exits 1 when it cannot tell the file is one a release of Prisma wrote: a `contract.json`, `migration.json` or ref file it cannot read or parse; a ref file in a migrations folder it recognises without a `hash` or an `invariants` list; a `migration.json` next to an `ops.json` with a field the format does not have or without one it has; a contract with both `formatVersion` and `schemaVersion`, or a `contract.json` holding a contract with neither; a contract whose `schemaVersion` is not `"1"`. Outside a migrations folder it recognises, it leaves alone, without a report, any file in a `refs` folder without a ref's content (a `hash` that is `empty` or a 64-character storage hash, and an `invariants` list of strings). If a command still refuses a ref file after the script ran, that ref was already invalid, and earlier releases refused it too: restore it from version control, or correct it by hand, since no Prisma command writes the head ref in an extension's own package: its `hash` is the `storage.storageHash` of the contract the extension emits. It also reports a stored file whose `formatVersion` is not `1` and a snapshot's `contract.json` that is not a JSON object. It does not follow symbolic links. It ignores a link to the package folder or a folder above it, and a link to a folder inside the package that the walk enters or to a `.json` file in one, unless the walk would read the target as another kind of file than at the link, such as a ref in `migrations/refs/` that links to a file elsewhere; it reports such a link and exits 1. It reports a link to any other file or folder, outside the package or skipped by the walk, that holds a stored file it would change or report.
1901
1901
 
@@ -2000,9 +2000,9 @@ node .agents/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-r
2000
2000
 
2001
2001
  As with the format version script, run it once for each extension package and give it the package's folder, here `packages/extension-foo`, or `.` for a package at the repository root. The script checks every stored file below that folder before it changes anything. A hand-written `migration.json` whose `migrationHash` does not match its migration, or a snapshot with hashes no release wrote, makes it change no file and exit with code 1; a lone contract file, such as a test fixture, is left alone, as the next paragraph says. It skips the files and folders git ignores, other than a migrations folder and what is in it.
2002
2002
 
2003
- The path names the copy of the `prisma-8` skill in `.agents/skills/`. Where the project has no `.agents` folder, use the copy in the agent's own skills folder instead: `.claude/skills/`, `.cursor/skills/` or `.windsurf/skills/`.
2003
+ The path names the copy of the `prisma-8` skill in `.agents/skills/`. Put the folder of the newest release's skill in its place, as [Step 0 of the upgrade reference](../../../../references/upgrade-extension.md#step-0--read-the-newest-releases-skill) says.
2004
2004
 
2005
- Node 24 or later runs the TypeScript script directly. It reads and writes files only. It first checks that each stored storage hash, and each snapshot directory's name, is the hash the old rules or the new rules give the contract's content, and that each `migrationHash` matches its migration. If one does not, the file was edited by hand or comes from another release: the script changes no file, names each such file, and exits 1. The one exception is a contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture: the script leaves that file alone, prints the hashes its content gives, still upgrades the rest of the package, and exits 1. Otherwise it rewrites every hash listed above, renames each snapshot directory to its new hash, and recomputes each `migrationHash`, keeping every other byte of each file. It also renames each contract's and snapshot's `capabilities` to `requiredCapabilities`, and the type of that list in each `contract.d.ts`: `sql.interactiveTransactions` becomes `conn.interactiveTransactions`, every other `sql.` and `postgres.` key becomes `db.`, and a PostgreSQL contract loses the nine keys the release candidates wrote that nothing reads, such as `postgres.jsonAgg`. A contract a development build wrote, with `requiredCapabilities` grouped by provider (`{ "db": { "returning": true } }`), gets the sorted list too, of the keys it sets to `true`; a contract already in the list form keeps it. This release refuses a contract that still has `capabilities`, and a snapshot cannot be emitted again, so the script is the only way to bring one to this release. It changes no file, names the contract and exits 1 when a contract's capabilities cannot be renamed: two old keys become one key with different values (such as `sql.distinctOn: false` beside `postgres.distinctOn: true`, which both become `db.distinctOn`), the file has both `capabilities` and `requiredCapabilities`, `requiredCapabilities` is neither a list of strings nor an object, or a `sql` or `postgres` namespace of `capabilities`, or a provider of a grouped `requiredCapabilities`, is not an object. Emit the contract again with `prisma contract emit` if Prisma writes it, or fix the file by hand, and run the script again. It does not follow symbolic links. It also changes no file at all, names the cause and exits 1 when a link leads to a file or folder that holds stored files and that the walk does not reach, inside the package where the walk skips or outside the package, or that the walk reaches but reads as another kind of file, such as a ref in `migrations/refs/` that links to a file elsewhere, or when a snapshot directory, or the `contract.json` in one, is itself a link, wherever it points, or a folder above it is a link to a place where the snapshot is not under a `snapshots` folder by the same hash, such as a `snapshots` folder linked to a folder with another name, since the script renames each snapshot directory to its new storage hash and through the link it would keep the old name, or when a link outside a snapshot directory points into one, such as a `contract.json` linked to a snapshot's, since after the rename the link would point at nothing, or when a snapshot whose storage hash changes cannot be rewritten without changing other content: migrations and refs would then name a snapshot directory that keeps its old name. Fix the file as the report says and run the script again. It prints what it changed; a second run changes nothing. If you ran `prisma contract emit` with this release before the script, and the contract source holds a value the earlier release left out, the emitted contract's storage hash differs from the new hash of the contract the earlier release wrote, which is the one your databases are at. The script gives every snapshot, migration and ref that named the old hash that new hash, whether or not a snapshot of the contract is left. It leaves the emitted contract as it is and lists it with both hashes, on every run; "When the emitted contract gets a different storage hash" below says what to do. Two kinds of snapshot are accepted although a stored hash does not match. An earlier release may have written a snapshot's profile or execution hash by other rules, and no version of the file has the right one; `prisma db sign <contract reference>` copies a snapshot's profile hash into the database's contract signature, so the script gives such a snapshot the hashes its content gives, before any database is signed, and lists it. And the upgrade steps that renamed MongoDB indexes and field storage names rewrote snapshots in place and kept their storage hashes, because contract signatures, the ledger and migrations name a snapshot by its hash; such a MongoDB snapshot, whose directory name and stored hash agree, takes the new hash of its content, every file that names it follows, and the script lists it.
2005
+ Node 24 or later runs the TypeScript script directly. It reads and writes files only. It first checks that each stored storage hash, and each snapshot directory's name, is the hash the old rules or the new rules give the contract's content, and that each `migrationHash` matches its migration. If one does not, the file was edited by hand or comes from another release: the script changes no file, names each such file, and exits 1. The one exception is a contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture: the script leaves that file alone, prints the hashes its content gives, still upgrades the rest of the package, and exits 1. An intermediate contract, which a migration's `migration.ts` imports to type the queries of a data migration and which sits beside that `migration.ts`, `migration.json` and `ops.json`, is left alone the same way when its storage hash is one nothing names, but listed last under "Intermediate contracts, left as they are", and does not make the script exit 1; when it is all that is left, every run exits 0. Leave it as it is and do not set its hashes: only that `migration.ts` reads it, and it is not run again after this upgrade. A contract whose `execution.mutations.defaults` refs still have the keys `table` and `column`, which 8.0.0-rc.13 renamed to `entry` and `field`, is left alone like one with wrong hashes when it is not a snapshot and nothing names its storage hash: an intermediate contract is listed as one, and any other is listed under "Left unchanged:" and makes the script exit 1. A snapshot with such refs, or a contract something names, makes the script change no file and exit 1, listing the contract under "Changed no file, because:"; for one under `migrations/`, run the command the message gives from the package folder, which runs the script of the 8.0.0-rc.12 to 8.0.0-rc.13 step `execution-ref-entry-field` from the same skill copy, `node <skill>/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts`, or emit any other contract again, as that step says, and run this script again. Otherwise it rewrites every hash listed above, renames each snapshot directory to its new hash, and recomputes each `migrationHash`, keeping every other byte of each file. It also renames each contract's and snapshot's `capabilities` to `requiredCapabilities`, and the type of that list in each `contract.d.ts`: `sql.interactiveTransactions` becomes `conn.interactiveTransactions`, every other `sql.` and `postgres.` key becomes `db.`, and a PostgreSQL contract loses the nine keys the release candidates wrote that nothing reads, such as `postgres.jsonAgg`. A contract a development build wrote, with `requiredCapabilities` grouped by provider (`{ "db": { "returning": true } }`), gets the sorted list too, of the keys it sets to `true`; a contract already in the list form keeps it. This release refuses a contract that still has `capabilities`, and a snapshot cannot be emitted again, so the script is the only way to bring one to this release. It changes no file, names the contract and exits 1 when a contract's capabilities cannot be renamed: two old keys become one key with different values (such as `sql.distinctOn: false` beside `postgres.distinctOn: true`, which both become `db.distinctOn`), the file has both `capabilities` and `requiredCapabilities`, `requiredCapabilities` is neither a list of strings nor an object, or a `sql` or `postgres` namespace of `capabilities`, or a provider of a grouped `requiredCapabilities`, is not an object. Emit the contract again with `prisma contract emit` if Prisma writes it, or fix the file by hand, and run the script again. It does not follow symbolic links. It also changes no file at all, names the cause and exits 1 when a link leads to a file or folder that holds stored files and that the walk does not reach, inside the package where the walk skips or outside the package, or that the walk reaches but reads as another kind of file, such as a ref in `migrations/refs/` that links to a file elsewhere, or when a snapshot directory, or the `contract.json` in one, is itself a link, wherever it points, or a folder above it is a link to a place where the snapshot is not under a `snapshots` folder by the same hash, such as a `snapshots` folder linked to a folder with another name, since the script renames each snapshot directory to its new storage hash and through the link it would keep the old name, or when a link outside a snapshot directory points into one, such as a `contract.json` linked to a snapshot's, since after the rename the link would point at nothing, or when a snapshot whose storage hash changes cannot be rewritten without changing other content: migrations and refs would then name a snapshot directory that keeps its old name. Fix the file as the report says and run the script again. It prints what it changed; a second run changes nothing. If you ran `prisma contract emit` with this release before the script, and the contract source holds a value the earlier release left out, the emitted contract's storage hash differs from the new hash of the contract the earlier release wrote, which is the one your databases are at. The script gives every snapshot, migration and ref that named the old hash that new hash, whether or not a snapshot of the contract is left. It leaves the emitted contract as it is and lists it with both hashes, on every run; "When the emitted contract gets a different storage hash" below says what to do. Two kinds of snapshot are accepted although a stored hash does not match. An earlier release may have written a snapshot's profile or execution hash by other rules, and no version of the file has the right one; `prisma db sign <contract reference>` copies a snapshot's profile hash into the database's contract signature, so the script gives such a snapshot the hashes its content gives, before any database is signed, and lists it. And the upgrade steps that renamed MongoDB indexes and field storage names rewrote snapshots in place and kept their storage hashes, because contract signatures, the ledger and migrations name a snapshot by its hash; such a MongoDB snapshot, whose directory name and stored hash agree, takes the new hash of its content, every file that names it follows, and the script lists it.
2006
2006
 
2007
2007
  Then run `prisma contract emit`, build the package and run its tests, and publish a new version. An application must upgrade the extension together with Prisma: an older version of the extension does not load in this release, and this version does not load in an earlier one.
2008
2008
 
@@ -12,7 +12,9 @@
12
12
  *
13
13
  * It reads a stored file whether or not it has a `formatVersion`, and leaves its format version as it is: a file a release candidate wrote keeps `"schemaVersion": "1"`, or no version field, and this release reads it as format version 0.
14
14
  *
15
- * A contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture, does not stop the upgrade when its hashes are wrong: it is reported, left unchanged, and makes the script exit 1.
15
+ * A contract that is not a snapshot and whose storage hash no migration, ref or snapshot names, such as a hand-made test fixture, does not stop the upgrade when its hashes are wrong: it is reported, left unchanged, and makes the script exit 1. An intermediate contract, one in a migration's directory beside its `migration.ts`, which reads it to type a data migration's queries, is the exception: when its hashes are wrong it is listed as an intermediate contract and left unchanged, and the script still exits 0, since that `migration.ts` is not run again after this upgrade.
16
+ *
17
+ * A contract whose `execution.mutations.defaults` refs still have the keys `table` and `column`, which 8.0.0-rc.13 renamed to `entry` and `field`, stops the run when it is a snapshot or something names its storage hash: the script changes no file and gives the command of the 8.0.0-rc.12 to 8.0.0-rc.13 step that renames them. Such a contract that nothing names is left alone like one with wrong hashes: an intermediate contract is listed as one, and any other is reported and makes the script exit 1.
16
18
  *
17
19
  * Otherwise it rewrites: the three hashes in every contract; the same hashes in the `contract.d.ts` beside it; each snapshot directory's name; `from`, `to` and `migrationHash` in every `migration.json`, and the storage hashes in the `ops.json` beside it; `hash` in every ref file; and every old storage hash in every `migration.ts` (snapshot import paths and hash literals). It edits each file's text, so every other byte stays, including a leading byte order mark, and replaces each file in one rename, so a run that stops partway can be run again to finish. It prints what it changed and each hash it replaced. A `contract.d.ts` whose hashes it cannot match with its contract, or a migration or ref naming a hash it cannot tell the new value of, is reported, left unchanged, and makes it exit 1. A second run changes nothing.
18
20
  *
@@ -32,7 +34,8 @@ import {
32
34
  statSync,
33
35
  writeFileSync,
34
36
  } from 'node:fs';
35
- import { basename, dirname, join, relative, resolve, sep } from 'node:path';
37
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
38
+ import { fileURLToPath } from 'node:url';
36
39
 
37
40
  type Json = null | boolean | number | string | Json[] | JsonRecord;
38
41
  interface JsonRecord {
@@ -1481,20 +1484,81 @@ function hashList(hashes: HashSet): string {
1481
1484
  }
1482
1485
 
1483
1486
  interface ContractChecks {
1487
+ /** The project root the script upgrades. */
1488
+ readonly root: string;
1484
1489
  readonly stops: string[];
1485
1490
  /** Contracts the script leaves unchanged and reports, without refusing the project. */
1486
1491
  readonly left: string[];
1487
1492
  /** Snapshots whose profile or execution hash an earlier release wrote by other rules. */
1488
1493
  readonly notes: string[];
1494
+ /** Stale intermediate contracts the script leaves unchanged without counting them as problems. */
1495
+ readonly intermediate: string[];
1489
1496
  /** Every storage hash a migration, ref or snapshot names. */
1490
1497
  readonly named: ReadonlySet<string>;
1491
1498
  }
1492
1499
 
1500
+ function oldExecutionRefs(value: JsonRecord): readonly string[] {
1501
+ const execution = value['execution'];
1502
+ const mutations = isRecord(execution) ? execution['mutations'] : undefined;
1503
+ const defaults = isRecord(mutations) ? mutations['defaults'] : undefined;
1504
+ if (!Array.isArray(defaults)) return [];
1505
+ return defaults.flatMap((entry) => {
1506
+ const ref = isRecord(entry) ? entry['ref'] : undefined;
1507
+ if (!isRecord(ref) || !('table' in ref || 'column' in ref)) return [];
1508
+ return [`${String(ref['table'])}.${String(ref['column'])}`];
1509
+ });
1510
+ }
1511
+
1512
+ function isIntermediateContract(path: string): boolean {
1513
+ const dir = dirname(path);
1514
+ return isMigrationPackage(dir) && existsSync(join(dir, 'migration.ts'));
1515
+ }
1516
+
1517
+ /** The `node` command that runs the 8.0.0-rc.12 to 8.0.0-rc.13 script of this skill copy from `root`: relative to `root` when the copy is inside it. */
1518
+ function renameExecutionRefKeysCommand(root: string): string {
1519
+ const upgrades = resolve(dirname(fileURLToPath(import.meta.url)), '../../..');
1520
+ const script = join(
1521
+ upgrades,
1522
+ '8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts',
1523
+ );
1524
+ const fromRoot = relative(realpathSync(root), script);
1525
+ const path = fromRoot.startsWith('..') || isAbsolute(fromRoot) ? script : fromRoot;
1526
+ return `node ${path.split(sep).join('/')}`;
1527
+ }
1528
+
1529
+ function planOldExecutionRefs(
1530
+ file: StoredText,
1531
+ shown: string,
1532
+ oldRefs: readonly string[],
1533
+ checks: ContractChecks,
1534
+ ): void {
1535
+ const refs = `its execution.mutations.defaults refs name "table" and "column" (${oldRefs.join(', ')}), the keys from before 8.0.0-rc.13, which "entry" and "field" replaced`;
1536
+ const storage = storedHashes(file.value).storage;
1537
+ const isNamed = typeof storage === 'string' && checks.named.has(storage);
1538
+ if (snapshotDirectoryHash(file.path) === undefined && !isNamed) {
1539
+ if (isIntermediateContract(file.path)) checks.intermediate.push(shown);
1540
+ else
1541
+ checks.left.push(
1542
+ `${shown}: ${refs}. It is not a snapshot, and no migration, ref or snapshot names its hashes, so the script leaves it alone. If Prisma emits it, emit it again with \`prisma contract emit\`; otherwise rename those keys to "entry" and "field"`,
1543
+ );
1544
+ return;
1545
+ }
1546
+ const remedy = shown.split('/').includes('migrations')
1547
+ ? `Run the script of the 8.0.0-rc.12 to 8.0.0-rc.13 step \`execution-ref-entry-field\`, which renames the keys in every contract under a \`migrations\` folder, from the project root: \`${renameExecutionRefKeysCommand(checks.root)}\`. Then run this script again`
1548
+ : 'Emit it again with `prisma contract emit`, as the 8.0.0-rc.12 to 8.0.0-rc.13 step `execution-ref-entry-field` says, then run this script again';
1549
+ checks.stops.push(`${shown}: ${refs}. ${remedy}`);
1550
+ }
1551
+
1493
1552
  function planContract(
1494
1553
  file: StoredText,
1495
1554
  shown: string,
1496
1555
  checks: ContractChecks,
1497
1556
  ): ContractPlan | undefined {
1557
+ const oldRefs = oldExecutionRefs(file.value);
1558
+ if (oldRefs.length > 0) {
1559
+ planOldExecutionRefs(file, shown, oldRefs, checks);
1560
+ return undefined;
1561
+ }
1498
1562
  const sections = sectionsOf(file.value);
1499
1563
  if (typeof sections === 'string') {
1500
1564
  checks.stops.push(`${shown}: ${sections}`);
@@ -1539,7 +1603,9 @@ function planContract(
1539
1603
  );
1540
1604
  if (problems.length > 0) {
1541
1605
  const isNamed = typeof stored.storage === 'string' && checks.named.has(stored.storage);
1542
- if (snapshotHash === undefined && !isNamed)
1606
+ if (snapshotHash === undefined && !isNamed && isIntermediateContract(file.path))
1607
+ checks.intermediate.push(shown);
1608
+ else if (snapshotHash === undefined && !isNamed)
1543
1609
  checks.left.push(
1544
1610
  `${shown}: ${problems.join('; ')}. It is not a snapshot, and no migration, ref or snapshot names its hashes, so the script leaves it alone. If Prisma emits it, emit it again with \`prisma contract emit\`; otherwise set its ${hashList(newHashes)}, the hashes its content gives`,
1545
1611
  );
@@ -1729,6 +1795,7 @@ interface Plan {
1729
1795
  readonly superseded: string[];
1730
1796
  /** Contracts whose capabilities the script writes as the list of keys `requiredCapabilities`. */
1731
1797
  readonly renamedCapabilities: string[];
1798
+ readonly intermediate: readonly string[];
1732
1799
  readonly problems: string[];
1733
1800
  }
1734
1801
 
@@ -1751,9 +1818,11 @@ function main(args: readonly string[]): number {
1751
1818
 
1752
1819
  const contracts: ContractPlan[] = [];
1753
1820
  const checks: ContractChecks = {
1821
+ root,
1754
1822
  stops,
1755
1823
  left: [...files.unversioned],
1756
1824
  notes: [],
1825
+ intermediate: [],
1757
1826
  named: namedHashes(files),
1758
1827
  };
1759
1828
  for (const file of files.contracts) {
@@ -1797,6 +1866,7 @@ function main(args: readonly string[]): number {
1797
1866
  merged: [],
1798
1867
  superseded: [],
1799
1868
  renamedCapabilities: [],
1869
+ intermediate: checks.intermediate,
1800
1870
  problems: checks.left,
1801
1871
  };
1802
1872
  const alreadyNew = unknownHashesAlreadyNew(files.migrations, hashes);
@@ -2119,6 +2189,11 @@ function report(
2119
2189
  'Snapshot directories whose new name already held a snapshot with the same storage hash, which `prisma contract emit` wrote with this release. The script kept that snapshot unchanged and removed the old directory:',
2120
2190
  ...plan.superseded.map((note) => ` ${note}`),
2121
2191
  );
2192
+ if (plan.intermediate.length > 0)
2193
+ lines.push(
2194
+ 'Intermediate contracts, left as they are. Each sits beside the `migration.ts` of a data migration, which reads it to type its queries. Their hashes are not the ones their content gives, or their execution default refs have the keys from before 8.0.0-rc.13, but only that `migration.ts` reads them, and it is not run again after this upgrade, so the script does not change them:',
2195
+ ...[...plan.intermediate].sort(compareCodeUnits).map((path) => ` ${path}`),
2196
+ );
2122
2197
  process.stdout.write(`${lines.join('\n')}\n`);
2123
2198
  }
2124
2199
 
@@ -22,7 +22,7 @@
22
22
  import { spawnSync } from 'node:child_process';
23
23
  import { readdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
24
24
  import { createRequire } from 'node:module';
25
- import { join, relative, resolve, sep } from 'node:path';
25
+ import { basename, join, relative, resolve, sep } from 'node:path';
26
26
  import { fileURLToPath, pathToFileURL } from 'node:url';
27
27
  import type * as TS from 'typescript';
28
28
 
@@ -684,7 +684,7 @@ export function loadTypeScript(root: string): TypeScript {
684
684
  }
685
685
  if (withoutCompiler.size > 0)
686
686
  throw new ScriptStop(
687
- `This script reads code with the TypeScript compiler, and the \`typescript\` package it found, version ${[...withoutCompiler].join(' and ')}, has no compiler: the \`typescript\` package of TypeScript 7 exports only its version. The script needs TypeScript 5 or 6. Either install TypeScript 5 in the project for the run, for example with \`pnpm add -D typescript@5\`, and put your version back afterwards; or install \`typescript@5\` in an empty folder, copy this script into that folder, and run the copy with the project folder as its argument: \`node <folder>/<script>.ts <project folder>\`.`,
687
+ `This script reads code with the TypeScript compiler, and the \`typescript\` package it found, version ${[...withoutCompiler].join(' and ')}, has no compiler: the \`typescript\` package of TypeScript 7 exports only its version. The script needs TypeScript 5 or 6. There are two ways to give it one. The first changes nothing in the project: make an empty folder outside the project, write a \`package.json\` in it that holds \`{"type": "module"}\`, run \`pnpm add typescript@5\` in that folder, copy this script into it, and run the copy with the project folder as its argument: \`node <folder>/${basename(fileURLToPath(import.meta.url))} <project folder>\`. Without that \`package.json\`, Node prints a \`MODULE_TYPELESS_PACKAGE_JSON\` warning, which is harmless. The second installs TypeScript 5 in the project for the run: \`pnpm add -D typescript@5\`, with \`-w\` added at the root of a pnpm workspace. It changes \`package.json\` and the lockfile, so after the run put back the \`typescript\` version you had, with \`pnpm add -D typescript@<your version>\` (with \`-w\` again where you used it), or \`pnpm remove typescript\` if the project had none; do not use \`git checkout\` on those files, which would also undo the other uncommitted changes the upgrade made to them.`,
688
688
  );
689
689
  throw new ScriptStop(
690
690
  'This script reads code that imports a renamed name with TypeScript, and found no `typescript` package in the project or beside the script. Prisma lists `typescript` as an optional peer dependency, so the project may not have it: install it in the project, for example as a development dependency, then run the script again.',
@@ -9,7 +9,7 @@
9
9
  import { spawnSync } from 'node:child_process';
10
10
  import { readdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
11
11
  import { createRequire } from 'node:module';
12
- import { join, relative, resolve, sep } from 'node:path';
12
+ import { basename, join, relative, resolve, sep } from 'node:path';
13
13
  import { fileURLToPath, pathToFileURL } from 'node:url';
14
14
  import type * as TS from 'typescript';
15
15
 
@@ -1954,7 +1954,7 @@ export function loadTypeScript(root: string): TypeScript {
1954
1954
  }
1955
1955
  if (withoutCompiler.size > 0)
1956
1956
  throw new ScriptStop(
1957
- `This script reads code with the TypeScript compiler, and the \`typescript\` package it found, version ${[...withoutCompiler].join(' and ')}, has no compiler: the \`typescript\` package of TypeScript 7 exports only its version. The script needs TypeScript 5 or 6. Either install TypeScript 5 in the project for the run, for example with \`pnpm add -D typescript@5\`, and put your version back afterwards; or install \`typescript@5\` in an empty folder, copy this script into that folder, and run the copy with the project folder as its argument: \`node <folder>/<script>.ts <project folder>\`.`,
1957
+ `This script reads code with the TypeScript compiler, and the \`typescript\` package it found, version ${[...withoutCompiler].join(' and ')}, has no compiler: the \`typescript\` package of TypeScript 7 exports only its version. The script needs TypeScript 5 or 6. There are two ways to give it one. The first changes nothing in the project: make an empty folder outside the project, write a \`package.json\` in it that holds \`{"type": "module"}\`, run \`pnpm add typescript@5\` in that folder, copy this script into it, and run the copy with the project folder as its argument: \`node <folder>/${basename(fileURLToPath(import.meta.url))} <project folder>\`. Without that \`package.json\`, Node prints a \`MODULE_TYPELESS_PACKAGE_JSON\` warning, which is harmless. The second installs TypeScript 5 in the project for the run: \`pnpm add -D typescript@5\`, with \`-w\` added at the root of a pnpm workspace. It changes \`package.json\` and the lockfile, so after the run put back the \`typescript\` version you had, with \`pnpm add -D typescript@<your version>\` (with \`-w\` again where you used it), or \`pnpm remove typescript\` if the project had none; do not use \`git checkout\` on those files, which would also undo the other uncommitted changes the upgrade made to them.`,
1958
1958
  );
1959
1959
  throw new ScriptStop(
1960
1960
  'This script reads code with TypeScript, and found no `typescript` package in the project or beside the script. Prisma lists `typescript` as an optional peer dependency, so the project may not have it: install it in the project, for example as a development dependency, then run the script again.',
@@ -18,7 +18,7 @@ changes:
18
18
  - '(?<!\b(?:import|export)\s+(?:type\s+)?\{[^}]*)\bFunctionCondition\b(?!\s*<)'
19
19
  - id: condition-codec-on-mysql-and-sqlite
20
20
  summary: |
21
- On MySQL, MariaDB and SQLite a condition from `fns` is an expression of the target's boolean codec, and a selected condition reads as a boolean, or `null` when its value is NULL.
21
+ Only for an extension that runs on MySQL, MariaDB or SQLite: an extension that runs only on PostgreSQL changes nothing here. On those three targets a condition from `fns` is an expression of the target's boolean codec, and a selected condition reads as a boolean, or `null` when its value is NULL.
22
22
  - id: functions-builders-no-longer-published
23
23
  summary: |
24
24
  `createFunctions` and `createAggregateFunctions` are no longer published; a callback of the query builder receives the functions they built as its `fns` argument, and a callback of the ORM receives the ORM's functions, built from `createFunctions`.
@@ -0,0 +1,5 @@
1
+ ---
2
+ from: "8.0.0-rc.27"
3
+ to: "8.0.0-rc.28"
4
+ changes: []
5
+ ---