Repository navigation
feat(postgres)!: a PostgreSQL contract lists the capabilities it requires (optional, with a warning, until 8.0) - #31218
Merged
wmadden-electric merged 201 commits intoNov 27, 2026
Conversation
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… and why connection flags stay out of the contract Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…andle; the contract also states connection requirements, checked when the client is created Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ture is the one check of the database; the stack is checked against the contract Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…pabilities it requires; Prisma schema language syntax for them must be designed by the end of the project Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ws the fact; the target declares the database's capabilities by version Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…not a named object per version Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…sion' into worktree/capabilities-by-database-version-fb5e86
… list and where the signing check fits Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…h cover capabilities Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ilities each provides Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…st the facade fills with its runtime adapter's and driver's Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nent knows The database facts move to the target's version table. The runtime adapter and driver declare their own sets (empty today); the control adapter and driver declare nothing, since they migrate and do not run the application. The renderer checks locking clauses against the contract's capabilities. Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nnection's capabilities Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…configured components' Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…risma schema contract Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ity flags nothing reads Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ma contract it emits Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
TypeScript contracts state it in defineContract; Prisma schema contracts state it in the config's contract entry. Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…hitecture map Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… the configured components' Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nection's capabilities Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…d hands them to the contract source Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… version rows and drivers Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e and gives them to its source The version's row and the capabilities list are merged in order, keeping the flags that are on, and handed to defineContract, prismaContract and prisma7Contract alike. No control descriptor carries the row, so false turns a flag off the same way in every route. The facade's defineContract, defineConfig and prisma7Schema are built from the table so tests can use rows that differ. The table is named for what it holds and has one lookup. The renderer reads the locking flags from the contract it renders. Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… to write Co-Authored-By: Claude Opus <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…efineConfig Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s its record unpublished, and names itself A Prisma schema source built for another target and given no capabilities now gets only the CONTRACT.TARGET_MISMATCH error: the config reads the record of sources given no capabilities before any wrapper spreads the source, and the target refusal stays inside the default. Only isSourceGivenNoCapabilities is public. The record function moves to the unpublished subpath sources-given-no-capabilities, which prisma7Contract imports within the same published package. Every part of the stopgap carries "Prisma 8.0 removes" in its doc comment, so one search finds them. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ning's import goes in the file it names The client refuses the features that need a capability, but includes still work with one query per relation. For a TypeScript contract the warning's import goes in the contract file, not the config. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s tests, docs and an upgrade instruction Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Contributor
Public API changesThis pull request changes the ## API changes
- `@prisma/orm-better-auth (not exported): PrismaClientLike`:
- `@prisma/orm-better-auth (not exported): PrismaClientLikeFor`:
- `@prisma/orm-better-auth (not exported): TransactionalPrismaClientLike`:
- `@prisma/orm-better-auth: prismaAdapter`:
- `@prisma/orm-extension-paradedb`:
- `@prisma/orm-extension-paradedb (not exported): paradedbPackMetaBase`:
- `@prisma/orm-extension-paradedb/pack: default`:
- `@prisma/orm-extension-pgvector`:
- `@prisma/orm-extension-pgvector (not exported): pgvectorPackMetaBase`:
- `@prisma/orm-extension-postgis`:
- `@prisma/orm-extension-postgis (not exported): postgisPackMetaBase`:
- `@prisma/orm-extension-supabase`:
- `@prisma/orm-extension-supabase (not exported): ContractBase`:
- `@prisma/orm-extension-supabase (not exported): SupabaseStackProvides`:
- `@prisma/orm-extension-supabase/runtime: RoleBoundDb`:
- `@prisma/orm-extension-supabase/runtime: supabase`:
- `@prisma/orm-family-mongo`:
- `@prisma/orm-family-sql`:
- `@prisma/orm-family-sql`: (51 exports)
- `@prisma/orm-framework`:
- `@prisma/orm-framework/components/control: CapabilityFirstAvailable`:
- `@prisma/orm-framework/components/control: DatabaseCapabilitiesNotProvided`:
- `@prisma/orm-framework/components/control: DatabaseCapabilitiesNotProvidedExplanation`:
- `@prisma/orm-framework/components/control: DatabaseCapabilitiesNotProvidedFinding`:
- `@prisma/orm-framework/components/control: DatabaseVersion`:
- `@prisma/orm-framework/components/control: DiffableNode`:
- `@prisma/orm-framework/components/control: MigrationRunnerFailureMeta`:
- `@prisma/orm-framework/components/control: MismatchCause`:
- `@prisma/orm-framework/components/control: MismatchExplanation`:
- `@prisma/orm-framework/components/control: NodeMismatchExplanation`:
- `@prisma/orm-framework/components/control: databaseCapabilitiesNotProvidedIssue`:
- `@prisma/orm-framework/components/control: databaseCapabilitiesNotProvidedText`:
- `@prisma/orm-framework/components: CapabilityFirstAvailable`:
- `@prisma/orm-framework/components: DatabaseCapabilitiesNotProvided`:
- `@prisma/orm-framework/components: DatabaseCapabilitiesNotProvidedExplanation`:
- `@prisma/orm-framework/components: DatabaseCapabilitiesNotProvidedFinding`:
- `@prisma/orm-framework/components: DatabaseVersion`:
- `@prisma/orm-framework/components: DiffableNode`:
- `@prisma/orm-framework/components: MigrationRunnerFailureMeta`:
- `@prisma/orm-framework/components: MismatchCause`:
- `@prisma/orm-framework/components: MismatchExplanation`:
- `@prisma/orm-framework/components: NodeMismatchExplanation`:
- `@prisma/orm-framework/components: databaseCapabilitiesNotProvidedIssue`:
- `@prisma/orm-framework/components: databaseCapabilitiesNotProvidedText`:
- `@prisma/orm-mariadb`:
- `@prisma/orm-mariadb/family-contract/capability-messages: everything from @prisma/orm-family-sql/contract/capability-messages`:
- `@prisma/orm-mongo`:
- `@prisma/orm-mysql`:
- `@prisma/orm-mysql/family-contract/capability-messages: everything from @prisma/orm-family-sql/contract/capability-messages`:
- `@prisma/orm-postgres`:
- `@prisma/orm-postgres (not exported): DefaultRequiredCapabilities`:
- `@prisma/orm-postgres (not exported): PostgresAdapter`:
- `@prisma/orm-postgres (not exported): PostgresBaseScaffold`:
- `@prisma/orm-postgres (not exported): PostgresContributions`:
- `@prisma/orm-postgres (not exported): PostgresDefinition`:
- `@prisma/orm-postgres (not exported): PostgresResult`:
- `@prisma/orm-postgres (not exported): PostgresRuntimeBoundMembers`:
- `@prisma/orm-postgres (not exported): PostgresScaffold`:
- `@prisma/orm-postgres (not exported): PostgresStackProvides`:
- `@prisma/orm-postgres (not exported): defaultRequiredCapabilityLists`:
- `@prisma/orm-postgres (not exported): providedCapabilityLists`:
- `@prisma/orm-postgres/adapter/capabilities: everything from @prisma/orm-target-postgres/adapter/capabilities`:
- `@prisma/orm-postgres/config: PostgresConfigOptions`:
- `@prisma/orm-postgres/config: PostgresContractCapabilities`:
- `@prisma/orm-postgres/config: PostgresContractEntry`:
- `@prisma/orm-postgres/config: Prisma7SchemaOptions`:
- `@prisma/orm-postgres/config: RequiredCapabilities`:
- `@prisma/orm-postgres/config: defineConfig`:
- `@prisma/orm-postgres/config: postgres15`:
- `@prisma/orm-postgres/config: postgres16`:
- `@prisma/orm-postgres/config: postgres17`:
- `@prisma/orm-postgres/config: postgres18`:
- `@prisma/orm-postgres/config: postgresContractCapabilities`:
- `@prisma/orm-postgres/config: postgresDriver`:
- `@prisma/orm-postgres/config: prisma7Schema`:
- `@prisma/orm-postgres/contract-builder: PostgresContractCapabilities`:
- `@prisma/orm-postgres/contract-builder: RequiredCapabilities`:
- `@prisma/orm-postgres/contract-builder: defineContract`:
- `@prisma/orm-postgres/contract-builder: postgres15`:
- `@prisma/orm-postgres/contract-builder: postgres16`:
- `@prisma/orm-postgres/contract-builder: postgres17`:
- `@prisma/orm-postgres/contract-builder: postgres18`:
- `@prisma/orm-postgres/contract-builder: postgresDriver`:
- `@prisma/orm-postgres/driver/capabilities: everything from @prisma/orm-target-postgres/driver/capabilities`:
- `@prisma/orm-postgres/family-contract/capability-messages: everything from @prisma/orm-family-sql/contract/capability-messages`:
- `@prisma/orm-postgres/runtime: InteractiveTransactionsCapability`:
- `@prisma/orm-postgres/runtime: PostgresTransactionCallback`:
- `@prisma/orm-postgres/runtime: default`:
- `@prisma/orm-postgres/serverless: default`:
- `@prisma/orm-postgres/target/server-version-range: everything from @prisma/orm-target-postgres/target/server-version-range`:
- `@prisma/orm-sqlite`:
- `@prisma/orm-sqlite/family-contract/capability-messages: everything from @prisma/orm-family-sql/contract/capability-messages`:
- `@prisma/orm-target-mariadb`:
- `@prisma/orm-target-mariadb/adapter/adapter: mariadbAdapterCapabilities`:
- `@prisma/orm-target-mariadb/adapter/adapter: mariadbAdapterContractContributions`:
- `@prisma/orm-target-mariadb/adapter/adapter: mariadbAdapterDescriptorMeta`:
- `@prisma/orm-target-mariadb/adapter: mariadbAdapterCapabilities`:
- `@prisma/orm-target-mariadb/adapter: mariadbAdapterContractContributions`:
- `@prisma/orm-target-mariadb/adapter: mariadbAdapterDescriptorMeta`:
- `@prisma/orm-target-mongo`:
- `@prisma/orm-target-mysql`:
- `@prisma/orm-target-mysql/adapter/adapter: mysqlAdapterCapabilities`:
- `@prisma/orm-target-mysql/adapter/adapter: mysqlAdapterContractContributions`:
- `@prisma/orm-target-mysql/adapter/adapter: mysqlAdapterDescriptorMeta`:
- `@prisma/orm-target-mysql/adapter: mysqlAdapterCapabilities`:
- `@prisma/orm-target-mysql/adapter: mysqlAdapterContractContributions`:
- `@prisma/orm-target-mysql/adapter: mysqlAdapterDescriptorMeta`:
- `@prisma/orm-target-postgres`:
- `@prisma/orm-target-postgres (not exported): CapabilitiesByVersion`:
- `@prisma/orm-target-postgres (not exported): DatabaseCapabilitiesOf`:
- `@prisma/orm-target-postgres (not exported): FlagsOf`:
- `@prisma/orm-target-postgres (not exported): NamespacesOf`:
- `@prisma/orm-target-postgres (not exported): RowOf`:
- `@prisma/orm-target-postgres (not exported): postgresDatabaseCapabilities`:
- `@prisma/orm-target-postgres (not exported): postgresVersions`:
- `@prisma/orm-target-postgres/adapter/adapter: postgresAdapterCapabilities`:
- `@prisma/orm-target-postgres/adapter/adapter: postgresAdapterContractContributions`:
- `@prisma/orm-target-postgres/adapter/capabilities: postgresAdapterCapabilities`:
- `@prisma/orm-target-postgres/adapter/runtime: default`:
- `@prisma/orm-target-postgres/adapter/sql-renderer: renderLoweredSql`:
- `@prisma/orm-target-postgres/adapter: postgresAdapterCapabilities`:
- `@prisma/orm-target-postgres/adapter: postgresAdapterContractContributions`:
- `@prisma/orm-target-postgres/adapter: renderLoweredSql`:
- `@prisma/orm-target-postgres/driver/capabilities: postgresDriverCapabilities`:
- `@prisma/orm-target-postgres/driver/runtime: default`:
- `@prisma/orm-target-postgres/driver: postgresDriverCapabilities`:
- `@prisma/orm-target-postgres/target/runtime: default`:
- `@prisma/orm-target-postgres/target/server-version-range: POSTGRES_MIN_SERVER_VERSION`:
- `@prisma/orm-target-postgres/target/server-version-range: POSTGRES_NEWEST_VERSION`:
- `@prisma/orm-target-postgres/target/server-version-range: PostgresVersion`:
- `@prisma/orm-target-postgres/target/server-version: POSTGRES_MIN_SERVER_VERSION`:
- `@prisma/orm-target-postgres/target/server-version: postgresCapabilitiesByVersion`:
- `@prisma/orm-target-postgres/target/server-version: postgresRetiredCapabilities`:
- `@prisma/orm-target-postgres/target/server-version: readPostgresServerVersionNumber`:
- `@prisma/orm-target-postgres/target/types: PostgresDatabaseSchemaNode`:
- `@prisma/orm-target-postgres/target/types: PostgresDatabaseSchemaNodeInput`:
- `@prisma/orm-target-postgres/target/types: PostgresExtensionSchemaNode`:
- `@prisma/orm-target-postgres/target: POSTGRES_MIN_SERVER_VERSION`:
- `@prisma/orm-target-postgres/target: POSTGRES_NEWEST_VERSION`:
- `@prisma/orm-target-postgres/target: PostgresDatabaseSchemaNode`:
- `@prisma/orm-target-postgres/target: PostgresDatabaseSchemaNodeInput`:
- `@prisma/orm-target-postgres/target: PostgresExtensionSchemaNode`:
- `@prisma/orm-target-postgres/target: PostgresVersion`:
- `@prisma/orm-target-postgres/target: postgresCapabilitiesByVersion`:
- `@prisma/orm-target-postgres/target: postgresRetiredCapabilities`:
- `@prisma/orm-target-postgres/target: readPostgresServerVersionNumber`:
- `@prisma/orm-target-sqlite`:
- `@prisma/orm-target-sqlite/adapter/adapter: sqliteAdapterCapabilities`:
- `@prisma/orm-target-sqlite/adapter/adapter: sqliteAdapterContractContributions`:
- `@prisma/orm-target-sqlite/adapter: sqliteAdapterCapabilities`:
- `@prisma/orm-target-sqlite/adapter: sqliteAdapterContractContributions`:
- `@prisma/orm-toolchain`:
- `@prisma/orm-toolchain/cli/init-contribution: ConfigModuleExports`:
- `@prisma/orm-toolchain/cli/init-contribution: ContractEntryInput`:
- `@prisma/orm-toolchain/cli/init-contribution: ContractEntryNode`:
- `@prisma/orm-toolchain/cli/init-contribution: InitContribution`:
|
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… compiling POSTGRES_MIN_SERVER_VERSION is exported from the target's server-version path again, postgresAdapterCapabilities from the adapter's adapter path again, and verifySqlSchemaByDiff's databaseCapabilitiesNotProvided input is optional, as its reader already treats it. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nst release candidate 25 Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…meter Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…onContext keep compiling renderLoweredSql takes its old fifth argument again, and createExecutionContext its old driver option, both ignored until Prisma 8.0 removes them. The API check cannot see either break: a function with fewer parameters, or an options object with fewer properties, is assignable to the old type. A type test for each shows the old call compiles. The restored import paths of POSTGRES_MIN_SERVER_VERSION and postgresAdapterCapabilities are marked as part of the stopgap. The upgrade instructions say the old forms keep working until 8.0, and their detection matches the names, not an import path every project using createPostgresAdapter has. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden-electric
marked this pull request as ready for review
November 27, 2026 10:36
wmadden
approved these changes
Nov 27, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 27, 2026
…abilities - A contract that leaves out sql.insertOnConflictTarget now refuses upserts and skips on named columns, since the runtime no longer adds the adapter's capabilities; the test asserts the refusals and the untargeted skip. - The PSL round-trip walker expects the two release candidate 25 contracts to be refused for the same missing foreign key as the current emits of the same domain and storage. - The pgvector declaration test no longer rewrites the fixture's import line, whose formatting changed, so emit found `extension` undefined; it adds its own import and fails loudly if the fixture's opening line moves. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ves the capability out Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 27, 2026
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden-electric
deleted the
tml-3960-capabilities-by-database-version
branch
November 27, 2026 12:44
This was referenced Nov 27, 2026
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-prisma__orm
that referenced
this pull request
Nov 29, 2026
…e extension reuses as Early Access, not GA (prisma#31241) ## At a glance From release 8.0, everything a user can import from a generally available (GA) package must keep working until Prisma 9. This pull request decides that the building blocks of the PostgreSQL client are **not** promised that long. They are published under Early Access names, which may change in any release, and the `internal` import paths that held them are deleted. The Supabase extension is the one caller. Before: ```ts import { connectWithBinding, validateTransactionOptions } from '@prisma/orm-postgres/internal/options' import { buildPostgresStaticContext } from '@prisma/orm-postgres/internal/static-context' import { buildPostgresQueryMembers } from '@prisma/orm-postgres/internal/transaction-members' import { validatePostgresContract } from '@prisma/orm-postgres/internal/validate-contract' import { PostgresRuntimeImpl } from '@prisma/orm-postgres/runtime' import { preparedStatementQuery } from '@prisma/orm-family-sql/runtime/internal/prepared-query' ``` After: ```ts import { ea_connectWithBinding, ea_validateTransactionOptions, ea_buildPostgresQueryMembers, Ea_PostgresRuntimeImpl } from '@prisma/orm-postgres/runtime' import { ea_buildPostgresStaticContext, ea_validatePostgresContract } from '@prisma/orm-postgres/static' import { ea_preparedStatementQuery } from '@prisma/orm-family-sql/runtime' ``` The code behind each name is unchanged. What breaks is any code that imports the deleted `internal` paths or the old class name `PostgresRuntimeImpl`. That is extension code only: no example application, user guide or `prisma orm init` template imports them. ## Background `@prisma/orm-postgres` is the PostgreSQL *facade*: the one package an application installs to use PostgreSQL. Its `runtime` path exports `postgres()`, which builds the client an application queries with. `@prisma/orm-extension-supabase` is a separate published package. Its `supabase()` builds a different PostgreSQL client: one with no query interface until the application binds a database role, so no query can run without a role. It assembles that client from the same pieces as `postgres()`: connection handling, the builder for the client's `sql`, `orm` and `transaction` members, the option checks, and the runtime class, which it subclasses. Because it is a separate package, it can only use what the facade publishes, and the facade published those pieces on four import paths named `internal`, for Supabase alone. Anyone could import those paths, and nothing told a reader they might change. ## The decision The `ea_` prefix (`Ea_` for a type or class) marks a name as Early Access. `docs/oss/versioning.md` defines it: an Early Access name may change in any release, and the CI check that compares each package's exports with the last release does not fail when one changes. These pieces get that prefix because they are the seams inside `postgres()`. They were cut out of it so Supabase could reuse them, not designed as an interface. Their signatures expose how the client is put together today: `buildPostgresQueryMembers` takes the execution context, the query builder and a transaction context as separate inputs. Publishing them under plain names would freeze that structure until Prisma 9. If they prove stable, a later release adds plain names beside the prefixed ones. One limit: the prepared-query names also key members of the SQL family's `SqlRuntimeBase`, a GA class. The CI check judges a class's members as part of it, so changing those names would still be a recorded break. Settling that class's own level is the project's next platform slice; the plan records it. They move onto the paths that already load their code: `runtime`, where `postgres()` lives, and `static`, which holds the parts that need no database driver. ## What changes - **`@prisma/orm-postgres`** deletes `internal/options`, `internal/static-context`, `internal/transaction-members` and `internal/validate-contract`. Their exports move to `runtime` and `static` with the prefix, and `PostgresRuntimeImpl` becomes `Ea_PostgresRuntimeImpl`. - **`@prisma/orm-family-sql`**, the package shared by every SQL database, deletes `runtime/internal/prepared-query`. The seven names Supabase uses move to `runtime` with the prefix. The path's six other names (`settlementOf`, `transactionSettlement`, `wasRefusedBeforeBegin` and three types) are no longer exported at all: nothing outside the package uses them, and every name we export is one we must keep in some form. - **`@prisma/orm-mysql`, `@prisma/orm-mariadb` and `@prisma/orm-sqlite`** each re-export the SQL family's paths under their own name, so each loses `family-runtime/internal/prepared-query` too. - **The Supabase extension** imports the new names. It already lists `@prisma/orm-postgres` as a peer dependency; the decision record on the published packages now says it is the only extension that builds on a facade instead of the lower-level packages. - **Upgrade instructions** for extension authors list each old import and its replacement. ## A change from the design we agreed The design moved the runtime class and `validatePostgresContract` into `@prisma/orm-target-postgres`, the lower-level PostgreSQL package. Building it showed that was wrong, so both stay in the facade: - The target package deliberately does not depend on the SQL runtime package. Migrations and the `prisma orm` commands load the target, and keeping the query-execution code out of that load is the reason. `PostgresRuntimeImpl` extends a class from the SQL runtime, so moving it would pull that code in. - `validatePostgresContract` and `contractFromJson` mark a contract as validated under one shared key, so a contract checked by one is not checked again by the other. Moving one of them to another package would need that key exported and kept in step across packages. Either way the names are published at Early Access, so users are promised the same thing. ## API changes The CI check requires each package whose export list changed to be named here. - `@prisma/orm-postgres`: the five removed paths, and `PostgresRuntimeImpl` renamed `Ea_PostgresRuntimeImpl`. `runtime` adds `ea_resolveOptionalPostgresBinding`, `ea_connectWithBinding`, `Ea_PostgresBindingRules`, `ea_buildPostgresQueryMembers`, `ea_validateTransactionOptions`, `ea_validateCursorOptions` and `ea_toDriverCursorOptions`; `static` adds `ea_buildPostgresStaticContext` and `ea_validatePostgresContract`. Each is a part of `postgres()` the Supabase extension reuses. Five earlier break records (prisma#31150, prisma#31218) were updated: a record is tied to the exact text of the types it covers, and these covered the copies of `PostgresStaticContext` under the deleted `internal/static-context` path. With those copies gone, the check could also compare `serverless` and `static`'s default exports, which it had left undecided, and found the same column-name break (prisma#31150) in them; two records were added for it. - `@prisma/orm-family-sql`: `runtime/internal/prepared-query` removed; `runtime` adds the seven `ea_`/`Ea_` names above. - `@prisma/orm-mysql`: `family-runtime/internal/prepared-query` removed, because the SQL family's path it re-exported is removed. - `@prisma/orm-mariadb`: `family-runtime/internal/prepared-query` removed, because the SQL family's path it re-exported is removed. - `@prisma/orm-sqlite`: `family-runtime/internal/prepared-query` removed, because the SQL family's path it re-exported is removed. - `@prisma/orm-extension-supabase`: no change to its own exports; three records updated because `RoleBoundDb`, which the three types build on, now extends `Ea_PreparedStatementQueryTarget` and `Ea_PreparedStatementExecuteTarget`. ## How it was checked - The export comparison against the last release passes for each of the six packages, with every break recorded. - Type check and lint pass for the facade, the SQL runtime, the Supabase extension and the integration tests, which use the runtime class; the layering check passes. - The Supabase extension's 267 tests pass. They run its client, which calls every renamed piece. A new facade test checks that the prefixed names are on `runtime` and `static` and the old names are gone. - `postgres()` itself is unchanged: the facade exports its existing functions under a second name (`export { buildPostgresQueryMembers as ea_buildPostgresQueryMembers }`) and its own code still calls them directly. ## Alternatives considered - **Keep the `internal` paths and document them as unstable.** Rejected: a reader cannot see a document from an import line, and the CI check treats every path of a GA package as promised. A name prefix is visible wherever the name is used. - **A separate import path for extension authors**, such as `@prisma/orm-postgres/runtime-toolkit`. Rejected: `runtime` already loads this code, so a separate path keeps nothing out of an application's bundle. The level belongs in the name, which the reader sees at every use. - **Publish them as GA under plain names.** Rejected: it freezes the structure of `postgres()` until Prisma 9, for one caller we expect to change. - **A role-binding hook on `postgres()`, with Supabase as a thin layer on top.** Rejected: Supabase's client must have no query interface until a role is bound. A hook can add to `postgres()`'s client but cannot remove the interface it already has. Part of the project to reduce what the GA packages export (Linear TML-3979). Its plan is in `projects/reduce-exported-apis/`. Agent: gilderoy-93 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Breaking Changes** * Internal PostgreSQL and SQL runtime import paths are no longer available. Extensions using them must update imports to the supported runtime or static entry points; some former exports have no replacement. * PostgreSQL runtime and reusable helper APIs now use Early Access names. * **Documentation** * Added upgrade guidance to help extension authors identify and update affected imports. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-prisma__orm
that referenced
this pull request
Nov 29, 2026
… stored enum value changes (prisma#31192) ## At a glance A MongoDB user keeps `model User` and changes only what it is stored as: ```prisma // before // after model User { model User { id String @id @Map("_id") id String @id @Map("_id") email String email String @Map("mail") status Status status Status @@Map("users") @@Map("app_users") } } enum Status { enum Status { ACTIVE ACTIVE ARCHIVED @Map("archived") ARCHIVED @Map("retired") } } ``` On `main`, `prisma migration plan` and `prisma db update` plan a drop of collection `users` and a create of `app_users`. They then stop at the consent prompt, which asks the user to allow the data loss with `--delete User`. The `--rename` flag cannot help, because the model's name did not change. The only way to keep the documents is to rename the collection by hand. With this pull request, both commands plan the following and ask nothing. Each operation is labelled `widening`, which means it loses no data: ```text Rename collection users to app_users widening Rename field email to mail in collection app_users widening Replace value "archived" with "retired" in field status of collection app_users widening ``` The documents, indexes and validator move with the collection. PostgreSQL and SQLite have worked this way since prisma#31088. Some changes that MongoDB cannot apply safely are now refused instead, with an error that explains how to make the change in two steps. ## The decision 1. **Stored-name changes are planned as renames and value replacements.** [ADR 324](docs/architecture%20docs/adrs/ADR%20324%20-%20The%20same%20coordinate%20is%20the%20same%20object.md) says that a model, field or enum member with the same name in the database's current contract and in the new one is the same object, so only its storage changes. ADR 324 was implemented for PostgreSQL and SQLite and left MongoDB open. This pull request implements it for MongoDB, as close to the SQL behaviour as MongoDB allows. 2. **Plans that would not survive a re-run are refused**, and the error explains how to make the change in two migrations. The runner applies a MongoDB migration one operation at a time, not in a transaction, because collection commands such as `renameCollection` cannot run inside one. A migration that stops part way is finished by running it again: each operation checks the database before and after it runs, and a re-run skips one whose after-check already holds. So every plan must give the right result when run again after a stop. 3. **`--rename` of a model that shares its collection with another model is refused**, and the error prints a hand-written move of that model's documents. Renaming the collection would move every document in it, and nothing in a document says which model it belongs to. ### What changes for existing users - The changes in decision 1 are planned instead of asked about. - On `main`, `--rename` of a model that shares its collection renamed the whole collection, so the other model's documents moved too. It is now refused (decision 3). - On `main`, renaming a field of `Member` in the same change in which `Guest`, which stores the same field, joins `Member`'s collection was planned. It is now refused (the last item of section 2). ## 1. What is planned A variant is a model stored in its base model's collection; a discriminator field in each document says which variant it is. - **`@@map` change:** `renameCollection`. - **`@map` change on a field:** a field rename (`$rename`). On a variant, it touches only that variant's documents. - **`@map` change on a field of an embedded model:** the key is renamed in every place that embedded model is stored. - **A changed stored value of an enum member:** the value is replaced in every field and nested key of that enum type, in single values and in lists. - **Combined with other changes:** type changes, `--rename` and `--delete` act on the collection under its new name. The consent prompt still names the model and field as the user wrote them. - **`db update` on a database where the collection was already renamed by hand:** no collection operation is planned, and the rest of the plan acts on the collection under its new name. `createCollection` now has an after-check, which re-runs need. On `main` it had none, so a migration that created a collection could not be run again after a later step stopped: the re-run tried the create again, and its before-check failed. The after-check holds only when the collection exists with every option the call sets, its whole validator included, so a collection made another way still stops the create. Migrations users already emitted keep the old create until their `ops.json` is written again; the upgrade note says what to do after a stop with one of those. When such a create finds its collection already there, the runner's error says it cannot tell whether an earlier run made it, and gives its routes: write `ops.json` again if no other database applied the migration; drop the collection only if it holds nothing you need, even when an earlier run of the command created it, and then run the command that stopped again as it was run; or, on every database, move the collection aside and copy it back. The message names that route and points to the section "Moving a MongoDB collection aside" in the error reference, which gives the steps: stop writes until every step is done, move aside the collection the error names, removing a kept regular collection's validator with `collMod` before editing its documents (a time-series collection is copied with `$out` into a time-series collection with the same options, since MongoDB cannot rename one and its `_id` need not be unique), run `db migrate --to` the migration, make the documents meet the validator and unique indexes, list and compare the documents the run wrote again under the same `_id` (deleting a time-series document with a filter that matches it alone, since its `_id` need not be unique), copy them back, and drop the moved copy only once each of its documents is in the collection or deliberately not kept, and finally run the command that stopped again exactly as it was run. The message says the next run may stop at another create in the same state, where the same steps apply, and that an earlier run may have moved documents into the collection from a collection it then emptied. An extension migration gets no "write `ops.json` again" route, since its operations come from the extension's package. Where the change policy permits `reconcile`, it also offers applying the remaining operations by hand and then `db sign` with the migration's directory name (`db sign` checks collections, validators and indexes, not documents, and afterwards `migration status` shows the database up to date without marking that migration as applied). Every contract space's runner receives the database's policies through one option, `policiesInForce`, so an extension space gets the same advice; the runner itself uses them to guard only the application space's marker. The repository's own `examples/retail-store` initial migration is written again, and its migration hash changes. ## 2. What is refused, and why Each refusal is `MIGRATION.PLANNING_FAILED`. Its text explains how to make the change in two migrations: first give the objects temporary names that neither contract uses (the error suggests them, and says to pick others if the database already has one), plan and apply that, then give them their final names and plan again. These refusals apply to collection names, field stored names, embedded keys and enum stored values. Refused as on SQL, because the plan would read one model's documents as another's: - **Swaps:** `User` moves from `users` to `accounts` while `Account` moves from `accounts` to `users`. The error reads `Cannot rename collection "accounts" to "users": collection "users" is renamed in the same plan`. - **Takeovers:** field `email` is removed, and field `contact` takes its stored name `email`. - **An enum mapped to `true`/`false` whose two values swap.** The error says to keep the stored values in the contract. It gives no two-migration route, because a boolean field has no third value to hold one side while the other moves. - **`db update` when the database has both the old and the new collection.** The error names the fix for each cause: - the rename was half done by hand; - something wrote to the new collection first; - the old collection was renamed by hand and its name then reused. Refused on MongoDB only, because a re-run after a stop would go wrong: - **Chains:** `users` is renamed to `accounts` while `accounts` is renamed to `archive`. Ordered `accounts` first, the first run is right, but a re-run after a stop finds documents under `accounts` again and moves them on to `archive`. The same holds for enum stored values that shift along a chain, which SQL plans in one transaction. - **A plan that frees a collection name and creates a new collection under it.** Example: `users` is renamed to `app_users`, and a new model creates `users`. If the plan stops after the create, a re-run finds both collections, and the rename's before-check fails on every run. - **A rewrite of one model's field that would also reach documents of a model joining the same collection.** Example: `Member` renames its field `name`, and `Guest`, which also stores `name`, joins collection `members` in the same change. The rename would also rename the field in `Guest`'s documents. This holds even when `Guest` is new: a hand-written step in the same migration may copy its documents in, so the planner cannot assume it has none. The error says what works: make the rename in an earlier migration, before `Guest` joins the collection. ADR 324 records the rule. ## 3. Moving a model out of a shared collection Two models that are not variants can share one collection: ```prisma // before // after model User { model Member { name String fullName String @@Map("people") @@Map("members") } } model Admin { model Admin { level Int level Int @@Map("people") @@Map("people") } } ``` On `main`, `--rename User:Member --rename Member.name:Member.fullName` renames collection `people` to `members`, so `Admin`'s documents move with it and `Admin` reads an empty collection. That `--rename` is now refused. The error says what the plan without it does: `User`'s documents stay in `people`, and `Admin` keeps reading them. To move them, the error prints steps for the `migration.ts` of that plan: ```ts dataTransform({ run: () => rawAggregate("people", [ { $match: <a filter that selects only User's documents> }, { $set: { fullName: "$name" } }, { $unset: ["name"] }, { $merge: { into: "members" } }, ], { bypassDocumentValidation: true }), }), deleteDocuments({ collection: "people", filter: <the same filter> }), ``` The user writes the filter, because only they know which documents are `User`'s. The error works out everything else by planning the change again, in full, without the refused `--rename` flags, so it describes the plan the user will get: - **Where the steps go:** right after the plan creates the target collection, right after it renames another collection to the target's name, or at the start of the migration if the target collection already exists. - **The stages:** they write the model's renamed fields and its discriminator value if it becomes a variant, and they drop the fields it no longer stores. The text names the fields whose values are dropped. - **`bypassDocumentValidation`:** added only when a later operation in the plan replaces the target's validator and checks every document, the copied ones included. `rawAggregate` now takes this option, as `rawUpdateMany` already did. [ADR 188](docs/architecture%20docs/adrs/ADR%20188%20-%20MongoDB%20migration%20operation%20model.md) records why the copy must run under the target's old validator. - **Several models:** one set of steps covers every model the refused flags would move. When the plan without the flags drops the source collection, the steps move every model leaving it. - **A time-series target:** `$merge` cannot write into a time-series collection, so the copy reads the target, adds the moved documents with `$unionWith`, and writes the result back with `$out`. A lone `$out` copy was rejected: run again after its delete, it finds no documents and empties the collection. The chosen form is safe to run again except between the copy and the end of the delete, where the route says to finish the delete on the source first. The runner's error says it too, after any failure between that copy and the end of its deletes as the route prints them (just before the copy, the runner counts the target and the source documents the copy selects; after a failure while the copy runs, a write-concern error included, the advice says how to tell from the target's count whether the copy finished, and a drop of the source that throws is reported as one that may not have finished; before any delete or drop by hand, the advice says writes to both collections must still be stopped, and before counting, to check with a printed `$currentOp` query, which matches only this database and only an aggregate whose last stage writes into the collection, that the copy is no longer running, since MongoDB finishes an `$out` after the connection drops, and to check again after any `killOp`, since it is not immediate; when the source held none of the copy's documents, a re-run also needs that check and that nothing wrote to either collection; when that is not certain, to delete nothing from either collection and not run again until the two are settled by hand, leaving in the source every document the copy does not select, and of those it selects only the ones the target does not hold, since the next run copies the source again; the count it gives reads only writes a majority of the replica set has made, and when a count read fails, a count is not exact, or the two collections have different collations, it gives no count route and says to settle both collections by hand, and a failed count read does not stop the copy; both count conclusions hold only if nothing wrote to or deleted from either collection since the apply started), including a move of several groups, which gets one delete per `$unionWith` stage; it adds nothing for hand-written copies of another shape, including a copy with an after-check or with a stage after its `$match` other than `$set`, `$addFields` or `$unset`; a copy of another shape that writes with `$out` or `$merge` and stops on a thrown error is reported as `MIGRATION.EXECUTION_FAILED`, saying it may have finished, to check that it has ended, and to settle both collections by hand before running again; the planner's own `$merge` move into a collection that is not time-series is recognised and reported as before, since its `$merge` matches by `_id` and a re-run is safe, and a copy with a check is told that a re-run copies again unless postchecks and idempotency checks are both on and its check shows it ran. The copy reads the source with the time-series collection's collation, so the route gives each `deleteDocuments` that collation (`{ locale: "simple" }` when it has none), and the delete and its after-check select what the copy took, whatever the filter. When the count shows the old number, the advice says to count again after a moment, since a majority count can lag, and that a re-run may still add the documents a second time. The move route states the costs of this copy: it rewrites the whole collection, writes to both collections stop for the whole apply, and `$out` cannot write into a sharded collection. The time-series rename route under `migration plan` prints the same form of copy, followed by the plan's drop of the old collection, and, under both `db update` and `migration plan`, says to stop writes to both collections until the apply succeeds, re-runs included. ## Not covered - **A model that is not a variant moves out of a shared collection without `--rename`.** Its documents cannot be told apart from the other model's, so they stay behind, and the model starts empty in its new collection. The plan does not ask about it, as on `main`. The spec defers this as a data migration needing its own design; it is in `projects/migration-statements/deferred.md`. - **Two collections or fields of identical shape that swap names.** `migration plan` reports "No changes detected", because it compares a hash of the storage layout before planning, and the hash does not change. `db update` refuses the same change. This is the same known gap as on SQL, and the upgrade note states it. - **Two limits of the hand-written move, which the error states.** A document written to the source between the copy and the delete is deleted without being copied, so the error says to stop writes to both collections until the apply succeeds, re-runs included. `$merge` matches on `_id`, so the error says to check first that no `_id` is in both collections. Handling either automatically would need a new mechanism. - **The validator update's after-check compares only the `$jsonSchema`.** This is on `main` and is in `deferred.md`. - **The `true`/`false` enum swap is covered by planner tests only.** No contract can currently hold an enum member mapped to `false`, because canonicalization drops it (TML-3832). ## Other changes in this pull request - The ORM's tests no longer assert the first line of `CLI.CONSENT_REQUIRED`. That sentence is written and tested by `@prisma/cli-engine` in another repository, and every change to its wording forced edits here. The tests still assert what the ORM supplies: the code, the reason, the next steps and the unanswered questions. - Four changes to the database-neutral CLI package, the only ones under `packages/1-framework`. Each is about the CLI's own text, with no database concept added: - Advice no database reaches any more is deleted: the swap text in `keep-data-edit-advice.ts`, and the "member the new contract keeps" branch in `plan-questions.ts`. - A suggested fix in an error keeps the indentation of its lines (`normalize-error.ts` trimmed both ends of each line). The MongoDB move steps need it, and no other message a user can see has indented lines. - The error for a missing contract snapshot names `--advance-ref db` in its steps and suggested commands, where `main` printed the placeholder `<name>`, and says that `db` is the development database's ref, so a run against any other database gives another ref name (`cli-errors.ts`). The numbered steps a data-loss question shows are the same text, so they changed the same way. - When a data-loss question is asked and the contract the database is at is unknown, its advice now says that a change of a stored name alone is then planned with no question, and a change of a name is answered with `--rename` (`plan-questions.ts`, all targets). - The public API lists (`api.txt`) gain `rawAggregate`'s options, the runner option `policiesInForce` (which replaces 8.0.0-rc.25's `checkedPolicies`), and five helpers from the MongoDB family's `schema-verify` entry point (`isDisabledChangeStream`, `isSimpleCollation`, `reportedCappedMax`, `reportedCappedSize`, `reportsValidator`). The helpers are for internal use: they let the target's `createCollection` after-check and the schema verifier share one rule for what MongoDB reports, and the public package republishes every family entry point. They also gain `codecStoresValue` from `./contract/data-type`, beside `bsonTypesOfCodec`, which the enum swap route uses to suggest only a temporary value the enum's codec can store. - ADR 188 now records the order of operation kinds, that it stands in for dependencies the plan does not model, when a write may skip validation, and the time-series copy with the steps to take before running it again. ADR 324, the Migration System and MongoDB Family docs, the error reference and the `prisma-8` skill describe the end state. The upgrade note is in `upgrade-instructions/pending/mongo-stored-name-renames/`. - The project's handover notes are removed, and `projects/migration-statements/plan.md` lists every merged piece of the project. ## How it was checked - Planner tests in `packages/3-targets/mongo/1-target/test/`: the `mongo-planner.stored-name*`, `mongo-planner.enum-stored-values*`, `mongo-planner.document-moves*` and `mongo-planner.embedded-keys` files, `mongo-model-matching` and `mongo-document-moves`. - Runner tests against a live MongoDB (mongodb-memory-server) in `test/integration/test/mongo/target-runner/`: `runner-stored-name-renames`, `runner-stored-name-reruns`, `runner-document-moves*` and `runner-create-collection-reruns`, including runs stopped part way and run again. - CLI journeys in `test/integration/test/cli-journeys/`: `stored-name-renames.mongo`, `stored-name-refusals.mongo`, `stored-name-routes.mongo`, `stored-name-shared-collections.mongo` and `stored-name-db-update.mongo`. They follow every printed two-migration route and move to the end and read the documents back. - Thirty-three rounds of hands-on testing with the CLI against mongodb-memory-server, following every printed route. The reports are in `projects/migration-statements/manual-qa-reports/`. ## API changes - `@prisma/orm-family-mongo (not exported): RawAggregateOptions`, `@prisma/orm-family-mongo/query-ast/execution: RawAggregateCommand`, `@prisma/orm-family-mongo/query-ast: RawAggregateCommand`, `@prisma/orm-family-mongo/lowering: MongoLoweredDraft` and `@prisma/orm-family-mongo/wire: AggregateWireCommand`: a raw aggregate can now carry `bypassDocumentValidation`, from the query AST through lowering to the wire command, so a document move can copy past a validator that a later operation replaces. - `@prisma/orm-family-mongo/query-ast/execution: RawDeleteManyCommand`, `@prisma/orm-family-mongo/query-ast: RawDeleteManyCommand`, `@prisma/orm-family-mongo/wire: DeleteManyWireCommand` and the `collation` of `RawAggregateCommand`, `MongoLoweredDraft` and `AggregateWireCommand`: raw deletes and raw aggregates can carry a `collation`, so a move's delete selects with the collation its copy reads with. - `@prisma/orm-family-mongo (not exported): RawDeleteManyOptions`: new options type of `RawDeleteManyCommand`, holding its `collation`. - `@prisma/orm-target-mongo (not exported): DeleteDocumentsOptions`: gains the optional `collation` of `deleteDocuments`. - `@prisma/orm-family-mongo`: its `api-breaks.json` takes new fingerprints for records `main` already holds, for `buildMongoContractFromDefinition` (prisma#31185) and for the exports prisma#31218 recorded, which the compatibility check judges again because a declaration it uses changed on this branch. It also records `MongoRuntime` and `createMongoRuntime` (`./runtime`): this PR adds optional `bypassDocumentValidation` and `collation` to `RawAggregateCommand` and an optional `collation` to `RawDeleteManyCommand`, and `prepare`'s return type checks the plan's command against unions of those classes, so the comparison with 8.0.0-rc.25 reports a break, recorded as allowed: the change only adds optional members, and code written for that release still compiles. - `@prisma/orm-target-mongo`: its `api-breaks.json` takes the fingerprints this branch gives the exports prisma#31218 recorded there, because this PR changes `MongoMigrationRunnerExecuteOptions` and the planner the records depend on. - `@prisma/orm-mongo`: its new `api-breaks.json` records `MongoPrepareMember`. Its return type `MongoPreparedFrom` resolves a plan through `MongoPreparedFor`, which checks the plan's command against unions of the raw command classes this PR changes, so the comparison with 8.0.0-rc.25 reports a break, recorded as allowed: the change only adds optional members, and code written for that release still compiles. - `@prisma/orm-target-mongo/target/migration: deleteDocuments` and `@prisma/orm-target-mongo/target: deleteDocuments`: the `deleteDocuments` factory takes a `collation` option, which the move route prints. - `@prisma/orm-family-mongo/family/schema-verify: collationsMatch` and `@prisma/orm-family-mongo/family: collationsMatch`: new; the verifier's rule for whether two collations match, shared with the runner. - `@prisma/orm-target-mongo/target/migration: rawAggregate` and `@prisma/orm-target-mongo/target: rawAggregate`: the `rawAggregate` factory takes the same option, as `rawUpdateMany` already did. - `@prisma/orm-family-mongo/contract/data-type: codecStoresValue`: new; tells whether a codec can store a value, used to pick a temporary value when enum stored values are swapped. - `@prisma/orm-family-mongo/family/schema-verify: isDisabledChangeStream`, `@prisma/orm-family-mongo/family/schema-verify: isSimpleCollation`, `@prisma/orm-family-mongo/family/schema-verify: reportedCappedMax`, `@prisma/orm-family-mongo/family/schema-verify: reportedCappedSize`, `@prisma/orm-family-mongo/family/schema-verify: reportsValidator` and `@prisma/orm-family-mongo/family: isDisabledChangeStream`, `@prisma/orm-family-mongo/family: isSimpleCollation`, `@prisma/orm-family-mongo/family: reportedCappedMax`, `@prisma/orm-family-mongo/family: reportedCappedSize`, `@prisma/orm-family-mongo/family: reportsValidator`: now exported, so the target's `createCollection` after-check and the schema verifier share one rule for what MongoDB reports. They are for internal use. - `@prisma/orm-target-mongo (not exported): MongoPlanOptions`, `@prisma/orm-target-mongo/target/control: MongoMigrationPlanner` and `@prisma/orm-target-mongo/target: MongoMigrationPlanner`: the planner takes the stored-name rename statements and refuses the changes it cannot carry out. - `@prisma/orm-target-mongo/target/control: MongoMigrationRunnerExecuteOptions` and `@prisma/orm-target-mongo/target: MongoMigrationRunnerExecuteOptions`: the option `checkedPolicies`, released in 8.0.0-rc.25, is renamed `policiesInForce`, and every contract space's runner now receives it, so its advice offers only routes the policy permits; the runner itself guards only the application space's marker with it. Code that passes `checkedPolicies` must rename it, as the upgrade note says. The compatibility check cannot see a renamed optional property, so the existing records for `MongoMigrationRunner` and `MongoMigrationRunnerExecuteOptions` name it in their reasons. ## Alternatives considered - **Keep the consent prompt and the by-hand rename.** ADR 324 rejects this for every database: a user who changed `@@map` either lost the documents or renamed the collection by hand. - **Run the migration in a MongoDB transaction.** Collection commands such as `renameCollection` cannot run inside one, and transactions need a replica set. - **Record each operation's progress so a stopped chain can resume.** [ADR 188](docs/architecture%20docs/adrs/ADR%20188%20-%20MongoDB%20migration%20operation%20model.md) makes a migration only self-contained operations, each checking the database before and after, with no progress record. - **Copy the moving model's documents with validation on.** In some plans no position works: before the source's rewrites, the target's old validator rejects the copy; after them, the rewrites have already changed the documents. Ordering the plan by collection does not help, because the target's operations would also have to come before the source's. - **Ask about the documents a model leaves behind in a shared collection.** A question must belong to an operation that loses data, and here the plan may have none. It would also need a new kind of data-loss question in the CLI framework. - **Print a query that finds which source documents a stopped time-series copy took.** Each version had a case it got wrong: a time-series collection does not keep `_id` unique, sorts the keys of an object `metaField`, and keeps no earlier form of a document that changed after the copy. When the user cannot be sure nothing wrote to either collection, the advice says to delete nothing and settle the two collections by hand. Closes TML-3840. Agent: gandhi-65 --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At a glance
A capability is a named yes-or-no feature of the environment a PostgreSQL application runs in, such as
sql.lateral(the database has lateral joins) orsql.interactiveTransactions(the connection can hold a transaction open). Until now every PostgreSQL contract was given the same fixed set, whatever the project ran on.A contract now lists the capabilities it requires, from two lists Prisma exports: one for a PostgreSQL version, one for the driver's connection.
A project that has not added the list yet keeps working until 8.0. When it runs
prisma contract emit, it gets a warning with the exact text to add:The decision
The problem. A project could type-check a feature its environment lacks and find out when a query failed, for three reasons:
prisma db sign, which records that a database matches a contract) never compared the database with the contract's capabilities.The decision. Capabilities are a contract's dependencies. A database version or a connection provides them, and a contract requires them. Three rules follow:
requiredCapabilitiesis everything the contract requires. From 8.0 it is required and has no default, so every capability an error names is one the author can find in their own source.What breaks, and for whom. For a project on release candidate 25 that uses the PostgreSQL package's
defineConfig: nothing, until 8.0 (the stopgap below). Three things do change:db sign,db verify,db init,db updateanddb migrate. Before, onlyinit --probe-dbwarned about it.defineConfigand not the PostgreSQL package's, gets no default. Its next emit writes a contract with no capabilities. The upgrade instructions detect this form and give the one line to add.Why before 8.0. A required input and a change to which capabilities a contract contains would each need a major version afterwards.
How it works
Two lists
postgres15…postgres18postgresDriverThey are separate because they change separately. A project behind a connection pooler that cannot hold a transaction open keeps its database's list and leaves
sql.interactiveTransactionsout.All four version lists are equal today: no feature Prisma supports needs more than PostgreSQL 15. So it does not matter yet which one a project spreads, and
initwrites the newest. A version's list is fixed for a major version of Prisma, and a test pins each one. A feature that needs a newer server arrives with a new list, such aspostgres19, so a project that spreadspostgres18on a PostgreSQL 15 server is never refused by a later minor release.A capability is removed by leaving it out:
postgres18.filter((key) => key !== 'sql.jsonAgg'). TypeScript infers a type predicate from that comparison, so the key leaves the contract's type too, and the features that need it stop type-checking. A test covers it.Where the list is written
A TypeScript contract: in
defineContract, as above.A contract in the Prisma schema language: in the config, because the schema language has no syntax for it yet. That syntax is designed and not built; the config entry is a stopgap for it.
A project that keeps its Prisma 7 schema:
prisma7Schema(path, { requiredCapabilities }).prisma orm initwrites the list into a new project.contract.jsonstores the capability keys in itscapabilitiesfield, in the same shape as before, and never a database version.What is checked, and what the user sees
The database lacks a required capability.
db verify,db sign,db init,db updateanddb migrateprint one message and change nothing. They suggest no command, because none upgrades a server. The capability in this example does not exist; it stands for one that PostgreSQL would have from version 17:One limit: signing checks only the capabilities in its version table. It cannot tell a database capability it does not know from a connection capability, so the client reports those instead. The next pull request removes this limit (see "Not in this pull request").
The connection lacks a required capability. Where the application imports the contract's generated types, creating the client is a type error that names the capability. When the client starts, it logs a warning:
It is a warning and not a failure because the client's checks at start never stop a running application;
prisma db verifyis the command that fails a deploy.A feature's capability is not in the list. The call is refused, and it is a type error where TypeScript can see the need, as with
transaction(). Every such refusal now has one form (there were six):Release candidate projects keep working
The goal: a project exactly as release candidate 25 left it, with its config, its contract source and its emitted
contract.jsonunchanged, keeps type-checking, emitting and running after it upgrades, with warnings only. Three things make that so. All three are a stopgap, removed at 8.0.initwrites. The CLI commands that load the contract's source, such ascontract emit, print the warning shown at the top, with text that compiles when pasted. An application that loads its contract prints nothing.contract.jsonlists nine flags that nothing ever read:postgres.orderBy,postgres.limit,postgres.lateral,postgres.jsonAgg,postgres.returning,sql.enums, and three that extensions declared (pgvector.cosine,postgis.geometry,paradedb/bm25). The live flagssql.lateralandsql.jsonAggare different keys and stay. This pull request stops emitting the nine, and the client's check skips them, so an oldcontract.jsontype-checks and starts without a warning. A retired flag written into a new list is refused.contract.jsoncan still calltransaction(). The default in point 1 only helps once a project emits again. Until then itscontract.jsonhas nosql.interactiveTransactions, because that flag is new. A contract that lists a retired flag can only have come from a release candidate, whose clients all offeredtransaction(), so it is allowed.The proof. A test takes three projects' files from the tag
v8.0.0-rc.25, byte for byte and pinned by checksum, and checks that each type-checks, emits with the warning, creates a client with no warning, and runs a query and atransaction(). It runs in pull request CI.What a project does. Nothing before 8.0. To stop the warning: add the list as the warning shows, and run
prisma contract emit. This pull request alone does not require signing databases again. #31203 will, because it makes a contract's signature cover its capability list.Removing it. Every declaration that is part of the stopgap has "Prisma 8.0 removes" in its doc comment, so one search finds them all.
Changes to the framework
The framework packages must not know about any one database, so each change there is listed with why it is there:
PostgreSQLin the text comes from the target.db update. It gives no such advice while the database is refused, because those commands are refused too.initasks the database package for the config'scontract:entry. The CLI writesprisma.config.tsand cannot know what a database's entry contains. An optionalcontractEntrymember returns it, written with the tools migration files are already written with: an object that renders TypeScript source and lists the imports it needs. Without the member,initwrites the path as before.API changes
@prisma/orm-postgres:defineContract, the config's contract entry andprisma7SchematakerequiredCapabilities; the listspostgres15topostgres18andpostgresDriverand the typeRequiredCapabilitiesare added;postgresContractCapabilitiesbuilds a capability set from a list; the client's type checks its connection against the contract; and theinitentrypoint returns the config's contract entry.@prisma/orm-target-postgres: the target holds the table of capabilities by version, the server version range and the retired capabilities; its adapter and its control descriptors declare no capabilities, and the driver declaressql.interactiveTransactions.@prisma/orm-family-sql: the client's check of its connection (StackProvides,capabilitiesNotProvidedand the types around them), the one message for an unavailable feature (capabilityUnavailableMessage, which replacesmissingCapabilityRemedy), the check fortransaction(), the target hookdatabaseCapabilitiesNotProvided, andisSourceGivenNoCapabilitiesfor the release candidate default.@prisma/orm-framework: the types and the text function for a database that does not provide what a contract requires (DatabaseCapabilitiesNotProvidedand the names around it), and the mismatch explanation that carries it.@prisma/orm-toolchain: theinitcontribution'scontractEntrymember and its types (ContractEntryNode,ContractEntryInput,ConfigModuleExports).@prisma/orm-extension-supabase: its client checks its connection against the contract, as the PostgreSQL client does, so its client andRoleBoundDbtypes change.@prisma/orm-extension-pgvector,@prisma/orm-extension-postgisand@prisma/orm-extension-paradedb: each stops declaring a capability flag that nothing read, so its pack's type loses thecapabilitiesfield.@prisma/orm-better-auth:prismaAdapterrequires a client withtransaction()only when thetransactionoption is on, and reads the client's retired capabilities so a release candidate contract is accepted.@prisma/orm-target-mysql,@prisma/orm-target-mariadband@prisma/orm-target-sqlite: each adapter's capability list gainssql.interactiveTransactions, whichtransaction()now requires of a contract.@prisma/orm-mysql,@prisma/orm-mariadband@prisma/orm-sqlite: each re-exports the SQL family's newcapability-messagesentry.@prisma/orm-family-mongo,@prisma/orm-mongoand@prisma/orm-target-mongo: no export of theirs changes; each gains records, because their verification types include the cause of a schema difference, which gains a member (below).Breaks against release candidate 25, each recorded in its package's
api-breaks.json. These reach code written against the packages' lower-level types, such as tooling and extensions. Only thetransaction()one touches code an application writes, and a release candidate's contract can still call it.database-capabilities-not-provided, and the migration runner can fail withMIGRATION.DATABASE_CAPABILITIES_NOT_PROVIDED. Code that handles every cause or every code stops compiling until it handles the new one. This one cause is 321 of the 363 records, in every package whose types include it.serverVersionNumberin place of the textpgVersion.transaction()is a type error for a contract that does not requiresql.interactiveTransactions.Four things stay as release candidate 25 had them until 8.0, so that code written against it keeps compiling: the import paths of
POSTGRES_MIN_SERVER_VERSIONandpostgresAdapterCapabilities, the fifth argument ofrenderLoweredSql, and thedriveroption ofcreateExecutionContext. The last two are ignored. The API check cannot see a removed parameter, so a type test covers each.Merge order
#31203 makes a contract's signature cover its capability list. The two pull requests can merge in either order. Whichever merges second regenerates the emitted fixtures.
Reading the diff
Most changed files are mechanical: about 450 configs, contracts, examples and tests gained the list. The substance is in:
packages/3-targets/postgres/1-target/src/core/server-version.tsandretired-capabilities.ts: the table of versions and the retired flags.packages/3-targets/postgres/9-facade/src/contract/andsrc/config/: the list, the default and the warning.packages/2-sql-family/5-runtime/src/stack-capabilities.ts: the client's check.packages/1-framework/1-core/framework-components/src/control/database-capabilities-not-provided.ts: the refusal as data.packages/1-framework/3-tooling/cli/src/commands/init/andpackages/3-targets/postgres/9-facade/src/init/: whatinitwrites.test/e2e/framework/test/release-candidate-project.test.ts: the proof for release candidate projects.docs/architecture docs/adrs/ADR 335 - A contract lists the capabilities it requires.md: the decision record.Not in this pull request
contract.jsonstill calls the fieldcapabilities, and keys still start withsql.orpostgres.. The next pull request, before 8.0, renames the field torequiredCapabilitiesand prefixes each key by its provider (db.orconn.). Signing can then refuse any database capability its table does not know. It is separate because it is a pure rename across about 700 hand-written files.Alternatives considered
contract.jsonwould stop type-checking.databaseVersion: 17) in place of a list. It hid the connection's capabilities behind a default, and the number read as the exact version the database runs, when it is the oldest the contract supports.capabilities). "The contract's capabilities" reads as what the contract can do.Linear: TML-3960
Agent: heathcliff-78
🤖 Generated with Claude Code