v8.0.0-rc.25
A database can now record how it may change and what data it protects, and the CLI refuses a migration or update that breaks those rules. MariaDB gets a client of its own, and MySQL gains the ORM's aggregates. Int, BigInt, Float, Decimal, String, Boolean, Bytes and Json are convenience types on every database. SQL clients run nested transactions with tx.transaction(callback), and an ORM write inside a transaction is atomic. On PostgreSQL and SQLite, a changed @@map, @map or enum stored value is planned as a rename. Nested writes gain onConflict, variants of a polymorphic model, a disconnect that applies its criteria, and update and delete of one related row. prisma orm init --target takes any target package by name.
The upgrade recipes for this hop: the app recipe and the extension recipe. Each breaking change below names the change ids to look for in them. The examples write the ORM client as db.orm.public.<Model>, the PostgreSQL form; on SQLite, MySQL and MariaDB it is db.orm.<Model>. After upgrading, run prisma contract emit once: the generated contract.d.ts now imports from one module of the target package, SQL contracts record two new capabilities, and MySQL and MariaDB contracts gain aggregate types.
Breaking changes
-
pgand@types/pgare peer dependencies.@prisma/orm-postgres,@prisma/orm-target-postgresand@prisma/orm-extension-supabaseno longer install their own copy ofpgand@types/pg. Add"pg": "^8.22.0"to your dependencies and"@types/pg": "^8.20.0"to your dev dependencies before you install the upgrade. This fixes aPoolfrom your ownpgnot being accepted by the client when the two@types/pgversions differed. Seepg-is-a-peer-dependencyin the app recipe and the extension recipe, andextension-importing-pg-peers-itin the extension recipe. (#31060) -
temporal-polyfillmust be 1.0.8 or later. Every database package that requirestemporal-polyfillas a peer dependency now requires^1.0.8, where it required^1.0.4. A project or extension package that pins an older 1.0.x version updates it. Seetemporal-polyfill-peer-range-moves-to-1-0-8in the app recipe and the extension recipe. (#31045) -
PostgreSQL connections no longer set
lc_monetary=C. This lets a pooled Prisma Postgres URL connect. If you usemoneycolumns, runSHOW lc_monetaryas the application's role, outside Prisma. If it is notC,POSIXoren_US, runALTER ROLE <role> SET lc_monetary = 'C'before you deploy the upgrade; otherwise amoneyread fails withRUNTIME.LC_MONETARY_NOT_C. Under a locale with no or three fraction digits, writes made before the change are stored wrong, so make the change first. Seepostgres-lc-monetary-not-setin the app recipe. (#31081) -
The config type is
PrismaConfig. The typedefineConfigreturns is renamed fromPrismaNextConfigtoPrismaConfig, with no alias. The language server's diagnosticPRISMA_NEXT_INTERPRETATION_FAILEDis nowPRISMA_INTERPRETATION_FAILED. Seeconfig-type-renamed-to-prisma-configin the app recipe and the extension recipe. (#31062)Before:
import type { PrismaNextConfig } from '@prisma/orm-toolchain/cli/config-types'; const config: PrismaNextConfig<'sql', 'postgres'> = defineConfig({ /* ... */ });
After:
import type { PrismaConfig } from '@prisma/orm-toolchain/cli/config-types'; const config: PrismaConfig<'sql', 'postgres'> = defineConfig({ /* ... */ });
-
Generated files import from the module the target package names. A generated
contract.d.tsnow imports all its types from one module, such as@prisma/orm-postgres/contract-types; runprisma contract emitto regenerate it. A config that you assemble from the framework's owndefineConfig, not a target package's, must setcontract.typesModuleandmigrations.module, or commands fail withCONFIG.CONTRACT_TYPES_MODULE_MISSINGandCONFIG.MIGRATION_MODULE_MISSING. Control API callers passtypesModuletoemitandrenderContractDts, and theprojectDiroption is gone.@prisma/orm-toolchain/publish-surfaceand its two sub-entries are removed. Extension authors: the emitter, migration renderer and MySQL config factory take the module names too. Seecontract-types-import-from-the-target-package,hand-assembled-config-names-generated-file-modules,control-api-takes-types-moduleandtoolchain-publish-surface-entrypoints-removedin the app recipe, andtarget-package-names-generated-file-modules,extension-config-names-generated-file-modules,family-imports-are-import-requirements,migration-renderer-takes-the-migration-module,emitter-takes-the-types-module,mysql-config-components-carry-family-and-modules,control-api-takes-types-module,component-type-import-module-is-not-a-literal-typeandtoolchain-publish-surface-entrypoints-removedin the extension recipe. (#31078) -
On PostgreSQL and SQLite, a changed stored name is planned as a rename. When a model, field or enum member keeps its name and only its
@@map,@mapor stored value changes,migration plananddb updatenow rename the table or column, or replace the stored value, without asking. A script that passed--deletefor such a change now fails withCLI.CONSENT_UNUSED; remove the flag. To get an empty table under the new name, remove the model in one migration and add it back in the next. Swaps, chains and takeovers of table and column names are refused withMIGRATION.PLANNING_FAILED, and so are enum members that swap stored values or take the stored value of a removed member; make them in two migrations: the first moves every name involved to a name nothing uses, and the second moves them to the final names. Chains of enum stored values are planned. A table that still has the lowered name an earlier release gave a model with no@@mapis renamed to the model name; add@@mapto keep the old name. MySQL and MongoDB plan these changes as before. Seesql-stored-name-change-is-a-rename,sql-stored-name-delete-is-unused,sql-stored-name-empty-table,sql-stored-name-swaps-refusedandsql-lowered-table-names-renamedin the app recipe. Extension authors who call the SQL family's statement planning seeschema-tables-same-name,plan-statements-plans-stored-name-renames,subjects-of-calls-storage-renamesandstored-value-keep-data-edit-removedin the extension recipe. (#31088)Before:
prisma migration plan --name move-users --delete User
After:
prisma migration plan --name move-users
-
sql.String(n)is nowsql.Varchar(n), and PostgreSQL'sjsonColumnisplainJsonColumn.sql.String(n)still works as a deprecated alias that warns withPSL_DEPRECATED_SCALAR_NAME, in PSL and astype.sql.String(n)in TypeScript. The PostgreSQL column helperjsonColumnis removed; importplainJsonColumn. No contract changes. Seepsl-renamed-sql-string,ts-renamed-sql-stringandts-renamed-postgres-json-column-helperin the app recipe, andts-postgres-explicit-json-typein the extension recipe. (#31065)Before:
model Label { id Int @id name sql.String(50) }
After:
model Label { id Int @id name sql.Varchar(50) }
-
On MongoDB,
Int64is nowInt64BigInt.Int64still works in PSL as a deprecated alias that warns. In a TypeScript contract,type.Int64()is removed; writetype.BigInt()ortype.Int64BigInt(). No contract changes. Seepsl-renamed-mongo-int64andts-removed-mongo-int64-helperin the app recipe and the extension recipe. (#31067)Before:
model Post { id ObjectId @id @map("_id") views Int64 }
After:
model Post { id ObjectId @id @map("_id") views BigInt }
-
On SQLite,
DecimalandBigIntNumberchange codec, and integers are checked. ADecimalfield now uses its own codec,sqlite/decimal@1, and refuses text that is not a decimal.BigIntNumberis a deprecated alias ofIntegerNumber; writeBigInt(as: number). Both change the contract's storage hash, so re-emit and sign the database: with migrations,migration plan --from <latest migration>thendb migrate; without,db update. No column changes. AnIntfield now refuses to write, and fails to read, a number that is not an integer within ±(2^53 − 1). The column helpersintegerColumn,bigintColumnandjsonColumnare renamedintegerNumberColumn,integerBigIntColumnandplainJsonColumn. The recipe has queries that find rows the new checks refuse. Seesqlite-decimal-codec,ts-sqlite-decimal-codec,sqlite-bigintnumber-deprecated,sqlite-integer-safe-rangeandts-renamed-sqlite-column-helpersin the app recipe and the extension recipe. (#31086) -
Re-emit MySQL and MariaDB contracts. The MySQL target now supplies the ORM's aggregates and has codecs for the new convenience types. Run
prisma contract emitsocontract.d.tscarries their types; the contract's hashes do not change. Errors from MySQL's shared code no longer carrymeta.target; readdb.stack.target.targetIdinstead. Extension authors: the MySQL driver factories take the target's runtime metadata and its CHECK error numbers, and a hand-written MySQL codec descriptor needswrapParameter. Seere-emit-mysql-contract-for-aggregates,mysql-errors-drop-meta-targetandmysql-reemit-contractin the app recipe, andmysql-driver-factories-take-the-targetandmysql-codec-descriptor-wrap-parameterin the extension recipe. (#31082, #31109) -
SQL contracts record two include capabilities, and a nullable unique key no longer identifies a row. Run
prisma contract emitto recordsql.outerReferencesInDerivedTablesandsql.jsonAggWithoutTruncation; a contract that is not re-emitted keeps working. A table whose only unique key has a nullable column now has no row identity, soupdate(),delete()and writes followed by.include(...)on it fail withORM.ROW_IDENTITY_MISSING. Give such a table a primary key, or make the key's fields required. Extension authors with an SQL adapter report the three include capabilities. Seere-emit-for-include-capabilitiesandnullable-unique-key-is-no-row-identityin the app recipe, andadapters-report-include-capabilitiesin the extension recipe. (#31058) -
contract emitrefuses a TypeScript contract built for another target. A contract that importsdefineContractfrom another target's package, such as SQLite's in a PostgreSQL project, now fails withCONTRACT.TARGET_MISMATCH, whose fix names the right module. It used to emit and then fail when the client loaded it.typescriptContractFromPathfrom@prisma/orm-family-sql/contract-ts/config-typesnow takes the target and itscontract-buildermodule. Seetypescript-contract-for-another-target-refusedandtypescript-contract-from-path-requires-targetin the app recipe, andtypescript-contract-from-path-requires-targetin the extension recipe. (#31091) -
A TypeScript
hasOnerelation needs a unique key on the target.rel.hasOne(Target, { by })now fails withCONTRACT.RELATION_INVALIDunless a primary key, unique constraint or unique index withoutwherecovers exactly thebyfields. Make them unique, or userel.hasMany. PSL already refused this. Seehas-one-key-must-be-uniquein the app recipe and the extension recipe. (#31030) -
Single-table variants keep their foreign keys, and refuse uniques and indexes over the whole table. A relation on a variant that shares its base model's table now stores its foreign key and backing index; both used to be dropped.
@unique,@@uniqueand most@@indexwithoutwhere:on such a variant now fail withPSL_UNSCOPED_INDEX_ON_STI_VARIANT, whose message gives the partial index to write instead. Re-emit, then plan and apply a migration. Seesti-variant-unscoped-index-refusedandsti-variant-foreign-keys-storedin the app recipe. (#31040) -
A PSL schema must be valid UTF-8. A schema file with bytes in another encoding now fails with
PSL_SCHEMA_READ_FAILED, naming the file. Before, each bad byte became U+FFFD and the file loaded. Reopen the file in its original encoding, such as Windows-1252, and save it as UTF-8. Seepsl-schema-must-be-utf8in the app recipe. (#30202) -
SQL builder comparisons check values against the column's type. In
fns.eq,ne,gt,gte,lt,lte,inandnotIn, a value compared with an enum column, or any column whose type is narrower than its codec's, must have the column's type. A misspelled member, a plainstringor astring[]is now a type error. Narrow the value first, or compare throughfns.rawto match a value the enum no longer lists. Seesql-builder-enum-comparison-values-are-checkedin the app recipe. (#31019) -
Nested relation mutation errors use the general ORM codes.
ORM.RELATION_MUTATION_INVALIDis nowORM.ARGUMENT_INVALID, andORM.RELATION_MUTATION_UNSUPPORTEDis nowORM.OPERATION_UNSUPPORTED;metais unchanged.createAllandcreateAndCountwithonConflict: 'skip'now refuse, before any statement runs, a row that gives no value for any key the option watches, and a table with no key at all, withORM.ARGUMENT_INVALID. Seerelation-mutation-error-codes-merged,create-all-skip-refuses-rows-without-conflict-keyandcreate-all-skip-refuses-tables-without-keysin the app recipe. (#31031) -
disconnectinupdate()data changed in three ways. On a relation whose foreign key is required,r.disconnect()is now a type error and is refused withORM.OPERATION_UNSUPPORTED(meta.reason: 'required-foreign-key') before any statement runs; useconnectto another row, or delete. On a many-to-one relation,r.disconnect(criteria)now unlinks only when the linked row matches the criteria; it used to ignore them.r.disconnect([])now disconnects nothing; it used to act asr.disconnect(). Seedisconnect-on-required-relation-refused,to-one-disconnect-criteria-appliedanddisconnect-empty-criteria-disconnects-nothingin the app recipe. (#31072, #31095) -
A nested create on a polymorphic model names its variant. In a relation callback whose target is a polymorphic base model,
r.create(data)no longer compiles. Writer.variant(value).create(data)and drop the discriminator field from the data.create()on a variant stored in its own table, without thereturningcapability, now namescreate()in itsORM.CAPABILITY_MISSINGerror, notcreateAll(). Seenested-create-on-polymorphic-target-needs-variantandvariant-create-without-returning-names-createin the app recipe. (#31029)Before:
await db.orm.public.Project.where({ id: 1 }).update({ tasks: (tasks) => tasks.create({ title: 'Crash on login', type: 'bug' }), });
After:
await db.orm.public.Project.where({ id: 1 }).update({ tasks: (tasks) => tasks.variant('bug').create({ title: 'Crash on login' }), });
-
Inside a transaction, other work on
txis refused while an ORM write of several statements runs. Such a write, for example a create with a nested relation, now runs in a savepoint. Work sent on the sametxwhile it runs, such as a second call inPromise.all, rejects withRUNTIME.TRANSACTION_SUSPENDED. Await the write before sending the other work. When such a write hits an error that ends the whole transaction, such as a deadlock on MySQL or MariaDB, it now rejects withRUNTIME.TRANSACTION_ROLLBACK_FAILEDand carries the database's error ascause; code that retries on a deadlock reads it from there. Seeorm-write-inside-transaction-suspends-txin the app recipe and the extension recipe. (#31121)Before:
await db.transaction(async (tx) => { await Promise.all([ tx.orm.public.Post.create({ title, author: (author) => author.create(user) }), tx.execute(plan), ]); });
After:
await db.transaction(async (tx) => { await tx.orm.public.Post.create({ title, author: (author) => author.create(user) }); await tx.execute(plan); });
-
update()data refuses a foreign key together with a callback on its relation. Data that sets a foreign key the record holds, such asauthorId, and also has a callback on that relation, such asauthor, is refused withORM.ARGUMENT_INVALID(meta.problem: 'foreign-key-with-relation-mutation') before any statement runs. It used to run, and acreate,connectordisconnectcallback overwrote the foreign key. Keep one of the two, or make two calls. Seeforeign-key-with-relation-callback-refusedin the app recipe and the extension recipe. (#31100) -
__proto__is refused as a name, and a JSON default with a__proto__key changes the storage hash. A contract now refuses a namespace, model, table, column, field, enum, value object, collection or root named__proto__withCONTRACT.NAME_UNUSABLE_AS_KEY(PSL_STORED_NAME_UNSUPPORTEDin a MongoDB schema); before, the entry was dropped or the contract came out wrong. One exception: in a MongoDB PSL contract, an enum named__proto__is not refused but left out of the contract without an error, together with every field typed by it. Choose another name. A SQL builderselectalias__proto__is refused withRUNTIME.AST_INVALID. A JSON column default that has a__proto__key now keeps that key incontract.json; re-emit, then plan and apply a migration. Seesql-proto-names-refused,mongo-proto-names-refusedandjson-default-proto-key-keptin the app recipe. (#31148, #31173) -
Update data cannot set the discriminator of a polymorphic model. Setting it is now a type error, and it is refused with
ORM.FIELD_IMMUTABLE. Before, it changed only the base table and left the variant's rows inconsistent. Remove the discriminator from update data; to move a row to another variant, delete it and create it as that variant. Seeupdate-data-refuses-discriminatorin the app recipe. (#31068) -
prisma db migrateadvances thedbref by default. After a successful apply,db migratenow moves thedbref (migrations/app/refs/db.json) to the contract the database is at, asdb initanddb updatedo, so the nextmigration planstarts from what was applied. It does so when the connection comes fromprisma.config.tsand the CLI does not detect CI. With--db <url>or in CI it advances nothing, and in CI it says so withMIGRATION.REF_NOT_ADVANCED_IN_CI. A deploy that runsdb migratefrom the config outside a CI runner, such as a container entrypoint or a release command, now rewrites that tracked file: pass the new--no-advance-ref, or--db. Remove--advance-ref dbfrom development commands that read the connection from the config. A ref that cannot be written is now the warningMIGRATION.REF_NOT_WRITTENand the command exits 0; it used to fail the command after the migrations had applied. Passing--advance-refand--no-advance-reftogether is refused withCLI.ADVANCE_REF_ARG_CONFLICT. Seedb-migrate-advances-db-refin the app recipe. (#31169)Before:
prisma db migrate --advance-ref db
After:
prisma db migrate
-
The CLI engine is
@prisma/cli-engine0.10.4, and its consent error has one fixed first line.@prisma/orm-toolchainnow requires exactly0.10.4, up from0.10.0; a project that declares@prisma/cli-engineitself moves to0.10.4. When a command stops because it needs consent it cannot ask for, the first line ofCLI.CONSENT_REQUIREDis nowThis command requires explicit consent, but it was not provided., or, under--yes,This command requires explicit consent for which --yes is not sufficient.It no longer names the subject or quotes the question. The suggested commands,meta, the code and the exit code are unchanged, and so is thewhyline of a refused migration or update; the error that--confirmanswers gains awhyline that holds the question. A script or test that matched the old first line reads the error'scode,whyandmetainstead. Seeengine-pin-moves-to-0-10-4andconsent-required-summary-is-one-fixed-sentencein the app recipe and the extension recipe. (#31179)Before:
✘ [CLI.CONSENT_REQUIRED] "Shop.legacy" needs a statement, and the session is not interactive.After:
✘ [CLI.CONSENT_REQUIRED] This command requires explicit consent, but it was not provided. -
MongoDB plans now ask about, and rewrite, changes inside documents. A field a value object or embedded model loses, an enum stored value that is removed, and a variant that is removed or whose discriminator value changes are now questions, answered with
--rename,--deleteor--convert. A script that runs with--yesand no statements fails withCLI.CONSENT_REQUIRED; add the statements it lists. A new required field inside a value object or embedded model is filled with a temporary value unless--backfillnames it. Seemongo-nested-removals-are-asked,mongo-nested-statements-are-plannedandmongo-nested-required-field-gets-temporary-valuein the app recipe. (#31061) -
The control API's
migratetakes the target ref whole.MigrateOptionsno longer takesrefHash,refInvariantsandrefName; passtarget: { kind: 'ref', ref: { name, ...entry } }ortarget: { kind: 'hash', hash }.DbSignOptionsrequiresinvocation. CLI users are not affected. Seemigrate-options-ref,db-sign-invocationandpermit-policy-changein the app recipe. (#30926) -
Extension authors: migration runners record database policies, and families name access changes. A target's migration runner writes
databasePoliciesinto the marker and checks the policies it was given under its lock.ControlFamilyInstanceandSqlControlTargetDescriptorgain a requiredaccessChangesOf(operations), andplanMigrationandresolveRecordedPathtake it too; a target with no operation that changes access returns[]. Seerunner-records-database-policies,control-family-access-changes-ofandaggregate-planner-access-changes-ofin the extension recipe. (#30926, #31087) -
Extension authors: transaction contexts have
transaction, and an activity handle's transaction takes a callback and is always there.TransactionContext,PostgresTransactionContext,MysqlTransactionContext,SqliteTransactionContextandSupabaseTransactionContexthave a requiredtransaction(fn)member, so a context an extension builds by hand needs one.TransactionSettlementStategainsclosedandabandon(). An activity handle'stransaction(fn, options)now runsfnthroughwithTransactioninstead of returning a transaction to commit;SqlRuntimeBase.ownTransactionis removed; androllback()after a commit rejects withRUNTIME.TRANSACTION_CLOSED. AnActivityHandlealways hastransaction(fn, options)and a newinTransaction()member, so a handle built by hand needs both, andActivityRoute.transactionis neverundefined. Seetransaction-context-has-transaction,postgres-transaction-context-has-transaction,transaction-settlement-state-has-closed-and-abandon,facade-transaction-contexts-have-transaction,supabase-transaction-context-has-transaction,activity-handle-transaction-takes-callback,sql-runtime-base-own-transaction-removed,orm-runtime-queryable-transaction-removed,rollback-after-commit-rejects,activity-handle-transaction-and-in-transaction-requiredandactivity-route-transaction-always-definedin the extension recipe. (#31073, #31106, #31120, #31121) -
Extension authors: the relation mutator types take
WritesandDeleteDisabled. The boolean type parameterFilteredWritesDisabledofRelationMutator, from@prisma/orm-family-sql/orm-client, is replaced byWrites extends 'many' | 'one' | 'none', and the type gains the parametersNsId,ConflictActionsandDeleteDisabled.VariantRelationMutatoris new and takes the same parameters. Code that passes the argument replacesfalsewith'many', andtruewith'one'or'none'. Seerelation-mutator-writes-parameterin the extension recipe. (#31096, #31100) -
Extension authors: MongoDB ORM collections can be prepared. A hand-written
MongoCollectionneeds apreparedmember, and itslimitandoffsettake a placeholder.MongoPrepareMembermoved to@prisma/orm-mongo/runtimeand takes the contract.MongoWhereFiltervalues can be placeholders, andcompileMongoQuerytakes no type argument. Seemongo-collection-has-prepared,mongo-prepare-member-moved,mongo-where-filter-takes-placeholdersandcompile-mongo-query-has-no-row-typein the extension recipe. (#31054)
Features
- A database can record a change policy and a data protection policy. A ref file declares them under
policies:changelistsmigrate(db migrate),reconcile(db update,db sign) or both, anddataProtectionsetsdataLossandaccessWideningto…-forbidden,…-with-consentor…-permitted.db migrate --to <ref>anddb update --to <ref>refuse a ref whose policies differ from the database's withMIGRATION.POLICY_MISMATCH, unless--permit-policy-changeconsents to writing them. A command the change policy does not allow fails withMIGRATION.CHANGE_POLICY_FORBIDS. A database with no recorded policy behaves as before. (#30926) - Data protection is enforced. Where a setting is
forbidden,db updateanddb migraterefuse an operation that loses data, or one that the target counts as changing who can read or write data, withMIGRATION.DATA_PROTECTION_FORBIDS, before anything runs;--delete,--allowand a typed answer cannot permit it, and--renamestill applies.migration plan --to <ref>refuses to write a migration the ref's policy forbids. Where a setting ispermitted,db updateasks nothing about it. The refusal's advice names the policy that refused, says how to plan the change again without losing data, and tells you not to edit an extension's migrations. On PostgreSQL, only two operations count as access changes: disabling row-level security, and dropping a row-level-security policy. Creating a policy does not count, even a permissive one that grants access. Nor does a policy that the same plan or migration drops and creates again, under the same name or generated-name prefix, whatever its new roles, command,USING,WITH CHECKor permissive setting say, so a replacement that widens access is not refused. ArawSqloperation is not read either, so SQL in a hand-written migration that disables row-level security or drops a policy is not refused. SQLite, MySQL, MariaDB and MongoDB count no operation as an access change, soaccessWidening: access-widening-forbiddenrefuses nothing on them. (#31087, #31131) - MariaDB has a client:
mariadb()from@prisma/orm-mariadb/runtimeruns ORM reads and writes, takes every optionmysql()takes, and acceptsmariadb://andmysql://URLs.@prisma/orm-mariadb/contract-builderwrites MariaDB contracts in TypeScript. On a database that cannot run the ORM's one-query include, such as MariaDB, the ORM loads each include with one query per relation. (#31058, #31082, #31091) - The ORM's aggregates,
count,sum,avg,minandmax, run on MySQL and MariaDB inaggregate(),groupBy(),combine()and scalar includes. (#31082) Int,BigInt,Float,Decimal,String,Boolean,BytesandJsonare convenience types on PostgreSQL, MongoDB, SQLite, MySQL and MariaDB. Each chooses one explicit type, and takes options such asBigInt(as: number)andString(storage: text). MySQL and MariaDB gainFloat,Decimal,Boolean,BytesandJson; SQLite gainsBoolean; MongoDB gainsBigInt,DecimalandBytes. A SQLiteBigIntfield now reads the full 64-bit range. (#31067, #31086, #31109)- On PostgreSQL,
Json(storage: jsonb)gives ajsonbcolumn;Jsonstill givesjson.contract inferandcontract printwrite ajsonbcolumn asJson(storage: jsonb). (#31065) - SQL clients run nested transactions. Inside
db.transaction(callback),tx.transaction(callback)runs in a savepoint, to any depth, on PostgreSQL, MySQL, MariaDB, SQLite and Supabase. When the inner callback throws, only its work is rolled back andtxstays usable, unless the error ended the whole transaction, as a deadlock does on MySQL and MariaDB; thentx.transaction(...)rejects withRUNTIME.TRANSACTION_ROLLBACK_FAILED, with the callback's error ascause, andtxrefuses further statements withRUNTIME.TRANSACTION_CLOSED. The inner callback receives the same kind oftx, withorm,sqland the other members. While it runs, the outertxrefuses statements withRUNTIME.TRANSACTION_SUSPENDED. (#31053, #31106, #31120) - A nested
createtakes{ onConflict, conflictOn? }.onConflict: 'connect'inserts a row that does not collide and links an existing one that does, on every relation layout.onConflict: 'skip'leaves a colliding row as it is, on one-to-many relations. (#31031, #31070) - A relation callback can act on one variant of a polymorphic model:
r.variant(value)hascreate,connect,disconnect,where,updateAllanddeleteAll, each limited to rows of that variant.createwrites a complete row, including a variant stored in its own table. (#31029, #31034, #31095) - A relation callback in
update()data can update or delete one related row. On a to-many relation,r.where(filter).update(data)andr.where(filter).delete()change the first related row the filter matches. On a to-one relation,r.update(data)andr.delete()change the linked row, narrowed bywhere()if given. When no related row matches, nothing changes.deleteis refused on a relation whose foreign key, held by the record, is required. (#31096, #31100) - An ORM write of several statements inside
db.transaction(callback)is atomic: it runs in a savepoint, so a write that fails leaves none of its rows, and on PostgreSQL it no longer aborts the transaction. (#31121) poolOptions.maxsets the most connections the pool ofpostgres()andsupabase()opens; the default stays 10. Setmax: 1behind a server-side pooler, such as a pooled Prisma Postgres URL. (#31138)- The control API's
DbUpdateSuccesshasmigrationPlan: the--fromand--toof amigration planthat moves the database to the run's target. Its types,MigrationPlanArguments,MigrationPlanArgumentandMigrationPlanTargetArgument, are exported, anddatabaseStorageHashis deprecated in its favour.DbUpdateOptionstakes an optionalemittedContractHash. (#31174) - A MongoDB ORM read can be prepared once and run many times: the
db.preparecallback can returndb.orm.<collection>…prepared.all(),.first()or.firstOrThrow(), with placeholders inwhere,limitandoffset. (#31054) - A pgvector column can hold vectors of any length:
pgvector.Vectorin PSL, orvector()in TypeScript, is PostgreSQL'svectortype without a dimension, read asnumber[]. (#30664) prisma orm initinstalls the target package first and writes the project from that package'sinitentrypoint, so the files come from the version you install. The files it writes are unchanged. It reportsCLI.INIT_TARGET_PACKAGE_NOT_INSTALLED,CLI.INIT_CONTRIBUTION_UNAVAILABLEandCLI.INIT_AUTHORING_UNSUPPORTEDwhen a package cannot set up a project. Extension authors: a package that adds a target can export aninitentrypoint typedInitContributionfrom@prisma/orm-toolchain/cli/init-contribution; seetarget-package-exports-an-init-contributionin the extension recipe. (#31093)prisma orm init --targettakes the name of any target package that exports aninitentrypoint and lists theprisma-orm-extensionkeyword, beside the short namespostgresandmongodb.--target @prisma/orm-sqliteand--target @prisma/orm-mysqlset up SQLite and MySQL projects, and the picker has an entry for another package. The--jsonresult gainspackage, and itstargetis the package name for a package with no short name; a script that accepts onlypostgresandmongodbthere needs a change. Seeinit-target-takes-a-package-namein the app recipe andinit-reaches-a-target-package-by-namein the extension recipe. (#31128)- A target package built outside this repository can emit a contract whose
contract.d.tscompiles, because generated files import from the module the target package names. (#31078) - PSL accepts
/* … */block comments, as Prisma 6 and 7 do. (#30795) MutationUpdateInput, the typeupdate()takes, is exported from theorm-cliententry, such as@prisma/orm-postgres/orm-client, as the docs say. (#30611)
Fixes
- A pooled Prisma Postgres URL connects. (#31081)
- With
poolOptions: { max: 1 }, a transaction and a query sent together as a client's first calls no longer fail withCONTRACT.MARKER_READ_FAILEDafter 20 seconds, and a Supabase client on such a pool can run queries as a signed-in user. (#31146) - A PostgreSQL or MySQL URL that leaves the user or the host blank, such as
postgres://:password@localhost/db, connects with the driver's default for the blank part. (#31066) - Names that every JavaScript object inherits, such as
constructor,toStringandvalueOf, work as namespace, model, table, column and field names in contracts, the ORM client, the SQL builder,contract inferand migration planning. (#31148, #31173) - A statement started inside a transaction that has not reached the database when the transaction commits or rolls back is refused with
RUNTIME.TRANSACTION_CLOSED. Before, it could run on its own after theROLLBACKand be committed. (#30880) - A model whose primary key is also a foreign key to its parent can have an optional one-to-one relation to a child that does the same.
contract emitused to fail withCONTRACT.VALIDATION_FAILED. (#30710) - Tables in an unbound PostgreSQL namespace are found through
search_pathagain, instead of being queried as"__unbound__"."<table>". (#30723) - In the SQL builder, a column of the outer query used inside a subquery refers to the outer table, not to the inner table with the same column name. (#30727)
includeworks on a model with more than 50 columns on PostgreSQL, and more than 63 on older SQLite builds. (#30796)- On a collection such as
db.orm.auth.User,select,distinct,distinctOn,cursor,whereUniqueandconflictOnuse the fields of that namespace's model when another namespace has a model with the same name. (#30810) ilikeandfullTextMatchesin the SQL builder accept a nullable text column. (#30598)- The MongoDB ORM offers
incandmulon nullable number fields. (#30522) - A
Datecreated in another JavaScript realm, such as a Jest test file, is accepted wherever a value is written. On MongoDB it used to be written as{}. (#30809) - A column reference passed to
returnsRow()in a raw query keeps its codec parameters and array type, so such columns decode correctly. (#30973) - A
wherewith tens of thousands ofinvalues ororbranches is built in milliseconds instead of seconds. (#30870) - The SQL runtime computes a statement's fingerprint only when
telemetry()is read, instead of after every statement. (#30949) - Contract globs such as
./schema/*.prismawork on Windows. (#30872) - On MySQL, an ORM update or delete whose filter reads the table it writes now fails with
RUNTIME.AST_UNSUPPORTEDand says what to do, instead of the server's error 1093; code that matched error 1093 matchesRUNTIME.AST_UNSUPPORTED. A contract file whose export is not a contract fails withCONTRACT.EXPORT_INVALID, naming the file, instead of crashing. (#31091) - Most
prisma migration plancommands that the CLI prints now work. Errors,migration status, and the advice ofdb update,db init,db signanddb migratenow print the--fromand--tothe plan needs for where the database is, and repeat the flags you gave, such as--configand--permit-policy-change. Before, many of these commands failed withMIGRATION.PLAN_ORIGIN_UNKNOWNin a project with nodbref, or planned to the emitted contract when you had named a ref. When migrations on disk already lead the database to the target, or the database has not applied all of them and the advice is about one change such as a rename, the message says to apply them first withdb migrate --to <contract>. When no plan can work, for example when the database's marker names a contract no migration produces, the message gives the reason and prints no command. Advice written by the SQL and MongoDB planners, such as how to fill a new required field, can still leave out--from; use the--fromthatmigration statusprints. (#31130, #31174) prisma orm initno longer runs a failed pnpm install again with npm; it reportsCLI.INIT_INSTALL_FAILED. (#31079)- The
prisma-8skill names published@prisma/orm-*packages instead of names that only resolve inside this repository, and no longer mentions packages and features that do not exist. (#31083)
Known problems
Neither problem is new in this release, and neither is fixed in it.
- Inside
db.transaction(async (tx) => ...), send every query throughtx. On a PostgreSQL client with a single connection (a connection frompostgresServerless().connect(), orpostgres()given onepg.Client), a query sent throughdbwhile the transaction is open runs inside that transaction, and some calls, such as anupdate()of one row, wait and never finish. On a client withpoolOptions: { max: 1 }, a query throughdbwaits for the transaction's connection and fails afterconnectionTimeoutMillis, 20 seconds by default. A client whose pool has more than one connection runs the query outside the transaction. - A PostgreSQL database whose
prisma_contract.ledgertable was created by a release from before June 2026 lacks thespace,migration_nameandmigration_hashcolumns thatdb migratewrites. Nothing adds them, sodb migratefails on such a database.
New contributors
- @veksa made their first contribution in #29947
- @AbhilashG12 made their first contribution in #30227
- @sarankumar1325 made their first contribution in #30872
- @s-ueno made their first contribution in #30880
- @dennishavermans made their first contribution in #30196
- @abd1rahmane made their first contribution in #31009
- @praveen-kumary made their first contribution in #30949
- @hassanabrar202 made their first contribution in #31019
- @xgauravyaduvanshii made their first contribution in #31060
- @ninglinLiu made their first contribution in #30981
- @SudeepGowda55 made their first contribution in #31040
- @Lqm1 made their first contribution in #30723
- @wh1teee made their first contribution in #30973
- @okxint made their first contribution in #30727
- @AboEl3iz made their first contribution in #30202
- @ryangarber made their first contribution in #30664
- @kpostekk made their first contribution in #30710
- @zonglinc00-debug made their first contribution in #31066