@prisma/orm-postgres 8.0.0-rc.24-dev.42 → 8.0.0-rc.24-dev.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{contract-from-json-C5RaYxw_-CZexnZZA.mjs → contract-from-json-DoE5soiA-DAvpjAkO.mjs} +3 -3
- package/dist/{contract-from-json-C5RaYxw_-CZexnZZA.mjs.map → contract-from-json-DoE5soiA-DAvpjAkO.mjs.map} +1 -1
- package/dist/internal__static-context.mjs +1 -1
- package/dist/internal__validate-contract.mjs +1 -1
- package/dist/{postgres-static-0mhBLZPg-TkzCPypD.mjs → postgres-static-BSikEOb5-CrYnN7HO.mjs} +3 -3
- package/dist/{postgres-static-0mhBLZPg-TkzCPypD.mjs.map → postgres-static-BSikEOb5-CrYnN7HO.mjs.map} +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/runtime.mjs.map +1 -1
- package/dist/serverless.mjs +2 -2
- package/dist/serverless.mjs.map +1 -1
- package/dist/static.mjs +2 -2
- package/package.json +8 -8
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/references/debug.md +2 -2
- package/skills/prisma-8/references/migration-model.md +9 -10
- package/skills/prisma-8/references/migration-review.md +1 -1
- package/skills/prisma-8/references/migrations.md +22 -14
package/dist/{contract-from-json-C5RaYxw_-CZexnZZA.mjs → contract-from-json-DoE5soiA-DAvpjAkO.mjs}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import postgresTarget, { PostgresContractSerializer } from "@prisma/orm-target-postgres/target/runtime";
|
|
2
2
|
import { validateContractOnce } from "@prisma/orm-framework/contract/validate-once";
|
|
3
|
-
//#region ../../../3-targets/postgres/9-facade/dist/contract-from-json-
|
|
4
|
-
var version = "8.0.0-rc.24-dev.
|
|
3
|
+
//#region ../../../3-targets/postgres/9-facade/dist/contract-from-json-DoE5soiA.mjs
|
|
4
|
+
var version = "8.0.0-rc.24-dev.44";
|
|
5
5
|
const serializer = new PostgresContractSerializer();
|
|
6
6
|
const validator = `${postgresTarget.targetId}@${version}`;
|
|
7
7
|
/**
|
|
@@ -30,4 +30,4 @@ function validatePostgresContract(contract) {
|
|
|
30
30
|
//#endregion
|
|
31
31
|
export { validatePostgresContract as n, contractFromJson as t };
|
|
32
32
|
|
|
33
|
-
//# sourceMappingURL=contract-from-json-
|
|
33
|
+
//# sourceMappingURL=contract-from-json-DoE5soiA-DAvpjAkO.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-from-json-
|
|
1
|
+
{"version":3,"file":"contract-from-json-DoE5soiA-DAvpjAkO.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/contract-from-json-DoE5soiA.mjs"],"sourcesContent":["import postgresTarget, { PostgresContractSerializer } from \"@internal/target-postgres/runtime\";\nimport { validateContractOnce } from \"@internal/contract/validate-once\";\n//#region package.json\nvar version = \"8.0.0-rc.24-dev.44\";\n//#endregion\n//#region src/static/contract-from-json.ts\nconst serializer = new PostgresContractSerializer();\nconst validator = `${postgresTarget.targetId}@${version}`;\n/**\n* Validates an emitted Postgres `contract.json` and returns it as the contract type the\n* application names, ready to pass to `postgres({ contract })` and the other Postgres clients.\n* Clients built from 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 Postgres client, once per value. */\nfunction validatePostgresContract(contract) {\n\treturn validateContractOnce(contract, validator, () => serializer.deserializeContract(serializer.serializeContract(contract)));\n}\n//#endregion\nexport { validatePostgresContract as n, contractFromJson as t };\n\n//# sourceMappingURL=contract-from-json-DoE5soiA.mjs.map"],"mappings":";;;AAGA,IAAI,UAAU;AAGd,MAAM,aAAa,IAAI,2BAA2B;AAClD,MAAM,YAAY,GAAG,eAAe,SAAS,GAAG;;;;;;;;;;;;;;;;;AAiBhD,SAAS,iBAAiB,MAAM;CAC/B,OAAO,qBAAqB,MAAM,YAAY,UAAU,WAAW,oBAAoB,KAAK,CAAC;AAC9F;;AAEA,SAAS,yBAAyB,UAAU;CAC3C,OAAO,qBAAqB,UAAU,iBAAiB,WAAW,oBAAoB,WAAW,kBAAkB,QAAQ,CAAC,CAAC;AAC9H"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as buildPostgresStaticContext } from "./postgres-static-
|
|
1
|
+
import { n as buildPostgresStaticContext } from "./postgres-static-BSikEOb5-CrYnN7HO.mjs";
|
|
2
2
|
export { buildPostgresStaticContext };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as validatePostgresContract } from "./contract-from-json-
|
|
1
|
+
import { n as validatePostgresContract } from "./contract-from-json-DoE5soiA-DAvpjAkO.mjs";
|
|
2
2
|
export { validatePostgresContract };
|
package/dist/{postgres-static-0mhBLZPg-TkzCPypD.mjs → postgres-static-BSikEOb5-CrYnN7HO.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as validatePostgresContract } from "./contract-from-json-
|
|
1
|
+
import { n as validatePostgresContract } from "./contract-from-json-DoE5soiA-DAvpjAkO.mjs";
|
|
2
2
|
import { PG_ENUM_CODEC_ID } from "@prisma/orm-target-postgres/target/codec-ids";
|
|
3
3
|
import postgresTarget from "@prisma/orm-target-postgres/target/runtime";
|
|
4
4
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
@@ -6,7 +6,7 @@ import { buildNamespacedEnums, createEnumAccessor } from "@prisma/orm-framework/
|
|
|
6
6
|
import postgresAdapter from "@prisma/orm-target-postgres/adapter/runtime";
|
|
7
7
|
import { createExecutionContext, createSqlExecutionStack, createToSql } from "@prisma/orm-family-sql/runtime";
|
|
8
8
|
import { createRawLane, sql } from "@prisma/orm-family-sql/builder/runtime";
|
|
9
|
-
//#region ../../../3-targets/postgres/9-facade/dist/postgres-static-
|
|
9
|
+
//#region ../../../3-targets/postgres/9-facade/dist/postgres-static-BSikEOb5.mjs
|
|
10
10
|
/**
|
|
11
11
|
* The accessors for one namespace's value sets, leaving out each value set whose name is a domain enum's in the same namespace: a domain enum's value set takes its enum's name and namespace, and `db.enums` holds that enum. The rest are native enum types, because `native_enum` is the only pack entity that derives a value set today. Reads plain contract data, so a `validateContract`'d JSON contract works as well as a hydrated one. A member is a value, as in `CREATE TYPE … AS ENUM ('a', 'b')`, so each value is also its own name.
|
|
12
12
|
*/
|
|
@@ -77,4 +77,4 @@ function postgresStatic(options) {
|
|
|
77
77
|
//#endregion
|
|
78
78
|
export { buildPostgresStaticContext as n, postgresStatic as r, buildNamespacedNativeEnums as t };
|
|
79
79
|
|
|
80
|
-
//# sourceMappingURL=postgres-static-
|
|
80
|
+
//# sourceMappingURL=postgres-static-BSikEOb5-CrYnN7HO.mjs.map
|
package/dist/{postgres-static-0mhBLZPg-TkzCPypD.mjs.map → postgres-static-BSikEOb5-CrYnN7HO.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-static-
|
|
1
|
+
{"version":3,"file":"postgres-static-BSikEOb5-CrYnN7HO.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/postgres-static-BSikEOb5.mjs"],"sourcesContent":["import { n as validatePostgresContract } from \"./contract-from-json-DoE5soiA.mjs\";\nimport { PG_ENUM_CODEC_ID } from \"@internal/target-postgres/codec-ids\";\nimport postgresTarget from \"@internal/target-postgres/runtime\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { buildNamespacedEnums, createEnumAccessor } from \"@internal/contract/enum-accessor\";\nimport postgresAdapter from \"@internal/adapter-postgres/runtime\";\nimport { createExecutionContext, createSqlExecutionStack, createToSql } from \"@internal/sql-runtime\";\nimport { createRawLane, sql } from \"@internal/sql-builder/runtime\";\n//#region src/runtime/native-enums.ts\n/**\n* The accessors for one namespace's value sets, leaving out each value set whose name is a domain enum's in the same namespace: a domain enum's value set takes its enum's name and namespace, and `db.enums` holds that enum. The rest are native enum types, because `native_enum` is the only pack entity that derives a value set today. Reads plain contract data, so a `validateContract`'d JSON contract works as well as a hydrated one. A member is a value, as in `CREATE TYPE … AS ENUM ('a', 'b')`, so each value is also its own name.\n*/\nfunction buildNativeEnumsMapForNamespace(storage, domain, namespaceId) {\n\tconst result = {};\n\tconst valueSets = storage.namespaces[namespaceId]?.entries.valueSet;\n\tif (!valueSets) return result;\n\tconst domainEnums = domain.namespaces[namespaceId]?.enum ?? {};\n\tfor (const [name, valueSet] of Object.entries(valueSets)) {\n\t\tif (Object.hasOwn(domainEnums, name)) continue;\n\t\tresult[name] = createEnumAccessor({\n\t\t\tcodecId: PG_ENUM_CODEC_ID,\n\t\t\tmembers: valueSet.values.map((value) => ({\n\t\t\t\tname: String(value),\n\t\t\t\tvalue\n\t\t\t}))\n\t\t});\n\t}\n\treturn result;\n}\nfunction buildNamespacedNativeEnums(storage, domain) {\n\tconst result = {};\n\tfor (const namespaceId of Object.keys(storage.namespaces)) result[namespaceId] = buildNativeEnumsMapForNamespace(storage, domain, namespaceId);\n\treturn result;\n}\n//#endregion\n//#region src/static/postgres-static.ts\nfunction buildPostgresStaticContext(contract, context, stack) {\n\tconst { rawCodecInferer } = stack.adapter;\n\tconst sqlDb = sql({\n\t\tcontext,\n\t\trawCodecInferer\n\t});\n\tconst raw = createRawLane({\n\t\tcontext,\n\t\trawCodecInferer\n\t});\n\treturn {\n\t\tcontext,\n\t\tcontract,\n\t\tenums: Object.freeze(buildNamespacedEnums(context.contract.domain, (codecId) => context.contractCodecs.forCodecRef({ codecId }))),\n\t\tnativeEnums: blindCast(Object.freeze(buildNamespacedNativeEnums(context.contract.storage, context.contract.domain))),\n\t\tsql: sqlDb,\n\t\traw,\n\t\ttoSql: createToSql(stack, contract)\n\t};\n}\n/**\n* The query surfaces of a Postgres client without a driver: `sql`, `raw`, `enums`, `nativeEnums`\n* and `toSql`. Use it where loading `pg` is not wanted, for example in browser code that reads\n* enums.\n*\n* @example\n* ```ts\n* const { enums } = postgresStatic({ contract: contractFromJson<Contract>(contractJson) });\n* ```\n*/\nfunction postgresStatic(options) {\n\tconst contract = validatePostgresContract(options.contract);\n\tconst stack = createSqlExecutionStack({\n\t\ttarget: postgresTarget,\n\t\tadapter: postgresAdapter,\n\t\textensions: options.extensions ?? []\n\t});\n\treturn buildPostgresStaticContext(contract, createExecutionContext({\n\t\tcontract,\n\t\tstack\n\t}), stack);\n}\n//#endregion\nexport { postgresStatic as n, buildNamespacedNativeEnums as r, buildPostgresStaticContext as t };\n\n//# sourceMappingURL=postgres-static-BSikEOb5.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,SAAS,gCAAgC,SAAS,QAAQ,aAAa;CACtE,MAAM,SAAS,CAAC;CAChB,MAAM,YAAY,QAAQ,WAAW,YAAY,EAAE,QAAQ;CAC3D,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,cAAc,OAAO,WAAW,YAAY,EAAE,QAAQ,CAAC;CAC7D,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,SAAS,GAAG;EACzD,IAAI,OAAO,OAAO,aAAa,IAAI,GAAG;EACtC,OAAO,QAAQ,mBAAmB;GACjC,SAAS;GACT,SAAS,SAAS,OAAO,KAAK,WAAW;IACxC,MAAM,OAAO,KAAK;IAClB;GACD,EAAE;EACH,CAAC;CACF;CACA,OAAO;AACR;AACA,SAAS,2BAA2B,SAAS,QAAQ;CACpD,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,eAAe,OAAO,KAAK,QAAQ,UAAU,GAAG,OAAO,eAAe,gCAAgC,SAAS,QAAQ,WAAW;CAC7I,OAAO;AACR;AAGA,SAAS,2BAA2B,UAAU,SAAS,OAAO;CAC7D,MAAM,EAAE,oBAAoB,MAAM;CAClC,MAAM,QAAQ,IAAI;EACjB;EACA;CACD,CAAC;CACD,MAAM,MAAM,cAAc;EACzB;EACA;CACD,CAAC;CACD,OAAO;EACN;EACA;EACA,OAAO,OAAO,OAAO,qBAAqB,QAAQ,SAAS,SAAS,YAAY,QAAQ,eAAe,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;EAChI,aAAa,UAAU,OAAO,OAAO,2BAA2B,QAAQ,SAAS,SAAS,QAAQ,SAAS,MAAM,CAAC,CAAC;EACnH,KAAK;EACL;EACA,OAAO,YAAY,OAAO,QAAQ;CACnC;AACD;;;;;;;;;;;AAWA,SAAS,eAAe,SAAS;CAChC,MAAM,WAAW,yBAAyB,QAAQ,QAAQ;CAC1D,MAAM,QAAQ,wBAAwB;EACrC,QAAQ;EACR,SAAS;EACT,YAAY,QAAQ,cAAc,CAAC;CACpC,CAAC;CACD,OAAO,2BAA2B,UAAU,uBAAuB;EAClE;EACA;CACD,CAAC,GAAG,KAAK;AACV"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as postgresError } from "./errors-DfWK9xep-CB07krZF.mjs";
|
|
2
2
|
import { i as validateTransactionOptions, n as toDriverCursorOptions, r as validateCursorOptions } from "./postgres-options-CZyV9Him-2OSYJKqo.mjs";
|
|
3
3
|
import { a as resolveOptionalPostgresBinding, i as postgresBindingRules, n as isPgClient, o as resolvePostgresBinding, r as isPgPool, t as connectWithBinding } from "./binding-BSPfNZju-CRI85Wi0.mjs";
|
|
4
|
-
import { n as validatePostgresContract } from "./contract-from-json-
|
|
5
|
-
import { n as buildPostgresStaticContext, t as buildNamespacedNativeEnums } from "./postgres-static-
|
|
4
|
+
import { n as validatePostgresContract } from "./contract-from-json-DoE5soiA-DAvpjAkO.mjs";
|
|
5
|
+
import { n as buildPostgresStaticContext, t as buildNamespacedNativeEnums } from "./postgres-static-BSikEOb5-CrYnN7HO.mjs";
|
|
6
6
|
import { n as buildPostgresRuntimeBoundMembers } from "./postgres-members-CRPX0rhb-C0keDjWe.mjs";
|
|
7
7
|
import { t as PostgresRuntimeImpl } from "./postgres-runtime-BKdag6p9-gHVB2jfC.mjs";
|
|
8
8
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/runtime.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { i as validateTransactionOptions, n as toDriverCursorOptions, r as validateCursorOptions } from \"./postgres-options-CZyV9Him.mjs\";\nimport { a as resolveOptionalPostgresBinding, i as postgresBindingRules, n as isPgClient, o as resolvePostgresBinding, r as isPgPool, t as connectWithBinding } from \"./binding-BSPfNZju.mjs\";\nimport { r as buildNamespacedNativeEnums, t as buildPostgresStaticContext } from \"./postgres-static-
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/runtime.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { i as validateTransactionOptions, n as toDriverCursorOptions, r as validateCursorOptions } from \"./postgres-options-CZyV9Him.mjs\";\nimport { a as resolveOptionalPostgresBinding, i as postgresBindingRules, n as isPgClient, o as resolvePostgresBinding, r as isPgPool, t as connectWithBinding } from \"./binding-BSPfNZju.mjs\";\nimport { r as buildNamespacedNativeEnums, t as buildPostgresStaticContext } from \"./postgres-static-BSikEOb5.mjs\";\nimport { n as validatePostgresContract } from \"./contract-from-json-DoE5soiA.mjs\";\nimport { n as buildPostgresRuntimeBoundMembers } from \"./postgres-members-CRPX0rhb.mjs\";\nimport { t as PostgresRuntimeImpl } from \"./postgres-runtime-BKdag6p9.mjs\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport postgresTarget, { postgresIsolationLevels as IsolationLevel } from \"@internal/target-postgres/runtime\";\nimport postgresDriver from \"@internal/driver-postgres/runtime\";\nimport postgresAdapter from \"@internal/adapter-postgres/runtime\";\nimport { createExecutionContext, createSqlExecutionStack, toRuntimeOptions } from \"@internal/sql-runtime\";\n//#region src/runtime/postgres.ts\n/**\n* Creates a lazy Postgres 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 static query surfaces are available\n* at once; the pool is created on the first query or `connect()`.\n*\n* @example\n* ```ts\n* import { contractFromJson } from '@prisma/orm-postgres/static';\n* import postgres from '@prisma/orm-postgres/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 = postgres({ contract, url: process.env['DATABASE_URL']! });\n* ```\n*/\nfunction postgres(options) {\n\tconst cursor = validateCursorOptions(options.cursor, \"postgres\");\n\tconst transactionOptions = validateTransactionOptions(options.transactionOptions);\n\tconst contract = validatePostgresContract(options.contract);\n\tlet binding = resolveOptionalPostgresBinding(options, postgresBindingRules);\n\tconst stack = createSqlExecutionStack({\n\t\ttarget: postgresTarget,\n\t\tadapter: postgresAdapter,\n\t\tdriver: postgresDriver,\n\t\textensions: options.extensions ?? []\n\t});\n\tconst context = createExecutionContext({\n\t\tcontract,\n\t\tstack,\n\t\tdriver: postgresDriver\n\t});\n\tconst { sql, raw: rawSqlTag, enums, nativeEnums, toSql } = buildPostgresStaticContext(contract, context, stack);\n\tlet runtimeInstance;\n\tlet runtimeDriver;\n\tlet driverConnected = false;\n\tlet connectPromise;\n\tlet backgroundConnectError;\n\tlet closePromise;\n\tconst closedError = () => postgresError(\"DRIVER.NOT_CONNECTED\", \"Postgres client is closed\", {\n\t\twhy: \"close() was called on this client.\",\n\t\tfix: \"Create a new postgres(...) client.\",\n\t\tmeta: { extension: \"postgres\" }\n\t});\n\tconst connectDriver = async (resolvedBinding) => {\n\t\tif (driverConnected) return;\n\t\tif (!runtimeDriver) throw new InternalError(\"Postgres runtime driver missing\");\n\t\tif (connectPromise) return connectPromise;\n\t\tconnectPromise = connectWithBinding(runtimeDriver, resolvedBinding, options).then(() => {\n\t\t\tdriverConnected = true;\n\t\t}).catch((err) => {\n\t\t\tbackgroundConnectError = err;\n\t\t\tconnectPromise = void 0;\n\t\t\tthrow err;\n\t\t});\n\t\treturn connectPromise;\n\t};\n\tconst getRuntime = () => {\n\t\tif (closePromise !== void 0) throw closedError();\n\t\tif (backgroundConnectError !== void 0) throw backgroundConnectError;\n\t\tif (runtimeInstance) return runtimeInstance;\n\t\tconst adapter = stack.adapter.create(stack);\n\t\tconst driver = stack.driver.create({ cursor: toDriverCursorOptions(cursor) });\n\t\truntimeDriver = driver;\n\t\tconst runtime = new PostgresRuntimeImpl({\n\t\t\tcontext,\n\t\t\tadapter,\n\t\t\tdriver,\n\t\t\t...toRuntimeOptions(options),\n\t\t\tcloseRefusal: \"at-once\"\n\t\t});\n\t\truntimeInstance = runtime;\n\t\tif (binding !== void 0) connectDriver(binding).catch(() => void 0);\n\t\treturn runtime;\n\t};\n\tconst closeRuntime = async () => {\n\t\tif (!driverConnected) await connectPromise?.catch(() => void 0);\n\t\tawait runtimeInstance?.close();\n\t};\n\treturn {\n\t\tsql,\n\t\t...buildPostgresRuntimeBoundMembers({\n\t\t\tcontext,\n\t\t\tcollections: options.collections,\n\t\t\tsql,\n\t\t\traw: rawSqlTag,\n\t\t\tenums,\n\t\t\tnativeEnums,\n\t\t\ttoSql,\n\t\t\tgetRuntime,\n\t\t\tgetRuntimeForWork: getRuntime,\n\t\t\ttransactionOptions\n\t\t}),\n\t\tenums,\n\t\tnativeEnums,\n\t\traw: rawSqlTag,\n\t\ttoSql,\n\t\tcontext,\n\t\tcontract,\n\t\tstack,\n\t\tasync connect(bindingInput) {\n\t\t\tif (closePromise !== void 0) throw closedError();\n\t\t\tif (driverConnected || connectPromise) {\n\t\t\t\tif (bindingInput !== void 0) throw postgresError(\"DRIVER.ALREADY_CONNECTED\", \"Postgres 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\tmeta: { extension: \"postgres\" }\n\t\t\t\t});\n\t\t\t\tconst runtime = getRuntime();\n\t\t\t\tawait connectPromise;\n\t\t\t\tif (closePromise !== void 0) throw closedError();\n\t\t\t\treturn runtime;\n\t\t\t}\n\t\t\tif (bindingInput !== void 0) binding = resolvePostgresBinding(bindingInput);\n\t\t\tif (binding === void 0) throw postgresError(\"RUNTIME.BINDING_MISSING\", \"Postgres binding not configured. Pass url/pg/binding to postgres(...) or call db.connect({ ... }).\", { meta: { extension: \"postgres\" } });\n\t\t\tconst runtime = getRuntime();\n\t\t\tif (driverConnected) return runtime;\n\t\t\tawait connectDriver(binding);\n\t\t\tif (closePromise !== void 0) throw closedError();\n\t\t\treturn runtime;\n\t\t},\n\t\tclose() {\n\t\t\tclosePromise ??= closeRuntime();\n\t\t\treturn closePromise;\n\t\t},\n\t\t[Symbol.asyncDispose]() {\n\t\t\treturn this.close();\n\t\t}\n\t};\n}\n//#endregion\nexport { IsolationLevel, PostgresRuntimeImpl, buildNamespacedNativeEnums, postgres as default, isPgClient, isPgPool };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAS,SAAS,SAAS;CAC1B,MAAM,SAAS,sBAAsB,QAAQ,QAAQ,UAAU;CAC/D,MAAM,qBAAqB,2BAA2B,QAAQ,kBAAkB;CAChF,MAAM,WAAW,yBAAyB,QAAQ,QAAQ;CAC1D,IAAI,UAAU,+BAA+B,SAAS,oBAAoB;CAC1E,MAAM,QAAQ,wBAAwB;EACrC,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,YAAY,QAAQ,cAAc,CAAC;CACpC,CAAC;CACD,MAAM,UAAU,uBAAuB;EACtC;EACA;EACA,QAAQ;CACT,CAAC;CACD,MAAM,EAAE,KAAK,KAAK,WAAW,OAAO,aAAa,UAAU,2BAA2B,UAAU,SAAS,KAAK;CAC9G,IAAI;CACJ,IAAI;CACJ,IAAI,kBAAkB;CACtB,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM,oBAAoB,cAAc,wBAAwB,6BAA6B;EAC5F,KAAK;EACL,KAAK;EACL,MAAM,EAAE,WAAW,WAAW;CAC/B,CAAC;CACD,MAAM,gBAAgB,OAAO,oBAAoB;EAChD,IAAI,iBAAiB;EACrB,IAAI,CAAC,eAAe,MAAM,IAAI,cAAc,iCAAiC;EAC7E,IAAI,gBAAgB,OAAO;EAC3B,iBAAiB,mBAAmB,eAAe,iBAAiB,OAAO,CAAC,CAAC,WAAW;GACvF,kBAAkB;EACnB,CAAC,CAAC,CAAC,OAAO,QAAQ;GACjB,yBAAyB;GACzB,iBAAiB,KAAK;GACtB,MAAM;EACP,CAAC;EACD,OAAO;CACR;CACA,MAAM,mBAAmB;EACxB,IAAI,iBAAiB,KAAK,GAAG,MAAM,YAAY;EAC/C,IAAI,2BAA2B,KAAK,GAAG,MAAM;EAC7C,IAAI,iBAAiB,OAAO;EAC5B,MAAM,UAAU,MAAM,QAAQ,OAAO,KAAK;EAC1C,MAAM,SAAS,MAAM,OAAO,OAAO,EAAE,QAAQ,sBAAsB,MAAM,EAAE,CAAC;EAC5E,gBAAgB;EAChB,MAAM,UAAU,IAAI,oBAAoB;GACvC;GACA;GACA;GACA,GAAG,iBAAiB,OAAO;GAC3B,cAAc;EACf,CAAC;EACD,kBAAkB;EAClB,IAAI,YAAY,KAAK,GAAG,cAAc,OAAO,CAAC,CAAC,YAAY,KAAK,CAAC;EACjE,OAAO;CACR;CACA,MAAM,eAAe,YAAY;EAChC,IAAI,CAAC,iBAAiB,MAAM,gBAAgB,YAAY,KAAK,CAAC;EAC9D,MAAM,iBAAiB,MAAM;CAC9B;CACA,OAAO;EACN;EACA,GAAG,iCAAiC;GACnC;GACA,aAAa,QAAQ;GACrB;GACA,KAAK;GACL;GACA;GACA;GACA;GACA,mBAAmB;GACnB;EACD,CAAC;EACD;EACA;EACA,KAAK;EACL;EACA;EACA;EACA;EACA,MAAM,QAAQ,cAAc;GAC3B,IAAI,iBAAiB,KAAK,GAAG,MAAM,YAAY;GAC/C,IAAI,mBAAmB,gBAAgB;IACtC,IAAI,iBAAiB,KAAK,GAAG,MAAM,cAAc,4BAA4B,oCAAoC;KAChH,KAAK;KACL,KAAK;KACL,MAAM,EAAE,WAAW,WAAW;IAC/B,CAAC;IACD,MAAM,UAAU,WAAW;IAC3B,MAAM;IACN,IAAI,iBAAiB,KAAK,GAAG,MAAM,YAAY;IAC/C,OAAO;GACR;GACA,IAAI,iBAAiB,KAAK,GAAG,UAAU,uBAAuB,YAAY;GAC1E,IAAI,YAAY,KAAK,GAAG,MAAM,cAAc,2BAA2B,sGAAsG,EAAE,MAAM,EAAE,WAAW,WAAW,EAAE,CAAC;GAChN,MAAM,UAAU,WAAW;GAC3B,IAAI,iBAAiB,OAAO;GAC5B,MAAM,cAAc,OAAO;GAC3B,IAAI,iBAAiB,KAAK,GAAG,MAAM,YAAY;GAC/C,OAAO;EACR;EACA,QAAQ;GACP,iBAAiB,aAAa;GAC9B,OAAO;EACR;EACA,CAAC,OAAO,gBAAgB;GACvB,OAAO,KAAK,MAAM;EACnB;CACD;AACD"}
|
package/dist/serverless.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as postgresError } from "./errors-DfWK9xep-CB07krZF.mjs";
|
|
2
2
|
import { i as validateTransactionOptions, n as toDriverCursorOptions, r as validateCursorOptions, t as DEFAULT_CONNECT_TIMEOUT_MILLIS } from "./postgres-options-CZyV9Him-2OSYJKqo.mjs";
|
|
3
3
|
import { s as validatePostgresUrl } from "./binding-BSPfNZju-CRI85Wi0.mjs";
|
|
4
|
-
import { n as validatePostgresContract } from "./contract-from-json-
|
|
5
|
-
import { n as buildPostgresStaticContext } from "./postgres-static-
|
|
4
|
+
import { n as validatePostgresContract } from "./contract-from-json-DoE5soiA-DAvpjAkO.mjs";
|
|
5
|
+
import { n as buildPostgresStaticContext } from "./postgres-static-BSikEOb5-CrYnN7HO.mjs";
|
|
6
6
|
import { n as buildPostgresRuntimeBoundMembers } from "./postgres-members-CRPX0rhb-C0keDjWe.mjs";
|
|
7
7
|
import { t as PostgresRuntimeImpl } from "./postgres-runtime-BKdag6p9-gHVB2jfC.mjs";
|
|
8
8
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
package/dist/serverless.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverless.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/serverless.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { i as validateTransactionOptions, n as toDriverCursorOptions, r as validateCursorOptions, t as DEFAULT_CONNECT_TIMEOUT_MILLIS } from \"./postgres-options-CZyV9Him.mjs\";\nimport { s as validatePostgresUrl } from \"./binding-BSPfNZju.mjs\";\nimport { t as buildPostgresStaticContext } from \"./postgres-static-
|
|
1
|
+
{"version":3,"file":"serverless.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/serverless.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { i as validateTransactionOptions, n as toDriverCursorOptions, r as validateCursorOptions, t as DEFAULT_CONNECT_TIMEOUT_MILLIS } from \"./postgres-options-CZyV9Him.mjs\";\nimport { s as validatePostgresUrl } from \"./binding-BSPfNZju.mjs\";\nimport { t as buildPostgresStaticContext } from \"./postgres-static-BSikEOb5.mjs\";\nimport { n as validatePostgresContract } from \"./contract-from-json-DoE5soiA.mjs\";\nimport { n as buildPostgresRuntimeBoundMembers } from \"./postgres-members-CRPX0rhb.mjs\";\nimport { t as PostgresRuntimeImpl } from \"./postgres-runtime-BKdag6p9.mjs\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport postgresTarget, { postgresIsolationLevels as IsolationLevel } from \"@internal/target-postgres/runtime\";\nimport postgresDriver, { createPgClient, suppressIdleConnectionErrors } from \"@internal/driver-postgres/runtime\";\nimport postgresAdapter from \"@internal/adapter-postgres/runtime\";\nimport { createExecutionContext, createSqlExecutionStack, toRuntimeOptions } from \"@internal/sql-runtime\";\nimport { redactDatabaseUrl } from \"@internal/utils/redact-db-url\";\n//#region src/runtime/postgres-serverless.ts\nfunction closedConnectionError() {\n\treturn postgresError(\"DRIVER.NOT_CONNECTED\", \"Postgres connection is closed\", {\n\t\twhy: \"close() was called on this connection, or the await using scope that held it has ended.\",\n\t\tfix: \"Call connect({ url }) again to open a new connection.\",\n\t\tmeta: { extension: \"postgres\" }\n\t});\n}\nfunction connectionFailedError(url, cause) {\n\treturn postgresError(\"DRIVER.CONNECTION_FAILED\", \"Database connection failed\", {\n\t\twhy: cause instanceof Error ? cause.message : String(cause),\n\t\tfix: \"Verify the database URL, ensure the database is reachable, and confirm credentials/permissions\",\n\t\tmeta: {\n\t\t\textension: \"postgres\",\n\t\t\t...redactDatabaseUrl(url)\n\t\t},\n\t\tcause\n\t});\n}\n/**\n* Creates a serverless client for serverless and edge runtimes (Cloudflare Workers + Hyperdrive,\n* AWS Lambda, Vercel, Deno Deploy).\n*\n* The serverless client holds no database connection and has the static members. Each\n* `connect({ url })` opens one database connection, a fresh `pg.Client`, and returns a connection\n* with the members of a `postgres()` client except `connect`. It rejects with\n* `DRIVER.CONNECTION_FAILED` when the database refuses the connection, rejects the credentials,\n* or does not answer within 20 seconds. Close the connection with `await using` or `close()`.\n*\n* The client infers its contract type from `contract` and validates it once, when the client is\n* created; connections reuse it.\n*\n* @example\n* ```ts\n* const postgres = postgresServerless({ contract: contractFromJson<Contract>(contractJson) });\n*\n* export default {\n* async fetch(_req: Request, env: Env): Promise<Response> {\n* await using db = await postgres.connect({ url: env.HYPERDRIVE.connectionString });\n* const users = await db.orm.public.User.all();\n* return Response.json(users);\n* },\n* };\n* ```\n*/\nfunction postgresServerless(options) {\n\tconst cursor = validateCursorOptions(options.cursor, \"postgresServerless\");\n\tconst transactionOptions = validateTransactionOptions(options.transactionOptions);\n\tconst contract = validatePostgresContract(options.contract);\n\tconst stack = createSqlExecutionStack({\n\t\ttarget: postgresTarget,\n\t\tadapter: postgresAdapter,\n\t\tdriver: postgresDriver,\n\t\textensions: options.extensions ?? []\n\t});\n\tconst context = createExecutionContext({\n\t\tcontract,\n\t\tstack,\n\t\tdriver: postgresDriver\n\t});\n\tconst { sql, raw, enums, nativeEnums, toSql } = buildPostgresStaticContext(contract, context, stack);\n\tconst buildRuntimeBoundMembers = (getRuntime, getRuntimeForWork) => buildPostgresRuntimeBoundMembers({\n\t\tcontext,\n\t\tcollections: options.collections,\n\t\tsql,\n\t\traw,\n\t\tenums,\n\t\tnativeEnums,\n\t\ttoSql,\n\t\tgetRuntime,\n\t\tgetRuntimeForWork,\n\t\ttransactionOptions\n\t});\n\tconst noRuntime = () => {\n\t\tthrow new InternalError(\"The serverless client has no runtime\");\n\t};\n\tbuildRuntimeBoundMembers(noRuntime, noRuntime);\n\tconst createConnection = (runtime) => {\n\t\tlet closing;\n\t\tconst close = () => {\n\t\t\tclosing ??= runtime.close();\n\t\t\treturn closing;\n\t\t};\n\t\tconst runtimeBoundMembers = buildRuntimeBoundMembers(() => {\n\t\t\tif (closing !== void 0) throw closedConnectionError();\n\t\t\treturn runtime;\n\t\t}, () => runtime);\n\t\treturn {\n\t\t\tsql,\n\t\t\traw,\n\t\t\tenums,\n\t\t\tnativeEnums,\n\t\t\ttoSql,\n\t\t\tcontext,\n\t\t\tcontract,\n\t\t\tstack,\n\t\t\t...runtimeBoundMembers,\n\t\t\tclose,\n\t\t\t[Symbol.asyncDispose]: close\n\t\t};\n\t};\n\treturn {\n\t\tsql,\n\t\traw,\n\t\tenums,\n\t\tnativeEnums,\n\t\ttoSql,\n\t\tcontext,\n\t\tstack,\n\t\tcontract,\n\t\tasync connect(binding) {\n\t\t\tconst url = validatePostgresUrl(binding.url);\n\t\t\tconst driverDescriptor = stack.driver;\n\t\t\tconst adapter = stack.adapter.create(stack);\n\t\t\tconst driver = driverDescriptor.create({ cursor: toDriverCursorOptions(cursor) });\n\t\t\tconst pgClient = suppressIdleConnectionErrors(createPgClient({\n\t\t\t\tconnectionString: url,\n\t\t\t\tconnectionTimeoutMillis: DEFAULT_CONNECT_TIMEOUT_MILLIS\n\t\t\t}, stack.target.sessionSettings ?? {}));\n\t\t\tawait driver.connect({\n\t\t\t\tkind: \"pgClient\",\n\t\t\t\tclient: pgClient,\n\t\t\t\townedByDriver: true\n\t\t\t});\n\t\t\tconst runtime = new PostgresRuntimeImpl({\n\t\t\t\tcontext,\n\t\t\t\tadapter,\n\t\t\t\tdriver,\n\t\t\t\t...toRuntimeOptions(options),\n\t\t\t\tcloseRefusal: \"when-idle\"\n\t\t\t});\n\t\t\tconst connection = createConnection(runtime);\n\t\t\ttry {\n\t\t\t\tawait (await driver.acquireConnection()).release();\n\t\t\t} catch (err) {\n\t\t\t\tawait driver.close().catch(() => void 0);\n\t\t\t\tthrow connectionFailedError(url, err);\n\t\t\t}\n\t\t\treturn connection;\n\t\t}\n\t};\n}\n//#endregion\nexport { IsolationLevel, postgresServerless as default };\n\n//# sourceMappingURL=serverless.mjs.map"],"mappings":";;;;;;;;;;;;;;AAcA,SAAS,wBAAwB;CAChC,OAAO,cAAc,wBAAwB,iCAAiC;EAC7E,KAAK;EACL,KAAK;EACL,MAAM,EAAE,WAAW,WAAW;CAC/B,CAAC;AACF;AACA,SAAS,sBAAsB,KAAK,OAAO;CAC1C,OAAO,cAAc,4BAA4B,8BAA8B;EAC9E,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAC1D,KAAK;EACL,MAAM;GACL,WAAW;GACX,GAAG,kBAAkB,GAAG;EACzB;EACA;CACD,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,mBAAmB,SAAS;CACpC,MAAM,SAAS,sBAAsB,QAAQ,QAAQ,oBAAoB;CACzE,MAAM,qBAAqB,2BAA2B,QAAQ,kBAAkB;CAChF,MAAM,WAAW,yBAAyB,QAAQ,QAAQ;CAC1D,MAAM,QAAQ,wBAAwB;EACrC,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,YAAY,QAAQ,cAAc,CAAC;CACpC,CAAC;CACD,MAAM,UAAU,uBAAuB;EACtC;EACA;EACA,QAAQ;CACT,CAAC;CACD,MAAM,EAAE,KAAK,KAAK,OAAO,aAAa,UAAU,2BAA2B,UAAU,SAAS,KAAK;CACnG,MAAM,4BAA4B,YAAY,sBAAsB,iCAAiC;EACpG;EACA,aAAa,QAAQ;EACrB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC;CACD,MAAM,kBAAkB;EACvB,MAAM,IAAI,cAAc,sCAAsC;CAC/D;CACA,yBAAyB,WAAW,SAAS;CAC7C,MAAM,oBAAoB,YAAY;EACrC,IAAI;EACJ,MAAM,cAAc;GACnB,YAAY,QAAQ,MAAM;GAC1B,OAAO;EACR;EACA,MAAM,sBAAsB,+BAA+B;GAC1D,IAAI,YAAY,KAAK,GAAG,MAAM,sBAAsB;GACpD,OAAO;EACR,SAAS,OAAO;EAChB,OAAO;GACN;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,GAAG;GACH;IACC,OAAO,eAAe;EACxB;CACD;CACA,OAAO;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAM,QAAQ,SAAS;GACtB,MAAM,MAAM,oBAAoB,QAAQ,GAAG;GAC3C,MAAM,mBAAmB,MAAM;GAC/B,MAAM,UAAU,MAAM,QAAQ,OAAO,KAAK;GAC1C,MAAM,SAAS,iBAAiB,OAAO,EAAE,QAAQ,sBAAsB,MAAM,EAAE,CAAC;GAChF,MAAM,WAAW,6BAA6B,eAAe;IAC5D,kBAAkB;IAClB,yBAAyB;GAC1B,GAAG,MAAM,OAAO,mBAAmB,CAAC,CAAC,CAAC;GACtC,MAAM,OAAO,QAAQ;IACpB,MAAM;IACN,QAAQ;IACR,eAAe;GAChB,CAAC;GACD,MAAM,UAAU,IAAI,oBAAoB;IACvC;IACA;IACA;IACA,GAAG,iBAAiB,OAAO;IAC3B,cAAc;GACf,CAAC;GACD,MAAM,aAAa,iBAAiB,OAAO;GAC3C,IAAI;IACH,OAAO,MAAM,OAAO,kBAAkB,EAAA,CAAG,QAAQ;GAClD,SAAS,KAAK;IACb,MAAM,OAAO,MAAM,CAAC,CAAC,YAAY,KAAK,CAAC;IACvC,MAAM,sBAAsB,KAAK,GAAG;GACrC;GACA,OAAO;EACR;CACD;AACD"}
|
package/dist/static.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as contractFromJson } from "./contract-from-json-
|
|
2
|
-
import { r as postgresStatic } from "./postgres-static-
|
|
1
|
+
import { t as contractFromJson } from "./contract-from-json-DoE5soiA-DAvpjAkO.mjs";
|
|
2
|
+
import { r as postgresStatic } from "./postgres-static-BSikEOb5-CrYnN7HO.mjs";
|
|
3
3
|
export { contractFromJson, postgresStatic as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/orm-postgres",
|
|
3
|
-
"version": "8.0.0-rc.24-dev.
|
|
3
|
+
"version": "8.0.0-rc.24-dev.44",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"skills"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@prisma/orm-family-sql": "8.0.0-rc.24-dev.
|
|
17
|
-
"@prisma/orm-framework": "8.0.0-rc.24-dev.
|
|
18
|
-
"@prisma/orm-target-postgres": "8.0.0-rc.24-dev.
|
|
19
|
-
"@prisma/orm-toolchain": "8.0.0-rc.24-dev.
|
|
16
|
+
"@prisma/orm-family-sql": "8.0.0-rc.24-dev.44",
|
|
17
|
+
"@prisma/orm-framework": "8.0.0-rc.24-dev.44",
|
|
18
|
+
"@prisma/orm-target-postgres": "8.0.0-rc.24-dev.44",
|
|
19
|
+
"@prisma/orm-toolchain": "8.0.0-rc.24-dev.44",
|
|
20
20
|
"@types/node": "26.1.2",
|
|
21
21
|
"arktype": "^2.2.9",
|
|
22
22
|
"pathe": "^2.0.3",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"tinyglobby": "^0.2.17"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@internal/postgres": "8.0.0-rc.24-dev.
|
|
29
|
-
"@repo/tsconfig": "8.0.0-rc.24-dev.
|
|
30
|
-
"@repo/tsdown": "8.0.0-rc.24-dev.
|
|
28
|
+
"@internal/postgres": "8.0.0-rc.24-dev.44",
|
|
29
|
+
"@repo/tsconfig": "8.0.0-rc.24-dev.44",
|
|
30
|
+
"@repo/tsdown": "8.0.0-rc.24-dev.44",
|
|
31
31
|
"tsdown": "0.22.14",
|
|
32
32
|
"typescript": "5.9.3"
|
|
33
33
|
},
|
package/skills/prisma-8/SKILL.md
CHANGED
|
@@ -104,10 +104,10 @@ The single source of truth: read the envelope, find the row by `code`, follow th
|
|
|
104
104
|
| `DRIVER.NOT_CONNECTED` with message `Runtime is closed` | A query, prepared statement or `db.runtime().connection()` that starts after `db.close()` and after the runtime was idle for one turn of the event loop, or after the `await using` scope that held a serverless connection ended | The work started after the runtime closed. Almost always it is a lazy read (`db.orm...all()`, `db.query(...)`) returned without `await`, which starts only when the caller awaits it, or work that waited on something other than the database first. Write `return await ...`, or move the call before `close()`. See `references/runtime.md` § *Workflow — Serverless and per-request runtimes*. |
|
|
105
105
|
| `await db.close()` or the end of an `await using` scope never settles in a test | A test that installed fake timers (`vi.useFakeTimers()`, Jest's modern fake timers) before the Prisma runtime module was imported | `close()` waits one turn of the event loop through a `setTimeout(0)` that the runtime module takes when it loads. Install fake timers after the imports, or advance the fake clock (`await vi.runAllTimersAsync()`) before awaiting the close. |
|
|
106
106
|
| `MIGRATION.MARKER_MISMATCH` | `db migrate`, `db migrate --show`, a Composer deploy | The database's marker is not in the migration graph, usually because a migration it applied was planned again or deleted. `why` names the last graph contract it applied and the missing migrations. `nextActions` gives the one recovery the database's change policy permits. Follow `references/migrations.md` § *A database whose marker is not in the migration graph*. Never reset or drop the database. |
|
|
107
|
-
| `MIGRATION.CHANGE_POLICY_FORBIDS` | `db update`, `db sign`, `db migrate` | The database's change policy does not include what the command does. When `db update` or `db sign` is refused, author
|
|
107
|
+
| `MIGRATION.CHANGE_POLICY_FORBIDS` | `db update`, `db sign`, `db migrate` | The database's change policy does not include what the command does. When `db update` or `db sign` is refused, follow its advice: apply the migrations on disk that already lead to the target with `db migrate`, or author one (with `migration plan`, or with `migration new` when the database is already at the target and lacks only invariants) and apply it with `db migrate`. See `references/migrations.md` § *Policies*. |
|
|
108
108
|
| `MIGRATION.DATA_PROTECTION_FORBIDS` | `db update`, `db migrate`, `migration plan --to <ref>`, a Composer deploy | The database's data protection policy (or the ref's, for `migration plan --to <ref>` and a run given `--permit-policy-change`) forbids an operation that loses data or changes who can read or write rows. `meta.operations` lists them. The operation cannot run on that database. For `db update` and `migration plan`, a refused data loss: state a `--rename` if it was only a rename, plan a type change with `migration plan --convert`, or keep the model or field. A refused access change: keep the contract's access rules as they are. For `db migrate`, first find out whether another database has applied the refused migration; if one has, keep it as it is. If none has, delete it and every later migration no database has applied, and plan once from where the first one started, with `--rename`, `--convert`, or after putting back in the contract what it removes; never only take the operation out of the migration. The full steps (saving hand-written operations, `--from`, `contract emit`, moving refs) are in `references/migrations.md` § *Policies*. For `db migrate` and `db update`, an operation in an extension's contract space belongs to the extension: do not edit or delete its migration; ask the extension's author for a version without the operation, or have the database's owner change the policy. `--delete` and `--allow` do not help, and never loosen the policy to make a deploy pass. See `references/migrations.md` § *Policies*. |
|
|
109
109
|
| `MIGRATION.POLICY_MISMATCH` | `db migrate --to <ref>`, `db update --to <ref>`, a Composer deploy | The ref declares a policy that differs from the database's. Fix the ref, or have the database's owner apply the change. Never loosen a policy to make a deploy pass. See `references/migrations.md` § *Policies*. |
|
|
110
|
-
| `MIGRATION.PATH_UNREACHABLE` | `db migrate`, a Composer deploy | The marker is in the graph but no migration reaches the target from it. Run the two commands the error prints: a `migration plan --from <
|
|
110
|
+
| `MIGRATION.PATH_UNREACHABLE` | `db migrate`, a Composer deploy | The marker is in the graph but no migration reaches the target from it. Run the two commands the error prints: a `migration plan --from <contract>`, with `--to <target>` unless the target is the emitted contract (a contract change emitted but not planned), then the `db migrate` that was run, with its flags. To the emitted contract, `--from` is where the history that continues from the marker ends, so the new migration extends the history instead of forking it; to any other target it is the marker. On an empty database, `--from` is where the migration history ends. When the history has more than one end, the error names each end for you to choose from. A database with no marker in a project with no migrations gets the plan from `@empty` as a choice: run it only on an empty database, and adopt one that already has tables with `db sign` first. When the path ends at the empty contract (`--to @empty`), or the project has migrations and the path starts at a contract none of them records, no plan can author it, and the error prints only `migration list`. In a project with no migrations yet, the plan starts from the ref that names the database's contract, and with no such ref the error prints no plan and says why. When an extension space has no path, the error says to install a version of the extension whose migrations start where the database is. `migration list` audits the graph. |
|
|
111
111
|
| `MIGRATION.PLAN_ORIGIN_UNKNOWN` / `MIGRATION.HASH_NOT_IN_GRAPH` / `MIGRATION.SNAPSHOT_MISSING` | `migration plan`, `migration new` | Origin resolution — `references/migration-model.md` § *The trap* and `references/migrations.md` § *Dev → ship transition*. |
|
|
112
112
|
| `MIGRATION.MISSING_INVARIANTS` | `migration status` `warn` diagnostic (exit 0) | The live marker reached the destination hash structurally but doesn't carry all invariants the target ref requires. Run `db migrate --to <name> --db $URL` to take a path that covers the missing invariants. See `references/migration-review.md`. |
|
|
113
113
|
| `MIGRATION.MARKER_NOT_IN_HISTORY` / `CONTRACT.UNREADABLE` | `migration status` `warn` diagnostics (exit 0) | Read `severity` *and* `code`. Up-to-date / pending / no-marker states are not codes — read `spaces[].currentContract` and `migrations[].status` in the `--json` document. `references/migration-review.md` covers the marker-out-of-history flow. |
|
|
@@ -60,8 +60,7 @@ pnpm prisma migration ref delete <name>
|
|
|
60
60
|
|---|---|
|
|
61
61
|
| `db init` / `db update` (default URL) | Implicitly advance `db` (override the name with `--advance-ref <name>`; suppressed whenever `--db` is passed without `--advance-ref`, regardless of the URL — even `--db $DATABASE_URL` pointing at the default database) |
|
|
62
62
|
| `db sign` | Advances `db` after a successful signature (override the name with `--advance-ref <name>`; `--no-advance-ref` skips it, writing no ref and no snapshot); an existing ref is overwritten and the previous hash is reported in the human output (the JSON `advancedRefs` lists `{ space, name, hash }` for each contract space it advanced). `--db` does **not** suppress it, unlike init/update: sign never mutates the schema, and adoption is normally done via `--db` |
|
|
63
|
-
| `db migrate
|
|
64
|
-
| plain `db migrate` | **Never advances anything** — deliberate: deploy and CI applies must not infer dev intent |
|
|
63
|
+
| `db migrate` | Advances `db` after a successful apply when the connection comes from `prisma.config.ts` and the CLI does not detect CI. Never with `--db`, and never in CI (unless the `CI` environment variable is `false`, which turns detection off whatever else is set, the CLI detects CI when `CI` is set or when a variable that CI services set is present, such as `BUILD_NUMBER`, `BUILD_ID` or `GITHUB_ACTIONS`; the run then reports `MIGRATION.REF_NOT_ADVANCED_IN_CI`), so deploys and pipelines write no ref. `--advance-ref <name>` advances that ref instead, in every case; `--no-advance-ref` advances none. A run that ends at the empty contract, which a ref cannot name, leaves `db` unchanged and, when `db` exists and the run passes neither `--db` nor `--no-advance-ref`, warns (`MIGRATION.REF_NOT_ADVANCED_TO_EMPTY`; when that database is your development database, remove the stale ref with `migration ref delete db`), and refuses an explicit `--advance-ref` before applying. A ref that cannot be written is a warning (`MIGRATION.REF_NOT_WRITTEN`), not a failure: the migrations have already applied |
|
|
65
64
|
| `migration plan` | Never advances anything — chaining discipline is yours |
|
|
66
65
|
| deploys (Composer / CD) | Write the database's marker; structurally cannot and do not touch repo refs |
|
|
67
66
|
|
|
@@ -87,7 +86,7 @@ The human output names the resolved origin on its `from:` line. **`from: (baseli
|
|
|
87
86
|
|
|
88
87
|
**A plan whose origin is the empty contract while migrations already exist on disk is almost always a mistake.** A full-create migration cannot do what you meant: a database that has the prior migrations applied refuses it (`MIGRATION.PATH_UNREACHABLE` — no path from its marker to the new plan's destination), and running its create statements against any populated schema fails outright. The CLI refuses this at plan time: when origin resolution falls all the way through (no `--from`, no `db` ref) and migrations exist, `migration plan` stops with `MIGRATION.PLAN_ORIGIN_UNKNOWN` instead of writing the package — the error's suggestions are the three exits below; do not reflexively take the `--from @empty` one, pick by intent.
|
|
89
88
|
|
|
90
|
-
How the fall-through happens: a project
|
|
89
|
+
How the fall-through happens: a project whose only commands run in CI or deploys (the deploy-first path below) never acquires a `db` ref, so *every* default plan resolves to the empty origin. Running the dev loop with an explicit `--db` has the same effect: `db init`, `db update` and `db migrate` with that flag never advance the ref, whatever URL it carries (`db sign` is the exception — it advances the ref with or without `--db`). The first time that is correct (it is the baseline; an empty migration graph plans with only the muted notice); every later time it is the trap the refusal catches.
|
|
91
90
|
|
|
92
91
|
**Recognize a from-empty plan** that was produced anyway (an explicit `--from @empty`, or an older CLI without the refusal), at either layer:
|
|
93
92
|
|
|
@@ -103,20 +102,20 @@ How the fall-through happens: a project that never runs `db init` / `db update`
|
|
|
103
102
|
|
|
104
103
|
## Workflow — the dev loop
|
|
105
104
|
|
|
106
|
-
The concept: while the schema is in flux, iterate the dev database with `db init` / `db update` — they apply the contract *and* keep the `db` ref current. When the shape settles, plan: the plan chains from the ref,
|
|
105
|
+
The concept: while the schema is in flux, iterate the dev database with `db init` / `db update` — they apply the contract *and* keep the `db` ref current. When the shape settles, plan and apply: the plan chains from the ref, the auto-baseline covers the case where the graph is still empty, and `db migrate` on the config's database moves the ref to what it applied.
|
|
107
106
|
|
|
108
107
|
```bash
|
|
109
108
|
pnpm prisma db init # once; advances the db ref
|
|
110
109
|
pnpm prisma contract emit && pnpm prisma db update # iterate; each advances the db ref
|
|
111
110
|
pnpm prisma contract emit && pnpm prisma migration plan --name <slug>
|
|
112
|
-
pnpm prisma db migrate
|
|
111
|
+
pnpm prisma db migrate # applies it; advances the db ref
|
|
113
112
|
```
|
|
114
113
|
|
|
115
|
-
|
|
114
|
+
Full mechanics, refusals, and recovery: `references/migrations.md` § *Dev → ship transition*.
|
|
116
115
|
|
|
117
116
|
## Workflow — the deploy-first loop (Composer / CD-managed databases)
|
|
118
117
|
|
|
119
|
-
The concept: the deploy pipeline owns the databases, so `db init` / `db update` never run and nothing ever advances a `db` ref for you. Deploys replay each database from its marker to the contract emitted at build time; they never write to `migrations/app/refs/`. Two disciplines keep this loop safe:
|
|
118
|
+
The concept: the deploy pipeline owns the databases, so `db init` / `db update` never run, `db migrate` runs only in CI or with `--db`, and nothing ever advances a `db` ref for you. Deploys replay each database from its marker to the contract emitted at build time; they never write to `migrations/app/refs/`. Two disciplines keep this loop safe:
|
|
120
119
|
|
|
121
120
|
**Author the baseline before the first deploy.** Before anything is deployed:
|
|
122
121
|
|
|
@@ -161,11 +160,11 @@ The concept: the database exists and its marker is accurate (hash **M**) — it
|
|
|
161
160
|
## Common Pitfalls
|
|
162
161
|
|
|
163
162
|
1. **Assuming `migration plan` or `migration new` chains from the newest migration on disk.** Neither does. The origin is `--from`, else the `db` ref. With neither, only an empty graph plans from scratch (with the muted `No db ref set` notice); once migrations exist, both commands refuse with `MIGRATION.PLAN_ORIGIN_UNKNOWN`.
|
|
164
|
-
2. **Expecting `migration plan
|
|
163
|
+
2. **Expecting `migration plan`, or `db migrate` with `--db` or in CI, to keep the `db` ref current.** None of them touches refs. `db init`, `db update` and `db migrate` advance `db` only when the connection comes from `prisma.config.ts` (and, for `db migrate`, outside CI); `db sign` advances it even with `--db`. Elsewhere, pass `--advance-ref db`.
|
|
165
164
|
3. **Expecting a deploy to update refs.** Deploys write the database's marker; the files under `migrations/app/refs/` only change when you change them.
|
|
166
165
|
4. **Reading `from: (baseline)` as informational.** Over a non-empty migrations directory it is the trap announcing itself. Stop and pick an exit before applying or committing.
|
|
167
166
|
5. **`migration ref set` with a hash no on-disk migration produces.** A ref target must be the `to` hash of an on-disk migration bundle. A hash outside the graph is refused (`MIGRATION.HASH_NOT_IN_GRAPH`); a from-only graph node is refused with `MIGRATION.REF_SET_BUNDLE_NOT_FOUND`, whose fix text points at fixtures and is unhelpful here. Either way: plan the edge whose `to` is the hash first (baseline or delta), then set the ref.
|
|
168
|
-
6. **Treating `db` as reserved.** It's a naming default. Setting it yourself is fine and sometimes exactly right (deploy-first chaining, retrofit); just expect dev commands on the
|
|
167
|
+
6. **Treating `db` as reserved.** It's a naming default. Setting it yourself is fine and sometimes exactly right (deploy-first chaining, retrofit); just expect dev commands on the config's database (`db init`, `db update`, and `db migrate` outside CI) to overwrite it.
|
|
169
168
|
7. **Authoring the first migration after the first deploy.** Then no graph node corresponds to what shipped, and every incremental path needs the retrofit. Baseline before the first deploy — it's one command.
|
|
170
169
|
|
|
171
170
|
## What Prisma 8 doesn't do yet
|
|
@@ -179,5 +178,5 @@ The concept: the database exists and its marker is accurate (hash **M**) — it
|
|
|
179
178
|
- [ ] In a deploy-first project: baseline authored and committed before the first deploy; every later plan chained via the `db` ref or `--from`.
|
|
180
179
|
- [ ] After each plan in a loop where nothing advances refs: advanced the `db` ref (`migration ref set db <to-hash>`) or resolved to pass `--from` next time.
|
|
181
180
|
- [ ] For a marked database with no on-disk migrations: made the graph reach the marker's hash (auto-baseline via `db update` or `db sign`, or an offline baseline plan) before planning deltas.
|
|
182
|
-
- [ ]
|
|
181
|
+
- [ ] Expected plain `db migrate` to advance `db` only when its connection comes from `prisma.config.ts`, the CLI does not detect CI and neither `--advance-ref` nor `--no-advance-ref` is passed; did NOT expect `migration plan`, `db migrate --db`, or a deploy in CI to advance any ref.
|
|
183
182
|
- [ ] Did NOT apply or commit a `from: (baseline)` plan without confirming the empty origin was the intent.
|
|
@@ -82,7 +82,7 @@ These codes surface on `migration plan`, `migration ref set`, and `db migrate`
|
|
|
82
82
|
| `MIGRATION.HASH_NOT_IN_GRAPH` | `migration plan` (non-empty graph) or `migration ref set` | Resolved hash is not a node in the on-disk migration graph — typical when the default `db` ref points past the graph tip after `db update` cycles. | `migration plan --from <reachable-ref>` (e.g. `--from production`); or realign the ref with `migration ref set db <graph-node-hash>`. |
|
|
83
83
|
| `MIGRATION.SNAPSHOT_MISSING` | `migration plan` | A named ref has no pointer file (`<name>.json`), and the hash being resolved isn't a node in the migration graph either. | `migration ref set <name> <hash>` to create the ref, `db update --advance-ref <name>` to advance it, or pass a hash that is a graph node. |
|
|
84
84
|
| `MIGRATION.MARKER_MISMATCH` | `db migrate` (pre-DDL, before the runner), `db migrate --show` | Live DB marker hash is not a graph node. Usually a migration the database applied was planned again or deleted. | Follow the error's next actions, and `references/migrations.md` § *A database whose marker is not in the migration graph*. Never reset the database. |
|
|
85
|
-
| `MIGRATION.PATH_UNREACHABLE` | `db migrate` (path resolution) | No migration path from the current marker to the resolved target in the on-disk graph. | Read the improved `fix` payload — it names `fromHash` / `targetHash` and prints the `migration plan` and `db migrate` commands to run, with `--to <target>` unless the target is the emitted contract
|
|
85
|
+
| `MIGRATION.PATH_UNREACHABLE` | `db migrate` (path resolution) | No migration path from the current marker to the resolved target in the on-disk graph. | Read the improved `fix` payload — it names `fromHash` / `targetHash` and prints the `migration plan` and `db migrate` commands to run, with `--to <target>` unless the target is the emitted contract. On an empty database the plan starts from where the migration history ends. When the space named is an extension's, it prints no plan command: install a version of the extension whose migrations start from the contract the database is at; run `migration list` to inspect the graph. |
|
|
86
86
|
|
|
87
87
|
## Workflow — *"What's about to run on deploy?"*
|
|
88
88
|
|
|
@@ -81,7 +81,7 @@ Treat the rendered import lines as framework-managed on both targets:
|
|
|
81
81
|
| `CONTRACT.MARKER_MISSING` | `db verify` (finding, exit 4), runtime startup (warning) | The DB has no marker yet. Run `prisma db init --db <url>` to baseline an empty database, `db update --db <url>` to apply the current contract directly, or `db sign --db <url>` if the schema already matches the contract. |
|
|
82
82
|
| `MIGRATION.STATEMENT_INVALID` | `migration plan` / `db update` with `--rename` | The statement is malformed, mixes a model and a field, renames something to itself, swaps two names, or repeats a name. The error's next step is the statement to type instead; use it. |
|
|
83
83
|
| `MIGRATION.STATEMENT_UNRESOLVED` | `migration plan` / `db update` with `--rename` | A name is not where a rename needs it. The error lists the names it found and says what to type: the statement the right way round, the order that works, or to leave out a rename that has already happened. |
|
|
84
|
-
| `MIGRATION.CHANGE_POLICY_FORBIDS` | `db update`, `db sign`, `db migrate` | The database's change policy does not include what the command does (`meta.change` lists what it permits). When `db update` or `db sign` is refused, the database changes only through migrations: author one with `migration plan` and apply it with `db migrate`. Do not look for a way round the policy. |
|
|
84
|
+
| `MIGRATION.CHANGE_POLICY_FORBIDS` | `db update`, `db sign`, `db migrate` | The database's change policy does not include what the command does (`meta.change` lists what it permits). When `db update` or `db sign` is refused, the database changes only through migrations: follow its advice, which says to apply the migrations on disk that already lead to the target with `db migrate`, or to author one (with `migration plan`, or with `migration new` when the database is already at the target and lacks only invariants) and apply it with `db migrate`. Do not look for a way round the policy. |
|
|
85
85
|
| `MIGRATION.POLICY_MISMATCH` | `db migrate --to <ref>`, `db update --to <ref>`, a Composer deploy | The ref declares a policy that differs from the database's (`why` names each setting with both values). Either the ref is wrong, so fix it to match the database, or the database's owner meant to change the policy, which the deploy does only when told it may. Never loosen a policy to make your own deploy pass. See *Policies* below. |
|
|
86
86
|
| `MIGRATION.STATEMENT_ORIGIN_UNKNOWN` | `db update --rename` | `db update` has no snapshot of the contract the database is at. Follow the error's steps: emit that contract, run `db update --advance-ref <name> --dry-run` and check it plans no operations, then run it without `--dry-run` to store its snapshot, then emit the new contract and run the rename. Do not drop the statements to get past it: without them the plan drops the renamed table with its rows. |
|
|
87
87
|
|
|
@@ -102,16 +102,18 @@ Treat the rendered import lines as framework-managed on both targets:
|
|
|
102
102
|
Example — iterate locally with `db update`, then publish the first real migration:
|
|
103
103
|
|
|
104
104
|
```bash
|
|
105
|
-
pnpm prisma db init
|
|
106
|
-
pnpm prisma contract emit && pnpm prisma db update
|
|
105
|
+
pnpm prisma db init
|
|
106
|
+
pnpm prisma contract emit && pnpm prisma db update
|
|
107
107
|
pnpm prisma contract emit && pnpm prisma migration plan --name add_feature
|
|
108
|
-
pnpm prisma db migrate
|
|
109
|
-
pnpm prisma db verify
|
|
108
|
+
pnpm prisma db migrate
|
|
109
|
+
pnpm prisma db verify
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
+
Every command here reaches the database through `db.connection` in `prisma.config.ts`, which is what lets `db init`, `db update` and `db migrate` keep the `db` ref current.
|
|
113
|
+
|
|
112
114
|
The `db` ref is a named pointer at `migrations/app/refs/db.json` — just `{ hash, invariants }`. It records which contract hash the project's dev database has been brought up to — the offline planner's stand-in for "where is my local DB?" without opening a connection at plan time. The contract it names resolves through the shared content-addressed store at `migrations/snapshots/<hex>/contract.json` by that hash, the same store every migration graph node resolves through.
|
|
113
115
|
|
|
114
|
-
**What `db init` / `db update` / `db sign` write.** When run against the project's default `--db` URL (no explicit `--db` flag), `db init` and `db update` implicitly advance the `db` ref: they write-if-absent the post-command contract IR into the snapshot store, then write the ref's pointer. Override the ref name with `--advance-ref <name>`. When you pass `--db <non-default-url>`, ref advancement is suppressed unless `--advance-ref` is explicit — reconciling a different database is not the same as checkpointing this project's dev state. `db sign` also advances the `db` ref after a successful signature, writing the signed contract into the snapshot store first; `--advance-ref <name>` overrides the name, and `--db` does **not** suppress it — sign never mutates the schema, and adoption is normally done against the real database via `--db`. The only opt-out is `--no-advance-ref`, which signs without writing any ref or snapshot — what a CI or deployment pipeline, or a dev checkout re-signing a production database, usually wants.
|
|
116
|
+
**What `db init` / `db update` / `db migrate` / `db sign` write.** When run against the project's default `--db` URL (no explicit `--db` flag), `db init` and `db update` implicitly advance the `db` ref: they write-if-absent the post-command contract IR into the snapshot store, then write the ref's pointer. Override the ref name with `--advance-ref <name>`. When you pass `--db <non-default-url>`, ref advancement is suppressed unless `--advance-ref` is explicit — reconciling a different database is not the same as checkpointing this project's dev state. `db migrate` follows the same rule after a successful apply, with one addition: it advances nothing when the CLI detects CI, so pipelines that read their URL through the config write no ref. Unless the `CI` environment variable is `false`, which turns detection off whatever else is set, the CLI detects CI when `CI` is set or when a variable that CI services set is present, such as `BUILD_NUMBER`, `BUILD_ID` or `GITHUB_ACTIONS`, and the run then reports `MIGRATION.REF_NOT_ADVANCED_IN_CI`. On a developer's machine, a variable in the shell, or in a `.env` file that `prisma.config.ts` loads (for example with `import 'dotenv/config'`), can turn advancement off; that notice says so, and a pipeline silences it with `--no-advance-ref`. A run that brings the database to the empty contract leaves `db` unchanged, because a ref cannot name it; when a `db` ref exists and the run passes neither `--db` nor `--no-advance-ref`, it warns with `MIGRATION.REF_NOT_ADVANCED_TO_EMPTY`, naming the hash `db` still holds (with either flag the ref is left unchanged and there is no warning); when that database is your development database, remove the stale ref with `migration ref delete db`. `--advance-ref <name>` advances that ref instead in every case except a run that ends at the empty contract, which it refuses before applying with `MIGRATION.REF_TARGET_EMPTY`, and `--no-advance-ref` advances none. A ref `db migrate` cannot write, for example on a read-only filesystem, is a warning (`MIGRATION.REF_NOT_WRITTEN`) and the command still exits 0, since the migrations have already applied; its next action is the command that writes it later: `migration ref set` when the snapshot store holds the contract for that hash, and otherwise the same `db migrate` with `--advance-ref <name>`, which applies nothing and writes both. `db sign` also advances the `db` ref after a successful signature, writing the signed contract into the snapshot store first; `--advance-ref <name>` overrides the name, and `--db` does **not** suppress it — sign never mutates the schema, and adoption is normally done against the real database via `--db`. The only opt-out is `--no-advance-ref`, which signs without writing any ref or snapshot — what a CI or deployment pipeline, or a dev checkout re-signing a production database, usually wants.
|
|
115
117
|
|
|
116
118
|
The on-disk layout is just the pointer:
|
|
117
119
|
|
|
@@ -142,7 +144,7 @@ pnpm prisma migration plan --name my_change
|
|
|
142
144
|
|
|
143
145
|
If the `db` ref's pointer is itself missing and the hash isn't a graph node either (`MIGRATION.SNAPSHOT_MISSING`), create it with `migration ref set db <hash>` or advance it with `db update --advance-ref db`.
|
|
144
146
|
|
|
145
|
-
**After
|
|
147
|
+
**After `db migrate` with `--db`, with `--no-advance-ref` or in CI.** The live marker advances and the `db` ref does not. The `db` ref records where development plans start, so move it only for your development database, never for a deployment database. On the development database, run the same `db migrate` again with `--advance-ref db`, without `--no-advance-ref`: it applies nothing and moves the ref to the contract the database is at. If that run ended at the empty contract (`--to @empty`, or a rollback of the first migration with `--to <first-migration-dir>^`), no ref can name it and `--advance-ref db` is refused with `MIGRATION.REF_TARGET_EMPTY`; remove the stale ref with `migration ref delete db` instead.
|
|
146
148
|
|
|
147
149
|
**When to switch paths.** Use `db update` while the schema is in flux, on a database whose migration history does not need to be kept (a local, development, staging or preview database). Switch to `migration plan` + `db migrate` when the change needs a reviewable, replayable migration — typically before opening a PR, and always for a database that changes only through migrations, such as production. The `db` ref bridges the two: it captures dev iteration state on disk so the first formal plan knows where you left off.
|
|
148
150
|
|
|
@@ -218,9 +220,11 @@ pnpm prisma db migrate --show --from <hash-or-ref> --to <hash-or-ref>
|
|
|
218
220
|
Fill in any data transforms (see *Fill a placeholder*), self-emit if you edited `migration.ts`, then:
|
|
219
221
|
|
|
220
222
|
```bash
|
|
221
|
-
pnpm prisma db migrate
|
|
223
|
+
pnpm prisma db migrate
|
|
222
224
|
```
|
|
223
225
|
|
|
226
|
+
On the database `prisma.config.ts` connects to, when the CLI does not detect CI, `db migrate` also moves the `db` ref to the contract it applied, so the next `migration plan` starts there. Against another database, pass `--db <url>`; that run leaves the `db` ref alone.
|
|
227
|
+
|
|
224
228
|
`db migrate` runs without prompting: the data-loss questions were answered when `migration plan` wrote the package. Review `destructive` and `data` operations in the plan output or in `migration show` *before* applying.
|
|
225
229
|
|
|
226
230
|
## Workflow — Fill a placeholder
|
|
@@ -535,7 +539,7 @@ A loss is an operation whose class is `destructive`. An access change is disabli
|
|
|
535
539
|
}
|
|
536
540
|
```
|
|
537
541
|
|
|
538
|
-
Commands that rewrite a ref (`migration ref set`, `db update`, `db sign`, `db migrate
|
|
542
|
+
Commands that rewrite a ref (`migration ref set`, `db update`, `db sign`, `db migrate`) keep `policies` and `invariants`.
|
|
539
543
|
|
|
540
544
|
**Applying a declared policy.** `db migrate --to <ref>` and `db update --to <ref>` compare the ref's declarations with the database before running anything. If they differ, the command fails with `MIGRATION.POLICY_MISMATCH` and nothing runs. The database's policy changes only when the deploy is told it may: `prisma db migrate --to production --permit-policy-change --db <url>`. The run is checked against the ref's policies, runs, and writes them into the marker when it succeeds, so a failed run leaves the old policy. With nothing pending, the run writes only the policies. A pipeline that should apply reviewed policy changes passes the flag on every deploy; a cautious team leaves it out and applies policy changes by hand. The flag needs `--to <ref>`: with a hash, `@db`, `@empty` or no `--to`, the command fails with `CLI.INVALID_ARGUMENTS` before it connects. A ref that declares no policies is accepted and changes nothing, so a pipeline can pass the flag on every deploy.
|
|
541
545
|
|
|
@@ -612,17 +616,19 @@ Failures that *can* leak partial state: Mongo DDL that partially applied before
|
|
|
612
616
|
Diagnose:
|
|
613
617
|
|
|
614
618
|
```bash
|
|
615
|
-
pnpm prisma db verify --
|
|
616
|
-
pnpm prisma db schema --
|
|
619
|
+
pnpm prisma db verify --json
|
|
620
|
+
pnpm prisma db schema --json
|
|
617
621
|
```
|
|
618
622
|
|
|
619
623
|
Fix and re-run `db migrate`:
|
|
620
624
|
|
|
621
625
|
```bash
|
|
622
626
|
node <package dir>/migration.ts
|
|
623
|
-
pnpm prisma db migrate
|
|
627
|
+
pnpm prisma db migrate
|
|
624
628
|
```
|
|
625
629
|
|
|
630
|
+
Every `prisma` command here addresses the database `prisma.config.ts` names, so the diagnosis and the re-run look at the same database; outside CI, the re-run also moves the `db` ref. For another database, add the same `--db <url>` to the diagnose commands and to `db migrate`, which then leaves the `db` ref alone.
|
|
631
|
+
|
|
626
632
|
If the failure was an out-of-band side-effect that left external systems half-changed, repair those by hand before re-applying.
|
|
627
633
|
|
|
628
634
|
## Workflow — Recover from `MIGRATION.HASH_MISMATCH`
|
|
@@ -631,9 +637,11 @@ The concept: `migrationHash` is content-addressed. A mismatch means `migration.j
|
|
|
631
637
|
|
|
632
638
|
```bash
|
|
633
639
|
node <package dir>/migration.ts
|
|
634
|
-
pnpm prisma db migrate
|
|
640
|
+
pnpm prisma db migrate
|
|
635
641
|
```
|
|
636
642
|
|
|
643
|
+
This applies to the database `prisma.config.ts` names and, outside CI, moves the `db` ref with it. For another database, add `--db <url>`.
|
|
644
|
+
|
|
637
645
|
If self-emit itself fails (e.g. the contract has moved on and the operations no longer make sense against the migration's end contract), the package is stale. Either restore it from version control or delete it and re-plan with `migration plan`.
|
|
638
646
|
|
|
639
647
|
## Workflow — Answer the data-loss questions (`migration plan` and `db update`)
|
|
@@ -684,7 +692,7 @@ In a terminal the command asks each question in turn; type `delete`, `allow`, or
|
|
|
684
692
|
9. **Planning with no `db` ref and no `--from` in a project that already has migrations.** The origin falls through to the empty database, which would make the plan a full-create migration; `migration plan` refuses with `MIGRATION.PLAN_ORIGIN_UNKNOWN` rather than writing it. Pick the exit that matches your intent — the error lists them, and `references/migration-model.md` § *The trap* explains which to choose.
|
|
685
693
|
10. **Hand-authoring `migration.ts` from a blank file, or rewriting the rendered import line.** Migration files are framework-rendered — let `prisma migration plan` (or `migration new`) render the package, then edit only the holes the framework leaves for you, and, until [prisma/orm#30504](https://github.com/prisma/orm/issues/30504) is fixed, the first argument of `this.dataTransform` (see pitfall 7). On Postgres leave the rendered `@prisma/orm-postgres/migration` (or `@prisma/orm-sqlite/migration`) import path alone; on Mongo leave `@prisma/orm-mongo/target/migration` as rendered. Add symbols to the existing import line rather than introducing new import paths.
|
|
686
694
|
12. **Replaying migrations onto a database that is already ahead.** `db migrate` on a database with no marker runs every migration, skipping operations already applied. When the database is already past a migration (it has `x int8` where the migration adds `x int4`), the run stops at that migration's precheck with `MIGRATION.PRECHECK_FAILED`. Adopt such a database with `prisma db sign` (after `contract infer` if needed), not by replaying history.
|
|
687
|
-
13. **Running Prisma 7 `migrate` commands against Prisma 8.** Each one answers `CLI.V7_COMMAND` with its Prisma 8 command: `migrate dev` is `contract emit`, `migration plan
|
|
695
|
+
13. **Running Prisma 7 `migrate` commands against Prisma 8.** Each one answers `CLI.V7_COMMAND` with its Prisma 8 command: `migrate dev` is `contract emit`, `migration status` (which prints the `migration plan` that takes the database to the new contract), running that `migration plan`, then `db migrate`; when migrations on disk already lead to the new contract, `migration status` prints no plan, so skip that step and run `db migrate`; `migrate deploy` is `db migrate`; `migrate reset` has no equivalent, because Prisma 8 has no reset: `db update` brings the database to the contract instead, asking before it loses data, but it keeps existing rows and runs no seed steps or data transforms (a database that changes only through migrations is moved with `db migrate`); `migrate status` is `migration status`; `migrate diff` is `db update --dry-run`, or `migration plan` to write a migration package; `migrate resolve` is `db sign <migration>`, which moves the database marker to that migration after checking its schema, but leaves `migration status` without an applied mark. While Prisma 7 still owns the migrations, install Prisma 7's CLI with `npm install --save-dev @prisma/prisma7@7` and run every one of them except `migrate diff`, whose replacement only reads, as `prisma7 migrate <command>` instead; `migrate resolve` runs as `prisma7 migrate resolve --applied <migration>`.
|
|
688
696
|
14. **Changing rows outside a data transform.** A `rawSql` step that inserts, updates or deletes rows, or a Postgres transform whose query comes from `db.raw.sql` or contains `fns.raw`. Write it in a `dataTransform` (with a `check` on Postgres and Mongo); on Postgres, build its queries with the SQL query builder. *Data changes go in a data transform* explains why. If the builder cannot express it, stop (see *When the SQL query builder cannot express the transform*).
|
|
689
697
|
15. **A data transform without `check` (Postgres, Mongo).** It runs `run` on every database, including those where the work is already done, and can never refuse bad data. Always write `check`.
|
|
690
698
|
16. **Passing a statement for a changed `@@map` or `@map` on Postgres or SQLite.** A model or field that keeps its name is the same model or field, so when only `@@map` or `@map` changes, `migration plan` and `db update` rename the table or column, and its constraints and indexes, with no question and no statement. This needs a snapshot of the contract the database is at, and a table whose control policy is `managed` in both contracts. Without a snapshot, the change is planned as a drop and a create and asked about, as before, except a table name whose only change is a capital first letter (`users` to `Users`): that is refused with `MIGRATION.TABLE_NAME_CASE_CHANGED`, whose message gives the steps to rename the table; for a table that is not `managed`, nothing is renamed, and the plan is what that control policy allows. `--rename User:User` is refused with `MIGRATION.STATEMENT_INVALID`, and a `--delete User` left in a script from earlier releases fails with `CLI.CONSENT_UNUSED`. To get an empty table under the new name instead, remove the model in one change and add it back in a second. A rename the planner cannot order is refused with `MIGRATION.PLANNING_FAILED`: two models or fields that swap tables or columns, a chain where one moves to a name another frees, a model that takes the table of a removed one, and a rename statement that moves something into the old name. The message gives two plans through a name nothing uses (`prisma_swap_<name>`), or, for a takeover, a first plan that removes the model or field holding the name; follow it. One swap is not refused by `migration plan`: when two tables or columns of the same shape swap names and nothing else changes, the storage does not change, so `migration plan` reports no change and writes nothing, and the rows are then read as the other model's; `db update` refuses it. Make such a swap through a name nothing uses in the same way. The table is renamed only when everything stored in it moves, so a variant that gains or loses a table of its own is still asked about, as a data migration. MySQL plans no renames, so there a changed `@@map` is still a drop and a create.
|