| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
feat(mongo): prisma6Schema reads a Prisma 6 MongoDB schema.prisma as the contract source (#30405) > Stacked on #30403 (Mongo execution defaults), which is stacked on #30396 and #30399. Until those merge, their commits appear in this diff; the slice 5 work starts at commit e33782e604. A Prisma 6 MongoDB project can point Prisma 8 at its existing `schema.prisma` and get a contract without rewriting anything: ```ts // prisma.config.ts import { definePrismaConfig } from 'prisma/config'; import { defineConfig as ormConfig, prisma6Schema } from '@prisma/orm-mongo/config'; export default definePrismaConfig({ orm: ormConfig({ contract: prisma6Schema('prisma/schema.prisma'), db: { connection: process.env['DATABASE_URL']! }, }), }); ``` ```prisma // prisma/schema.prisma, unchanged Prisma 6 model Post { id String @id @default(auto()) @map("_id") @db.ObjectId title String views BigInt meta Json authorId String @db.ObjectId author User @relation(fields: [authorId], references: [id]) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@index([authorId]) } ``` `prisma contract emit` produces the same contract Prisma 8 PSL would for the equivalent model written with `ObjectId`, `Int64`, `Json`, `temporal.createdAt()`, and `temporal.updatedAt()`, and `prisma db sign` verifies it against the database Prisma 6 built with zero findings. ## The decision The Prisma 6 MongoDB dialect is a first-class contract source, read by its own package (`@internal/mongo-contract-prisma6`, published as `@prisma/orm-family-mongo/provider`) that mirrors the Prisma 7 Postgres reader shipped in #30287. It parses with the Prisma 8 parser in its Prisma 7 grammar mode and builds the Mongo contract directly from the family's exported building blocks, so the storage hash and execution hash come from the same code the Prisma 8 interpreter uses. Everything the reader cannot express is a hard error with a `PSL.PRISMA6_MONGO_*` code and a span; nothing is silently dropped or approximated (ADR 252). The function is named `prisma6Schema` because Prisma 7 has no MongoDB connector, so the dialect it reads is Prisma 6's. ## How the pieces fit **Binding.** The Mongo target supplies a `Prisma6TargetBinding` (accepted providers, the scalar-to-codec map, the ObjectId codec, the timestamp generator id). The reader holds no target facts, matching the Prisma 7 reader's `Prisma7TargetBinding`. **What maps.** `String`, `Int`, `Float`, `Boolean`, `DateTime` to the existing codecs; `BigInt`, `Decimal`, `Bytes`, `Json` to the codecs #30396 added; `String @db.ObjectId` to the ObjectId codec; `DateTime @default(now())` to an on-create `timestampNow` generator and `@updatedAt` (with or without `@default(now())`) to on-create plus on-update, which is what `temporal.createdAt()` and `temporal.updatedAt()` from #30403 produce; composite `type` blocks to value objects; enums with member `@map` storage values; to-one `@relation(fields, references)`; `@unique`, `@@unique`, `@@index` with sort order; `@@fulltext` to a text index; `@map` and `@@map`; `@ignore` and `@@ignore` omitted. Index names are dropped: Mongo verify matches indexes by keys and options, never by name. **What is a hard error, expected to flip later as the Mongo family gains each capability.** Composite ids, `@map` on a composite-type field, referential actions on `@relation`, the scalar-list many-to-many shape, `@default` values other than `now()` and `auto()` on `_id` (Mongo has no storage defaults and registers no id generators), optional generated fields, `@updatedAt` on a non-`DateTime`, other `@db.*` types, `Unsupported(...)`, `view`, and `@@schema` (which has no Mongo meaning and stays an error). **No validators.** The Prisma 8 Mongo PSL interpreter emits a strict `$jsonSchema` validator per collection; a Prisma 6 database has none, and Mongo verify fails on a declared-but-missing validator. The reader emits none, which the TypeScript builder already does, so `db sign` passes against the database as Prisma 6 left it. The parity test shows validators are the only storage difference from the equivalent Prisma 8 PSL contract. **Facade.** `defineConfig` in `@prisma/orm-mongo/config` accepts `contract: string | ContractConfig`, exactly as the Postgres facade does, and exports `prisma6Schema`. **Also in this PR.** The Prisma 8 Mongo PSL interpreter now reports unknown top-level blocks (`view`, `datasource`, `generator`) with `PSL_UNSUPPORTED_TOP_LEVEL_BLOCK` instead of dropping them silently, mirroring SQL. The storage builder and back-relation pairing the reader shares with the interpreter were hoisted into the family packages so there is one implementation of each. ## What you will see in the diff - **Fixtures.** One case per rule-table row and per error code under `packages/2-mongo-family/2-authoring/contract-prisma6/test/fixtures/`, in the Prisma 7 reader's layout (`schema.prisma` or a `schema/` directory, `expected-contract.json` or `expected-diagnostics.json`, regenerated with `UPDATE_PRISMA6_FIXTURES=1`), plus a parity test against the equivalent Prisma 8 PSL schema. - **CLI journey.** `test/integration/test/cli-journeys/prisma6-source.e2e.test.ts` creates the collections and indexes Prisma 6 `db push` would create (no validators, Prisma 6 index names, unique indexes for `@unique`), then runs `contract emit`, `db sign`, and `db verify` through the CLI: zero findings in lenient and strict mode. An extra undeclared index is a warning in lenient mode and a failure in strict mode, as expected. - **Shared building blocks.** `buildMongoStorage` and `encodeMongoValueSets` now live in `@internal/mongo-contract`, and `pairMongoBackRelations` in `@internal/mongo-contract-psl`; the Prisma 8 interpreter and the reader both call them, and `fixtures:check` shows no hash moved. - **Docs.** `prisma6Schema` section in the Mongo facade README, the `PSL.PRISMA6_MONGO_*` codes in `docs/reference/error-reference.md`, and notes in the Prisma 8 skill references. The superseded slice spec under the Prisma 7 contract-source project is deleted and that project's deferred-gaps entries for Mongo defaults and codecs are marked filled. ## Alternatives considered - **Rewriting the Prisma 6 file into Prisma 8 syntax and running the Prisma 8 interpreter.** Rejected: several Prisma 6 facts have no channel through the interpreter (composite `@map`, enum member `@map`, the ObjectId codec on a `String` field), and every rewrite would be a lossy rule. The Postgres reader builds the contract directly for the same reason. - **Emitting validators and asking users to apply them before signing.** Rejected for the adoption story: `db sign` must pass against the database Prisma 6 built; validators come with the switch to Prisma 8 PSL. - **Warnings for unsupported constructs.** Rejected by ADR 252: a construct the reader cannot express is a hard error, and each error is a signal to build the feature. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Use Prisma 6 MongoDB schemas from a file or directory as contract sources. * Schema interpretation supports models, relations, indexes, enums, composite types, lists, and timestamps. * Mongo configuration accepts either a contract source path or a contract configuration. * Sign and verify MongoDB databases against emitted contracts; verification reports undeclared indexes. * **Bug Fixes** * `contract emit` identifies unsupported indexes on composite-type fields and suggests indexing a top-level field or removing the index. * **Documentation** * Added guidance on supported schemas, configuration, and database ownership during migration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> | 22 小时前 | |
refactor(runtime): mutation-default generators run once, in the framework, for SQL and Mongo (#30406) > Stacked on #30405, which is stacked on #30403, #30396 and #30399. Until those merge, their commits appear in this diff; the slice 4 work starts at commit 7795377a4b. Both database families now run the same write-time default machinery. The SQL runtime and the Mongo runtime each call three framework functions instead of carrying their own registry, availability check, and apply loop: ```ts import { applyMutationDefaults, assertMutationDefaultGeneratorsAvailable, collectMutationDefaultGenerators, } from '@internal/framework-components/runtime'; const generators = collectMutationDefaultGenerators([target, adapter, ...extensions]); assertMutationDefaultGeneratorsAvailable(contract.execution, generators); // per ORM operation: applyMutationDefaults(contract.execution, generators, { op: 'create', namespace, entry, values, defaultValueCache }); ``` A generator is `{ id, generate(params?), stability: 'field' | 'row' | 'query' }`, typed once in the framework; the SQL and Mongo `timestampNow` generators and the Postgres Temporal generators all use that type. ## The decision The mutation-default runtime is framework-owned. It was written for SQL and lived in `@internal/sql-runtime`; #30403 gave Mongo a deliberate short-lived copy so the Mongo work could land without touching SQL. This PR deletes both copies and moves the code, with the SQL semantics verbatim, into `framework-components/src/execution/mutation-defaults.ts`. Nothing in it was ever SQL-specific except the option key names, and #30399 had already made the contract reference neutral; this PR finishes the rename in the runtime options (`table` becomes `entry`, `column` becomes `field`). ## How the pieces fit **Semantics, unchanged from SQL.** A duplicate generator id refuses context creation naming both owners; a contract that requires a generator no component provides refuses context creation listing the ids; a key present in the values is explicit whatever its value; an update with no keys applies nothing; `'row'` stability gives one value per row per call, `'query'` one per operation through the caller's cache, `'field'` none; a reference is applied once per call. The unit tests moved from the SQL runtime package to the framework and run against plain contributor objects; the SQL package keeps only its wiring tests. **SQL.** The runtime calls the framework in the same place it ran its own code, after codec collection. The lanes' `ExecutionContext` extends the framework `MutationDefaults` interface. The ORM client, the mutation executor, and the SQL builder lane follow the option and result key rename. A new SQL builder test pins the existing rule that a key present with an `undefined` value counts as explicit. **Mongo.** The runtime copy from #30403 is deleted; `MongoExecutionContext` extends the same `MutationDefaults` interface and the Mongo ORM depends on it. The Mongo `undefined`-as-absent behaviour is a caller rule and its tests moved to the ORM level. **One execution-section builder.** `buildExecutionSection` in `@internal/contract` sorts defaults by namespace, entry, field and computes `executionHash`; both families' authoring paths use it. SQL previously sorted without the namespace key, so two multi-namespace fixtures re-hash; everything else is byte-identical. **ADR and docs.** ADR 255, "Mutation-default generators are a framework runtime concern", records the generator contract, the three stabilities and their caches, the availability check and its two error codes, the explicit-key rule and why `namespace` is required, the neutral reference and the sort order, and why each family keeps its own check position. ADR 158's example is updated; subsystem 4 (Runtime & Middleware Framework) gains a mutation-defaults section and subsystem 10 points at it. ## What you will see in the diff - **Deleted code.** The registry, availability check, apply loop, and generator types are gone from `packages/2-sql/5-runtime/src/sql-context.ts` and `packages/2-mongo-family/7-runtime/src/mongo-execution-stack.ts`; both keep only the wiring. `mongo-contract`'s `mutation-defaults.ts` and `build-execution-section.ts` are deleted. - **Renamed keys in SQL callers.** `table` → `entry` and `column` → `field` in the SQL ORM client, the mutation executor, the SQL builder lane, and their test stubs. Nothing else in those files changes. - **Moved tests.** The SQL runtime's generator tests now live in `framework-components/test/mutation-defaults.test.ts` and run against plain contributor objects; the SQL and Mongo runtime packages keep wiring tests only (including a new test per family pinning where the check runs relative to codec collection). The Mongo ORM gains tests that it strips `undefined` before calling the framework. - **Dependencies.** `family-sql` no longer depends on `sql-runtime` and `family-mongo` no longer depends on `mongo-runtime`; neither had a source import left. - **Fixtures.** Two multi-namespace SQL fixtures re-hash (`test/integration/test/ports/prisma/functional/multi-schema/_fixture/{different-names,no-map}`), the only contracts whose execution defaults span more than one namespace and were not already in namespace order. - **Upgrade instructions.** `upgrade-instructions/pending/mutation-default-runtime-in-framework/extension/instructions.md` covers the moved SQL and Mongo types, the renamed option and result keys, and `buildMongoExecutionSection` → `buildExecutionSection`. ## Alternatives considered - **Keep two copies and let them drift.** Rejected: the caching rule and the error contract are exactly the kind of thing that diverges silently, and the two copies had already diverged in `undefined` handling and check placement. - **Hoist before building the Mongo half.** Rejected during shaping: the framework reference still carried SQL names then, and the Mongo work would have blocked on a SQL-wide rename. Doing it in this order kept each PR reviewable. - **Treat `undefined` as absent inside the framework.** Rejected: that would change the SQL builder lane's behaviour; callers that want it (both ORMs) already filter before calling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Generated mutation defaults are now handled consistently across SQL and MongoDB operations, with shared support for create and update defaults. * Defaults can be scoped to a specific entry and field, with configurable value reuse and checks for missing or duplicate generators. * Execution defaults are sorted consistently before hashing, supporting stable contract results across environments. * **Documentation** * Added guidance on mutation-default behavior, generator stability, and execution-section construction. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> | 12 小时前 | |
chore(release): bump to 8.0.0-rc.12 (#30395) ## Release: 8.0.0-rc.11 → 8.0.0-rc.12 This is the release PR described in [docs/oss/versioning.md](https://github.com/prisma/orm/blob/main/docs/oss/versioning.md). It bumps every workspace package to 8.0.0-rc.12 and moves the Prisma dependencies to their latest versions. **Merging this PR ships the release.** The push to `main` carries the new root `version`. The `Publish to npm` workflow then publishes 8.0.0-rc.12 under `latest` and creates a pre-release GitHub Release from the notes file. ## Review these first - [docs/releases/v8.0.0-rc.12.md](https://github.com/prisma/orm/blob/release/8.0.0-rc.12/docs/releases/v8.0.0-rc.12.md): the release notes, which become the GitHub Release body. The same entry is at the top of `CHANGELOG.md`. - The upgrade guides for [apps](https://github.com/prisma/orm/blob/release/8.0.0-rc.12/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md) and [extensions](https://github.com/prisma/orm/blob/release/8.0.0-rc.12/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md). They merge the 24 pending fragments. The original fragments are moved unchanged to `upgrade-instructions/releases/8.0.0-rc.11-to-8.0.0-rc.12/sources/`. - Four guide entries have no fragment behind them. The `migration new` default and its removed error codes (#30389) had no guide entry. Neither did the PSL parser API changes (#30312, #30344, #30335, #30379). I wrote those entries while preparing the release. - Where fragments contradicted later code, the guide follows the code. Examples: the Supabase storage hash, `voidParamsSchema`, and quoted defaults printed by `infer`. ## Dependency updates | Package | From | To | Where | | --- | --- | --- | --- | | `@prisma/cli-engine` | 0.4.0 | 0.6.1 | examples, test fixtures, apps (the toolchain packages were already on 0.6.1 from #30372) | | `@prisma/dev` | 0.25.1 | 0.25.2 | the workspace catalog | | `@prisma/compute-sdk` | ^0.39.0 | ^0.43.0 | `apps/telemetry-backend` | | `@prisma/management-api-sdk` | ^1.56.0 | ^1.76.0 | `apps/telemetry-backend` | compute-sdk 0.43 renames "service" to "app" and "version" to "deployment". The telemetry deploy script now uses the new names. Both SDK versions call `/v1/apps/{appId}`, so the ID stored in the existing `TELEMETRY_DEPLOY_SERVICE_ID` secret is still correct. The app's typecheck now includes `scripts/`, so it catches the next SDK rename. The repo does not depend on `@prisma/composer`. ## Fixes needed to publish - **The publish workflow has failed on `main` since #30372.** `check:conformance` called the `orm` config validator as `validate(value)`. Engine 0.6 always calls `validate(value, provenance)`, and the validator reads `provenance.files`, so it threw on every input. The check now passes the same provenance the engine would. The prisma-cli copy of this check already does this. - `set-version` rewrote `workspace:@internal/cli@<version>` to `workspace:<version>`, dropping the alias. The prisma7-adoption example uses that alias. This is the first bump since the alias was added. - `lint:legacy-name` and the `add-model-map` test pointed at the pending fragment paths. They now point at the archived sources. ## Verification Passed locally: - `pnpm build` - `pnpm typecheck` - `pnpm lint` - `pnpm test:scripts` (563 tests) - `pnpm check:conformance` - `pnpm check:publish-deps` - `pnpm check:upgrade-coverage`, in both publish and PR mode - `pnpm check:release-notes`, in both publish and PR mode - `pnpm lint:legacy-name` - `pnpm lint:skills` - `pnpm test:packages`: all 18,196 tests passed Not covered locally, left to CI: - Three `test:packages` suites install packed tarballs from the registry. This machine's pnpm refuses `@vercel/detect-agent@1.2.5` because it has no provenance. CI passed the same suites on #30390. - `prisma-8-cloudflare-worker` needs a local Hyperdrive database. - The telemetry backend tests need Node 24.16 with `Temporal`. This machine has 24.13. - `fixtures:check` needs Postgres. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added PostgreSQL full-text search, multi-file schemas, prepared ORM reads and aggregates, and conflict-skipping options for bulk creation. * Added support for using a Prisma 7 schema as the contract source, JavaScript `Date` timestamps on PostgreSQL, editor support for attribute arguments, and per-finding diagnostics. * **Breaking Changes** * Prisma 8 schema files now require `// use prisma-8` on the first line; unmapped models use their names verbatim for table names. * Replace `dbgenerated(...)` with SQL tagged literals. Defaults must be valid for their column types, creation timestamps use the application clock, and native PostgreSQL enums no longer support text operations. * Config naming and path resolution, migration starting points, and extension contracts have changed. * **Bug Fixes** * Improved migration checks and branching warnings, contract generation and inference, default verification, and type checking. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> | 3 天前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 22 小时前 | ||
| 12 小时前 | ||
| 3 天前 |