@prisma/orm-mongo 8.0.0-rc.25-dev.29 → 8.0.0-rc.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/bson.d.mts +2 -1
- package/dist/components__runtime.d.mts +3 -1
- package/dist/config.d.mts +2 -1
- package/dist/config.d.mts.map +1 -1
- package/dist/contract-builder.d.mts +11 -12
- package/dist/contract-builder.d.mts.map +1 -1
- package/dist/contract-types.d.mts +5 -3
- package/dist/contract__types.d.mts +3 -1
- package/dist/control.d.mts +2 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/family-contract.d.mts +3 -1
- package/dist/family-runtime.d.mts +3 -1
- package/dist/family.d.mts +2 -1
- package/dist/family__control.d.mts +3 -1
- package/dist/init-quick-reference.md +1 -1
- package/dist/init.d.mts +2 -1
- package/dist/init.d.mts.map +1 -1
- package/dist/migration-tools__aggregate.d.mts +3 -1
- package/dist/migration-tools__hash.d.mts +3 -1
- package/dist/migration-tools__io.d.mts +3 -1
- package/dist/migration-tools__spaces.d.mts +3 -1
- package/dist/migration.d.mts +3 -1
- package/dist/{mongo-static-CZlnpepm-DnjIfx0L.mjs → mongo-static-DnxWWp96-D-vo6-SA.mjs} +4 -4
- package/dist/mongo-static-DnxWWp96-D-vo6-SA.mjs.map +1 -0
- package/dist/orm.d.mts +3 -1
- package/dist/query-ast__execution.d.mts +3 -1
- package/dist/query-builder.d.mts +3 -1
- package/dist/runtime.d.mts +3 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +6 -6
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.d.mts +2 -1
- package/dist/static.d.mts.map +1 -1
- package/dist/static.mjs +1 -1
- package/dist/target.d.mts +2 -1
- package/dist/target__codec-ids.d.mts +3 -1
- package/dist/target__codec-types.d.mts +3 -1
- package/dist/target__migration.d.mts +3 -1
- package/dist/target__runtime.d.mts +2 -1
- package/dist/value.d.mts +3 -1
- package/dist/vite-plugin-contract-emit.d.mts +3 -1
- package/package.json +12 -81
- package/skills/prisma-8/SKILL.md +8 -8
- package/skills/prisma-8/references/contract.md +8 -8
- package/skills/prisma-8/references/debug.md +11 -11
- package/skills/prisma-8/references/migration-model.md +17 -17
- package/skills/prisma-8/references/migration-review.md +21 -21
- package/skills/prisma-8/references/migrations.md +58 -42
- package/skills/prisma-8/references/queries-postgres.md +51 -8
- package/skills/prisma-8/references/queries.md +2 -2
- package/skills/prisma-8/references/quickstart.md +11 -11
- package/skills/prisma-8/references/runtime.md +3 -3
- package/skills/prisma-8/references/supabase.md +2 -2
- package/skills/prisma-8/references/upgrade-app.md +56 -23
- package/skills/prisma-8/references/upgrade-extension.md +35 -14
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +2385 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +2048 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +667 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +667 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +1996 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +586 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +1 -1
- package/skills/prisma-8/upgrading/extension/upgrades/0.8-to-0.9/instructions.md +1 -1
- package/skills/prisma-8/upgrading/extension/upgrades/0.9-to-0.10/instructions.md +1 -1
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +2043 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +2048 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +667 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +667 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +1996 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +586 -0
- package/dist/adapter.d.mts +0 -1
- package/dist/adapter.mjs +0 -2
- package/dist/adapter__control.d.mts +0 -3
- package/dist/adapter__control.mjs +0 -3
- package/dist/adapter__runtime.d.mts +0 -3
- package/dist/adapter__runtime.mjs +0 -3
- package/dist/components.d.mts +0 -1
- package/dist/components.mjs +0 -2
- package/dist/components__authoring.d.mts +0 -1
- package/dist/components__authoring.mjs +0 -2
- package/dist/components__codec.d.mts +0 -1
- package/dist/components__codec.mjs +0 -2
- package/dist/components__components.d.mts +0 -1
- package/dist/components__components.mjs +0 -2
- package/dist/components__control.d.mts +0 -1
- package/dist/components__control.mjs +0 -2
- package/dist/components__emission.d.mts +0 -1
- package/dist/components__emission.mjs +0 -2
- package/dist/components__execution.d.mts +0 -1
- package/dist/components__execution.mjs +0 -2
- package/dist/components__ir.d.mts +0 -1
- package/dist/components__ir.mjs +0 -2
- package/dist/components__psl-ast.d.mts +0 -1
- package/dist/components__psl-ast.mjs +0 -2
- package/dist/components__utils.d.mts +0 -1
- package/dist/components__utils.mjs +0 -2
- package/dist/contract.d.mts +0 -1
- package/dist/contract.mjs +0 -2
- package/dist/contract__apply-specifier-default-control-policy.d.mts +0 -1
- package/dist/contract__apply-specifier-default-control-policy.mjs +0 -2
- package/dist/contract__contract-validation-error.d.mts +0 -1
- package/dist/contract__contract-validation-error.mjs +0 -2
- package/dist/contract__default-namespace.d.mts +0 -1
- package/dist/contract__default-namespace.mjs +0 -2
- package/dist/contract__enum-accessor.d.mts +0 -1
- package/dist/contract__enum-accessor.mjs +0 -2
- package/dist/contract__format-version.d.mts +0 -1
- package/dist/contract__format-version.mjs +0 -2
- package/dist/contract__hashing-utils.d.mts +0 -1
- package/dist/contract__hashing-utils.mjs +0 -2
- package/dist/contract__hashing.d.mts +0 -1
- package/dist/contract__hashing.mjs +0 -2
- package/dist/contract__internal__format-version.d.mts +0 -1
- package/dist/contract__internal__format-version.mjs +0 -2
- package/dist/contract__is-plain-record.d.mts +0 -1
- package/dist/contract__is-plain-record.mjs +0 -2
- package/dist/contract__resolve-domain-model.d.mts +0 -1
- package/dist/contract__resolve-domain-model.mjs +0 -2
- package/dist/contract__validate-domain.d.mts +0 -1
- package/dist/contract__validate-domain.mjs +0 -2
- package/dist/contract__validate-once.d.mts +0 -1
- package/dist/contract__validate-once.mjs +0 -2
- package/dist/contract__validate-storage.d.mts +0 -1
- package/dist/contract__validate-storage.mjs +0 -2
- package/dist/driver.d.mts +0 -1
- package/dist/driver.mjs +0 -2
- package/dist/driver__control.d.mts +0 -3
- package/dist/driver__control.mjs +0 -3
- package/dist/driver__runtime.d.mts +0 -3
- package/dist/driver__runtime.mjs +0 -3
- package/dist/family-contract__canonicalization-hooks.d.mts +0 -1
- package/dist/family-contract__canonicalization-hooks.mjs +0 -2
- package/dist/family-contract__data-type.d.mts +0 -1
- package/dist/family-contract__data-type.mjs +0 -2
- package/dist/family-contract__entity-kinds.d.mts +0 -1
- package/dist/family-contract__entity-kinds.mjs +0 -2
- package/dist/family__control-adapter.d.mts +0 -1
- package/dist/family__control-adapter.mjs +0 -2
- package/dist/family__ir.d.mts +0 -1
- package/dist/family__ir.mjs +0 -2
- package/dist/family__migration.d.mts +0 -1
- package/dist/family__migration.mjs +0 -2
- package/dist/family__pack.d.mts +0 -3
- package/dist/family__pack.mjs +0 -3
- package/dist/family__runtime.d.mts +0 -1
- package/dist/family__runtime.mjs +0 -2
- package/dist/family__schema-verify.d.mts +0 -1
- package/dist/family__schema-verify.mjs +0 -2
- package/dist/migration-tools__contract-snapshot-store.d.mts +0 -1
- package/dist/migration-tools__contract-snapshot-store.mjs +0 -2
- package/dist/mongo-static-CZlnpepm-DnjIfx0L.mjs.map +0 -1
- package/dist/query-ast.d.mts +0 -1
- package/dist/query-ast.mjs +0 -2
- package/dist/query-ast__control.d.mts +0 -1
- package/dist/query-ast__control.mjs +0 -2
- package/dist/query-builder__contract-free.d.mts +0 -1
- package/dist/query-builder__contract-free.mjs +0 -2
- package/dist/target__codecs.d.mts +0 -1
- package/dist/target__codecs.mjs +0 -2
- package/dist/target__control.d.mts +0 -1
- package/dist/target__control.mjs +0 -2
- package/dist/target__data-types.d.mts +0 -1
- package/dist/target__data-types.mjs +0 -2
- package/dist/target__pack.d.mts +0 -3
- package/dist/target__pack.mjs +0 -3
- package/dist/target__server-version.d.mts +0 -1
- package/dist/target__server-version.mjs +0 -2
- package/dist/utils.d.mts +0 -1
- package/dist/utils.mjs +0 -2
- package/dist/utils__abortable.d.mts +0 -1
- package/dist/utils__abortable.mjs +0 -2
- package/dist/utils__array-equal.d.mts +0 -1
- package/dist/utils__array-equal.mjs +0 -2
- package/dist/utils__assertions.d.mts +0 -1
- package/dist/utils__assertions.mjs +0 -2
- package/dist/utils__canonical-stringify.d.mts +0 -1
- package/dist/utils__canonical-stringify.mjs +0 -2
- package/dist/utils__casts.d.mts +0 -1
- package/dist/utils__casts.mjs +0 -2
- package/dist/utils__defined.d.mts +0 -1
- package/dist/utils__defined.mjs +0 -2
- package/dist/utils__guards.d.mts +0 -1
- package/dist/utils__guards.mjs +0 -2
- package/dist/utils__hash-content.d.mts +0 -1
- package/dist/utils__hash-content.mjs +0 -2
- package/dist/utils__internal-error.d.mts +0 -1
- package/dist/utils__internal-error.mjs +0 -2
- package/dist/utils__json.d.mts +0 -1
- package/dist/utils__json.mjs +0 -2
- package/dist/utils__promise.d.mts +0 -1
- package/dist/utils__promise.mjs +0 -2
- package/dist/utils__redact-db-url.d.mts +0 -1
- package/dist/utils__redact-db-url.mjs +0 -2
- package/dist/utils__result.d.mts +0 -1
- package/dist/utils__result.mjs +0 -2
- package/dist/utils__simplify-deep.d.mts +0 -1
- package/dist/utils__simplify-deep.mjs +0 -2
- package/dist/utils__structured-error.d.mts +0 -1
- package/dist/utils__structured-error.mjs +0 -2
- package/dist/utils__suppress-idle-connection-errors.d.mts +0 -1
- package/dist/utils__suppress-idle-connection-errors.mjs +0 -2
- package/dist/utils__text.d.mts +0 -1
- package/dist/utils__text.mjs +0 -2
- package/dist/utils__types.d.mts +0 -1
- package/dist/utils__types.mjs +0 -2
- package/dist/utils__upgrade-guides.d.mts +0 -1
- package/dist/utils__upgrade-guides.mjs +0 -2
- package/dist/value__mongodb-types.d.mts +0 -1
- package/dist/value__mongodb-types.mjs +0 -2
|
@@ -61,7 +61,7 @@ db.orm.public.User.where((u) => u.email.eq('alice@example.com'));
|
|
|
61
61
|
db.orm.public.User.where({ kind: 'admin' });
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
Operators on the field proxy include `.eq`, `.neq`, `.lt`, `.lte`, `.gt`, `.gte`, `.like`, `.ilike`, `.in([...])
|
|
64
|
+
Operators on the field proxy include `.eq`, `.neq`, `.lt`, `.lte`, `.gt`, `.gte`, `.like`, `.ilike`, `.in([...])` (or a prepared list parameter, see *Prepared `in` with a list parameter*), `.isNull()`, `.isNotNull()`. Extensions add target-specific operators on extension-typed columns (`pgvector`'s `.cosineDistance(...)`, `postgis`'s `.within(...)` / `.intersectsBbox(...)` / `.distanceSphere(...)`).
|
|
65
65
|
|
|
66
66
|
**Full-text search** is built into the Postgres target, on any text column: `.fullTextMatches(q)` is the predicate, `.fullTextRank(q)` scores a row so you can order by relevance, and `.fullTextHeadline(q)` returns the text with `<b>` around the matches. The argument `q` is a `tsquery`, built with a helper from `@prisma/orm-postgres/target/full-text`. A bare string is a type error, because Postgres would read it as `tsquery` syntax without lowercasing or stemming it. Pick the helper by where the text comes from:
|
|
67
67
|
|
|
@@ -151,7 +151,7 @@ const posts = await db.orm.public.Post
|
|
|
151
151
|
.all();
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
-
The same argument reaches the callbacks inside an include refinement, a fragment and a relation filter (`some`, `every`, `none`), where the index's columns follow the alias the ORM gives the related table. A condition from `fns` combines with the ORM's `and`, `or` and `not`. The body of a fragment for any model (`db.
|
|
154
|
+
The same argument reaches the callbacks inside an include refinement, a fragment and a relation filter (`some`, `every`, `none`), where the index's columns follow the alias the ORM gives the related table. A condition from `fns` combines with the ORM's `and`, `or` and `not`. The body of a fragment for any model (`db.fragment(fields, body)`) gets `fns` but no indexes.
|
|
155
155
|
|
|
156
156
|
In the SQL builder, a table's `indexes` holds the same references:
|
|
157
157
|
|
|
@@ -355,6 +355,18 @@ The same holds for an `if` with an early return, a `switch`, a loop and a reassi
|
|
|
355
355
|
|
|
356
356
|
**A write refuses what it would ignore.** `updateAll`, `updateAndCount`, `deleteAll` and `deleteAndCount` change every row that matches the filter, and throw `ORM.ARGUMENT_INVALID` on a collection with a `limit`, an `offset`, a `cursor`, `distinct` or `distinctOn`; an `orderBy` is accepted. To change a page of rows, read their ids first and filter on them. `update` and `delete` change the one row `first()` returns, so the order, offset, cursor, `distinct` and `distinctOn` choose it; after `limit(0)` they change nothing and return `null`. `update` with a relation callback finds its row by the filter alone and throws on any of these and on an order.
|
|
357
357
|
|
|
358
|
+
**Setting values from SQL: the callback form.** `updateAll` and `updateAndCount` also take a callback `(model, { fns, indexes })`, the arguments of a `where` callback, that returns the values to set. It runs once per call and its values go into one `UPDATE`:
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
await db.orm.public.Post.where({ published: false }).updateAll((p, { fns }) => ({
|
|
362
|
+
slug: p.title,
|
|
363
|
+
title: 'Draft',
|
|
364
|
+
views: fns.raw`${p.views} + 1`.returns('pg/int4@1'),
|
|
365
|
+
}));
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
A value is a plain value, another field of the same codec, an `fns` result of the field's codec, or `fns.raw` with `.returns(codecId)`; there are no arithmetic functions, so an increment uses `fns.raw`. Only `updateAll` and `updateAndCount` take the callback; `update`, `upsert` and nested writes take the object form only. A value must match the field's codec and nullability and, for a copy of another field, its input type, or the call is a type error. A field comparison such as `p.views.gt(100)` is not a value. The full rules and limits are in the ORM client's README, section [Updating with expressions](https://github.com/prisma/orm/blob/main/packages/3-extensions/sql-orm-client/README.md#updating-with-expressions).
|
|
369
|
+
|
|
358
370
|
## Workflow — Custom collection classes
|
|
359
371
|
|
|
360
372
|
A custom collection class gives a model its own named queries. Extend `Collection` and pass the class to the client with the `collections` option. `db.orm` then returns the class for that model, and so does `tx.orm` inside `db.transaction(...)`:
|
|
@@ -417,13 +429,13 @@ await deleteMatching(Post.byAuthor(userId)).toArray();
|
|
|
417
429
|
|
|
418
430
|
A piece of a query used in several places is a function. Do not build a filter object and spread it into each query; write a function and pass it to `.where(...)`, `.orderBy(...)` or `.with(...)`. A **row fragment** is a function of the model accessor, and `.where(...)` and `.orderBy(...)` take it. A **query fragment** (a **fragment** for short) is a function from a collection to a collection, and `.with(...)` runs it. A **scope** is a fragment that only imposes conditions on the query, such as `createdSince` below, and is also run with `.with(...)`. When the condition is a function of one row and needs no declared fields, pass a row fragment to `.where(...)`. When the same condition should apply to every model that has some fields, write a scope: it declares the fields, checks them at run time, and returns the collection with the `Filtered` fact. `.with(...)` also runs what `.where(...)` cannot express, such as a shared `select` and `include`, an order, a limit or offset, or a variant.
|
|
419
431
|
|
|
420
|
-
**The same filter on several models.** Define a scope with `db.
|
|
432
|
+
**The same filter on several models.** Define a scope with `db.fragment(fields, body)`, on the client and on `tx`; the method is named `fragment` because it cannot know whether the body only filters. Declare each field the fragment needs with the same builder the schema uses, from the `field` and `type` that `@prisma/orm-postgres/contract-builder` exports, adding `.optional()` for a field that may be null. The body sees only those fields:
|
|
421
433
|
|
|
422
434
|
```typescript
|
|
423
435
|
import { field, type } from '@prisma/orm-postgres/contract-builder';
|
|
424
436
|
|
|
425
437
|
const createdSince = (since: Temporal.Instant) =>
|
|
426
|
-
db.
|
|
438
|
+
db.fragment({ createdAt: field.column(type.TimestamptzTemporal()) }, (rows) =>
|
|
427
439
|
rows.where((r) => r.createdAt.gte(since)),
|
|
428
440
|
);
|
|
429
441
|
|
|
@@ -460,7 +472,7 @@ await db.orm.public.Post.where({ userId }).with(postSummary).limit(20).all();
|
|
|
460
472
|
await db.orm.public.User.include('posts', (posts) => posts.with(postSummary)).all();
|
|
461
473
|
```
|
|
462
474
|
|
|
463
|
-
The body receives the plain collection of the model, without a custom class's methods. Apply the fragment before `.select(...)` or `.variant(...)`: it is refused on a collection they narrowed. Its result is always typed as the plain collection, even when the body keeps the row, so a custom class's methods are gone after it, and a filter or order applied before it is not recorded, although an earlier `.where(...)` still runs. `update` and `delete` are refused after it unless the body itself calls `where`, and `cursor` unless the body calls `orderBy`. For a filter on one model, use a class method or `db.
|
|
475
|
+
The body receives the plain collection of the model, without a custom class's methods. Apply the fragment before `.select(...)` or `.variant(...)`: it is refused on a collection they narrowed. Its result is always typed as the plain collection, even when the body keeps the row, so a custom class's methods are gone after it, and a filter or order applied before it is not recorded, although an earlier `.where(...)` still runs. `update` and `delete` are refused after it unless the body itself calls `where`, and `cursor` unless the body calls `orderBy`. For a filter on one model, use a class method or `db.fragment`. A fragment for one model refuses a collection of another model or namespace at run time with `ORM.ARGUMENT_INVALID`. Calling `.fragment(...)` on a collection with chained calls throws `ORM.ARGUMENT_INVALID`, because the fragment is built from the model alone; a filter, an order or an include before it, or a receiver typed by a type parameter such as `this` in a class method, is a compile error. Inside a class method, chain on `this` directly instead.
|
|
464
476
|
|
|
465
477
|
**A field to order by, from a request.** Pass the request's string to `orderByField` with the fields the endpoint allows. Do not index the field proxy with the raw string:
|
|
466
478
|
|
|
@@ -558,6 +570,37 @@ const rows = await db.query(plan);
|
|
|
558
570
|
|
|
559
571
|
The `.where(...)` callback receives `(fields, fns)` — `fields` is the field proxy (column references), `fns` is the operator namespace (`fns.eq`, `fns.ne`, `fns.gt`, …). Extensions inject extension-shaped helpers into the same `fns` namespace (`fns.distanceSphere`, `fns.cosineDistance`, etc.).
|
|
560
572
|
|
|
573
|
+
### Prepared `in` with a list parameter
|
|
574
|
+
|
|
575
|
+
A prepared statement (see *Prepared statements* in [`queries.md`](./queries.md)) can take a whole list as one parameter. Declare it with `many: { elementNullable }`; the value is an array, and one statement serves every list length. Use it for "rows whose id is in this list" instead of a fixed list of placeholders, which fixes the length in the SQL. When a list's length or values matter to the query plan, a literal `IN` list may plan better.
|
|
576
|
+
|
|
577
|
+
The example uses the demo schema's ids, `Uuid` in its Prisma schema (`pg/uuid@1`); use your id column's codec id, which must match the column's exactly.
|
|
578
|
+
|
|
579
|
+
```typescript
|
|
580
|
+
const ids = { codecId: 'pg/uuid@1', many: { elementNullable: false } } as const;
|
|
581
|
+
|
|
582
|
+
// SQL builder: in / notIn take a list expression of the left operand's codec.
|
|
583
|
+
const postsByUser = await db.prepare({ ids }, (p) =>
|
|
584
|
+
db.sql.public.post.select('id', 'title').where((f, fns) => fns.in(f.userId, p.ids)).build(),
|
|
585
|
+
);
|
|
586
|
+
|
|
587
|
+
// ORM: in / notIn on a scalar field take the same list parameter.
|
|
588
|
+
const usersExcept = await db.prepare({ ids }, (p) =>
|
|
589
|
+
db.orm.public.User.where((u) => u.id.notIn(p.ids)).select('id', 'email').prepared.all(),
|
|
590
|
+
);
|
|
591
|
+
|
|
592
|
+
const rows = await postsByUser.query(db.runtime(), { ids: userIds });
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
- It renders `= ANY($1::uuid[])` for `in` and `<> ALL($1::uuid[])` for `notIn`, with the same results as `IN` / `NOT IN`; an empty array matches no row for `in` and every row for `notIn`.
|
|
596
|
+
- The SQL builder also takes a list column on the right: `fns.in(p.tag, f.tags)`, with `p.tag` a scalar parameter declared `{ tag: 'pg/text@1' }` and `tags` a hypothetical `String[]` column (the demo schema has none). The left operand must be an expression (a column or a parameter), not a plain value.
|
|
597
|
+
- The SQL builder's `fns.eq` / `fns.ne` compare a list column with a list parameter, another list of the same element type, or an array: `fns.eq(f.tags, p.tags)`.
|
|
598
|
+
- The ORM takes a list parameter only on a scalar field, and only when neither the list nor its elements may be null (`nullable` absent or `false`, `elementNullable: false`); anything else is a compile error. At run time a nullable or element-nullable list parameter, one on a list field and one in a comparison other than `in` / `notIn` fail with `ORM.FILTER_UNSUPPORTED`; the codec match is checked by the types only.
|
|
599
|
+
- A list parameter needs `db.scalarList` in the contract's required capabilities (`postgres15` to `postgres18` all include it); without it `prepare` throws `ORM.CAPABILITY_MISSING`. SQLite, MySQL and MariaDB have no list parameters.
|
|
600
|
+
- Passing a value that is neither an array nor `null` fails when the statement runs, with `RUNTIME.ENCODE_FAILED`. `null` is not checked at run time, as for a single-value parameter: it binds SQL `NULL` and matches no row.
|
|
601
|
+
- A list of enum values uses the enum column's codec. The demo's `user_type` enum is stored as text (`@@type("pg/text@1")`), so a list of `User.kind` values is `{ codecId: 'pg/text@1', many: { elementNullable: false } }`. A native PostgreSQL enum column (`pg/enum@1`) also names its database type in `typeParams`, as the column does: for a native enum type `user_type`, `{ codecId: 'pg/enum@1', typeParams: { typeName: 'user_type' }, many: { elementNullable: false } }` renders `= ANY($1::"user_type"[])`.
|
|
602
|
+
- A list of `char(n)` values is cast to `bpchar[]`, PostgreSQL's `character` with no length, so no element is cut short.
|
|
603
|
+
|
|
561
604
|
### `INSERT` / `UPDATE` / `DELETE` with `RETURNING`
|
|
562
605
|
|
|
563
606
|
```typescript
|
|
@@ -586,7 +629,7 @@ const { affectedRows } = await db.execute(deletePlan);
|
|
|
586
629
|
|
|
587
630
|
Each row must include every column that is not nullable and has no default; leaving one out is a type error that names the column. A value typed `T | undefined` for such a column is also an error, so narrow it first.
|
|
588
631
|
|
|
589
|
-
`.returning(...)` requires the contract to require `
|
|
632
|
+
`.returning(...)` requires the contract to require `db.returning`. `postgres15` to `postgres18` list it.
|
|
590
633
|
|
|
591
634
|
### Computed projections and joins
|
|
592
635
|
|
|
@@ -696,7 +739,7 @@ Cross-namespace relations (e.g. `public.Profile` → `auth.User`) follow the sam
|
|
|
696
739
|
5. **Importing `and` / `or` / `not` from an internal package.** They are exported from `@prisma/orm-postgres/orm-client`; do not import them from a platform package such as `@prisma/orm-family-sql`.
|
|
697
740
|
6. **Trying to `db.sql.from(tables.user)`.** That surface does not exist. The builder is table-shaped: `db.sql.<ns>.<tableName>.select(...)`. There is no `db.schema.tables` either.
|
|
698
741
|
7. **Reading rows with `execute`.** Plans run through the client: `db.query(plan)` for rows, `db.execute(plan)` for a non-returning write (`{ affectedRows }`). Inside a transaction, `tx.query(plan)` / `tx.execute(plan)`. `execute` never yields rows — a `select` or `.returning(...)` plan passed to it gives you statistics, not data.
|
|
699
|
-
8. **Setting `capabilities: { lateral: true }` in `prisma.config.ts`.** The ORM config (`ormConfig({...})`) does not take `capabilities`. The contract lists every capability it requires in `requiredCapabilities`, beside the path in the contract entry or in `defineContract`, usually `[...postgres18, ...postgresDriver]`, which includes `
|
|
742
|
+
8. **Setting `capabilities: { lateral: true }` in `prisma.config.ts`.** The ORM config (`ormConfig({...})`) does not take `capabilities`. The contract lists every capability it requires in `requiredCapabilities`, beside the path in the contract entry or in `defineContract`, usually `[...postgres18, ...postgresDriver]`, which includes `db.lateral`, `db.jsonAgg` and `db.returning`. To require one more, add its key to that list (see `references/contract.md`).
|
|
700
743
|
9. **Confabulating a TypedSQL or `.stream()` surface.** Neither exists. Raw SQL does: the client's raw lane, ``db.raw.sql`…` ``. Reusable statements do: `db.prepare(...)` (see *Prepared statements* in [`queries.md`](./queries.md)). Streaming: `for await` over a read terminal or `runtime.query(plan)` — with the caveats in *Streaming* in [`queries.md`](./queries.md).
|
|
701
744
|
10. **Mixing the ORM mutation return with `db.query(plan)` / `db.execute(plan)`.** ORM terminals issue the query themselves and return rows. `query` and `execute` are for plans.
|
|
702
745
|
11. **Adding a `cursor()` to a relation, count, operation or `nulls` order.** It throws `ORM.ARGUMENT_INVALID`. Use `.limit(n).offset(n)`, or order by plain columns.
|
|
@@ -719,7 +762,7 @@ Cross-namespace relations (e.g. `public.Profile` → `auth.User`) follow the sam
|
|
|
719
762
|
- [ ] Expressed ranges as chained `.where(...)` clauses or a single `and(...)` clause — did NOT reach for a non-existent `.between(...)` operator.
|
|
720
763
|
- [ ] For cursor pagination, used `.orderBy(...).cursor({ field: lastValue }).limit(n).all()` — did NOT hand-write a `.where(p => p.field.lt(cursor))` workaround when the `.cursor()` API serves the same purpose.
|
|
721
764
|
- [ ] For ORM combinators, imported `and` / `or` / `not` from `@prisma/orm-postgres/orm-client`.
|
|
722
|
-
- [ ] Wrote a query piece shared between places as a function: a query fragment from `db.
|
|
765
|
+
- [ ] Wrote a query piece shared between places as a function: a query fragment from `db.fragment(fields, body)` or `collection.fragment(body)` run with `.with(...)`, a `where` callback typed with `CodecField`, or `orderByField` for an order parameter from a request.
|
|
723
766
|
- [ ] Ran SQL-builder plans via `db.query(plan)` when they return rows and `db.execute(plan)` only for non-returning writes (`tx.query` / `tx.execute` inside a transaction). Passed `insert()` an array of rows.
|
|
724
767
|
- [ ] Wrapped multi-statement work in `db.transaction(async (tx) => { ... })` where atomicity matters.
|
|
725
768
|
- [ ] For top-N grouped aggregates at meaningful scale, dropped to `db.sql.<ns>.<table>` rather than JS-side sort + slice over `groupBy(...).aggregate(...)`.
|
|
@@ -151,7 +151,7 @@ There is no `.stream()` method on a client or on a connection.
|
|
|
151
151
|
|
|
152
152
|
This section covers the SQL clients. MongoDB's `db.prepare` has the same shape, takes query-builder plans and ORM `.prepared` reads, and runs against `await db.runtime()`; see *Workflow — Prepared statements* in [`queries-mongo.md`](queries-mongo.md).
|
|
153
153
|
|
|
154
|
-
`db.prepare(declaration, (params) => plan)` builds a statement once and binds it per call. The declaration names each parameter's codec (`{ email: 'pg/text@1' }`); the callback receives typed `params`, builds the plan with `db.sql` (or an ORM `.prepared` description), and returns it. A row-returning plan gives a `PreparedStatement` you run with `ps.query(target, params)`; a plan whose result is an affected count gives a `PreparedExecution` you run with `ps.execute(target, params)`. A prepared statement runs on what it is given: the runtime, a connection, a transaction's `tx`, or a Supabase role-bound client, which runs it under its role. `ps.query(tx, params)` runs inside the transaction. Preparing sends nothing to the database. Inside a transaction, `tx.prepare(...)` prepares without the outer client. Declaring a parameter the plan never references throws `RUNTIME.PREPARE_UNUSED_PARAM`. `runtime.prepare(declaration, (params) => plan)` is the same thing on a `Runtime`.
|
|
154
|
+
`db.prepare(declaration, (params) => plan)` builds a statement once and binds it per call. The declaration names each parameter's codec (`{ email: 'pg/text@1' }`); the callback receives typed `params`, builds the plan with `db.sql` (or an ORM `.prepared` description), and returns it. A row-returning plan gives a `PreparedStatement` you run with `ps.query(target, params)`; a plan whose result is an affected count gives a `PreparedExecution` you run with `ps.execute(target, params)`. A prepared statement runs on what it is given: the runtime, a connection, a transaction's `tx`, or a Supabase role-bound client, which runs it under its role. `ps.query(tx, params)` runs inside the transaction. Preparing sends nothing to the database. Inside a transaction, `tx.prepare(...)` prepares without the outer client. Declaring a parameter the plan never references throws `RUNTIME.PREPARE_UNUSED_PARAM`. On Postgres a parameter declared with `many: { elementNullable }` holds a whole list for `in` / `notIn`; see *Prepared `in` with a list parameter* in [`queries-postgres.md`](./queries-postgres.md). `runtime.prepare(declaration, (params) => plan)` is the same thing on a `Runtime`.
|
|
155
155
|
|
|
156
156
|
```typescript
|
|
157
157
|
// examples/prisma-8-demo/src/queries/get-user-by-email-prepared.ts
|
|
@@ -229,7 +229,7 @@ Target-specific pitfalls live in the per-target guides.
|
|
|
229
229
|
- **Many-to-many relations work through the junction.** `.include('tags', (tag) => tag.select(...))` traverses an N:M relation's `through` table, and nested `create` / `connect` / `disconnect` on an N:M relation write the junction rows for you (`examples/prisma-8-demo/src/orm-client/get-post-tags.ts`, `create-post-with-tags.ts`). The one refusal: a junction with required payload columns the relation API cannot populate throws `ORM.OPERATION_UNSUPPORTED` — write that junction directly or use the SQL builder.
|
|
230
230
|
- **Ordering grouped aggregates by an aggregate alias (Postgres).** `db.orm.<ns>.<Model>.groupBy(...)` supports `.orderBy(...)` on group keys plus `.limit(...)` / `.offset(...)`, but the grouped collection cannot order by an aggregate alias such as `SUM(amount)`. A "top-N groups by SUM" query therefore falls back to JS-side sort + slice over the full grouped result, which is fine at small cardinalities and bad at scale. Workarounds: (a) drop to `db.sql.<ns>.<table>` and write the `GROUP BY` + `ORDER BY` + `LIMIT` against the aggregated table directly; (b) live with the JS-side sort/slice if the grouped cardinality is bounded. File a feature request via `references/feedback.md` if this is hitting you in production.
|
|
231
231
|
- **Set operations, window functions and `WITH` in the SQL builder.** `db.sql` has no `union` / `intersect` / `except`, no `OVER (...)` and no common table expressions. Write the whole query as raw SQL (next entry). If you want them in the builder, file a feature request via `references/feedback.md`.
|
|
232
|
-
- **A raw-SQL lane.** This one exists. Write whole-query raw SQL through the client's raw lane: ``db.raw.sql`SELECT ...`.returnsRow({ ... }).build()`` for rows, or `.affectedCount()` for a mutation's row count. Each declared column names the codec that decodes it, so the row stays typed. For an expression fragment inside a builder query, use `fns.raw` in a `.select(...)` callback instead.
|
|
232
|
+
- **A raw-SQL lane.** This one exists. Write whole-query raw SQL through the client's raw lane: ``db.raw.sql`SELECT ...`.returnsRow({ ... }).build()`` for rows, or `.affectedCount()` for a mutation's row count. Each declared column names the codec that decodes it, so the row stays typed. For an expression fragment inside a builder query, use `fns.raw` in a `.select(...)` callback instead, ending it with `.returns(codecId)`; an expression that holds an array, such as ``fns.raw`array_append(${f.tags}, 'x')` ``, ends with `.returns({ codecId: 'pg/text@1', many: { elementNullable: false } })`, so a list column's `update` value or `fns.eq` accepts it.
|
|
233
233
|
- **TypedSQL (`.sql` files compiled into typed callables).** Not implemented. For a repeated query, use `db.prepare(...)` (see *Prepared statements* above) or a function that returns the built plan and `db.query(plan)` at the call site. If you want a `.sql`-file compile path, file a feature request via `references/feedback.md`.
|
|
234
234
|
- **`EXPLAIN` / query-plan inspection.** Prisma 8 does not expose an `.explain()` method. Workaround: connect a `pg.Pool` you control via the runtime's `pg:` binding (see `references/runtime.md`) and issue `EXPLAIN ANALYZE` through it. If you want a first-class plan-inspection surface, file a feature request via `references/feedback.md`.
|
|
235
235
|
- **Multi-statement batching (Prisma-7-style `db.$transaction([call1, call2])`).** Prisma 8 runs each call sequentially. Workaround: wrap atomically-related work in `db.transaction(async (tx) => { ... })` on Postgres. If you want batch-as-array semantics, file a feature request via `references/feedback.md`.
|
|
@@ -7,7 +7,7 @@ This skill takes the user from zero (or near-zero) to a first working query agai
|
|
|
7
7
|
|
|
8
8
|
- **First-touch orientation** — the user has arrived at a Prisma 8 project for the first time (a scaffold tool like `npx createprisma` dropped them in, they cloned a teammate's repo, or they ran `prisma orm init` themselves and now want to make their first move) and they're asking *"what can I do with Prisma 8?"*, *"where do I start?"*, or *"what's next?"*. The goal is to anchor them on the contract, get them connected to a database, round-trip one row, and let further commands surface organically.
|
|
9
9
|
- **Greenfield** — new project, fresh database. User runs `prisma orm init` themselves. `init` seeds a starter contract with a sample model, so the path joins the first-touch orientation arc as soon as the database is initialised.
|
|
10
|
-
- **Brownfield-DB** — existing database, no contract yet. Infer the contract from the database with `contract infer`, sign the
|
|
10
|
+
- **Brownfield-DB** — existing database, no contract yet. Infer the contract from the database with `contract infer`, sign the database with `db sign`, then write queries against one of the existing tables.
|
|
11
11
|
|
|
12
12
|
This skill does **not** cover migrating from another ORM (Drizzle, Prisma 6/7, Sequelize, TypeORM, Kysely, Knex, raw drivers). Those are separately-installable skills.
|
|
13
13
|
|
|
@@ -37,7 +37,7 @@ This skill does **not** cover migrating from another ORM (Drizzle, Prisma 6/7, S
|
|
|
37
37
|
- **Why the application lists them.** The application must have exactly one copy of each. Prisma does not accept a value that another copy of its own code created, and a package manager takes a peer dependency only from the application's own list. A monorepo whose applications are on different Prisma releases can still get two copies under npm workspaces and under Bun's hoisted linker; keep such applications on one release, or use pnpm, Yarn or Bun's isolated linker.
|
|
38
38
|
- **Yarn Plug'n'Play.** `prisma orm init` does not support it. With Yarn, set `nodeLinker: node-modules` in `.yarnrc.yml` first.
|
|
39
39
|
- **`db.ts`**: the runtime entry point. Lives next to the contract source at `src/prisma/db.ts`. Imports the contract artefacts and exports a `db` value the rest of the app uses.
|
|
40
|
-
- **
|
|
40
|
+
- **Contract signature**: a row in the `prisma.signatures` table (Postgres) or a document in the `_prisma_migrations` collection (Mongo) that records the contract hash per contract space. Lets Prisma 8 detect drift between contract and live DB. Created by `db init` (greenfield / first-touch orientation) or `db sign` (brownfield).
|
|
41
41
|
|
|
42
42
|
### Canonical on-disk layout
|
|
43
43
|
|
|
@@ -109,7 +109,7 @@ If that prints `[{ id: 1, email: 'alice@example.com' }]`, the project is wired e
|
|
|
109
109
|
- The contract source exists at `src/prisma/contract.{prisma,ts}` (a starter model from `init`, or the inferred contract from `contract infer`, or whatever the bootstrap tool generated).
|
|
110
110
|
- `src/prisma/db.ts` exists and instantiates the runtime with the emitted contract.
|
|
111
111
|
- `DATABASE_URL` is set in `.env` (or wherever the runtime's config tells it to look).
|
|
112
|
-
- The database has been initialised (`db init`) or
|
|
112
|
+
- The database has been initialised (`db init`) or signed (`db sign`), so its contract signature exists and the schema matches the contract.
|
|
113
113
|
|
|
114
114
|
The three workflows below each describe how their path gets the user to that state. After that, the arc above is the same.
|
|
115
115
|
|
|
@@ -135,7 +135,7 @@ Before saying anything specific to the user, read:
|
|
|
135
135
|
- The contract source the config declares (canonically `src/prisma/contract.prisma` or `src/prisma/contract.ts`; a project scaffolded by an older init may have it at `prisma/contract.{prisma,ts}` instead — check the `contract` field of the config) — what starter models, if any, exist.
|
|
136
136
|
- `src/prisma/db.ts` (next to the contract) — the runtime entry point.
|
|
137
137
|
- `.env` / `.env.example` — is `DATABASE_URL` set, or only the example?
|
|
138
|
-
- Optionally `pnpm prisma db verify` — does the live DB match the contract? (Exit `4` with findings means drift or no
|
|
138
|
+
- Optionally `pnpm prisma db verify` — does the live DB match the contract? (Exit `4` with findings means drift or no contract signature; `2` means it could not run.)
|
|
139
139
|
|
|
140
140
|
Then **say the contract path back to the user, with its role attached**. Something like: *"Your contract is at `src/prisma/contract.prisma`, and it currently declares a `User` model. The contract describes your app — every query type, migration, and runtime type the framework gives you flows from this file. Let's get your app connected to a database next."* The exact wording is up to the agent; what matters is that the user leaves the first response knowing *where the contract is* and *that it is the source of truth*.
|
|
141
141
|
|
|
@@ -144,8 +144,8 @@ Then **say the contract path back to the user, with its role attached**. Somethi
|
|
|
144
144
|
The motivation is *"so your app can actually run against your database"*, not *"so the prerequisite checklist passes"*. The mechanics depend on what's already in place from Step 1:
|
|
145
145
|
|
|
146
146
|
- **Everything already wired.** Go straight to writing and reading a row (see *Your first arc — connect, write, read* above). Adapt the snippet to whatever model the contract declares.
|
|
147
|
-
- **`DATABASE_URL` not set.** Have the user set it in `.env` (not in `prisma.config.ts` — see Pitfall 5). Then `pnpm prisma db init` to apply the current contract to that database and write the
|
|
148
|
-
- **Database is connectable but not yet aware of the contract** (
|
|
147
|
+
- **`DATABASE_URL` not set.** Have the user set it in `.env` (not in `prisma.config.ts` — see Pitfall 5). Then `pnpm prisma db init` to apply the current contract to that database and write the contract signature row. Now the app can connect.
|
|
148
|
+
- **Database is connectable but not yet aware of the contract** (signature row missing; `db verify` reports drift). Run `pnpm prisma db init`. (`db update` is the alternative for quick dev cycles — it's looser, doesn't write a migration history, and is what users reach for when they want to iterate on the schema fast. Mention it if the user asks how to make schema changes flow to the DB; don't pre-explain it.)
|
|
149
149
|
- **Contract is empty** (bootstrap left the source blank). Add **one** model with **two** fields (e.g. `User { id, email }`), `pnpm prisma contract emit`, then `pnpm prisma db init`. Minimal — get the round-trip working, *then* extend.
|
|
150
150
|
|
|
151
151
|
The user encounters `db init` (and optionally `db update`, `contract emit`) here because they're the commands their current move *requires*. They learn what those commands are by using them.
|
|
@@ -214,7 +214,7 @@ The flags `init` accepts (run `prisma orm init --help` for the source of truth):
|
|
|
214
214
|
After init succeeds, the path converges on *Your first arc — connect, write, read* above. `init` has already seeded a starter contract with `User` and `Post` models (with a relation between them) and run `contract emit` once; the only remaining prerequisites are setting `DATABASE_URL` and initialising the database. Two commands:
|
|
215
215
|
|
|
216
216
|
1. Set `DATABASE_URL` in `.env` (copy from `.env.example`).
|
|
217
|
-
2. Initialise the database: `pnpm prisma db init`. Creates tables, indexes, constraints, and writes the
|
|
217
|
+
2. Initialise the database: `pnpm prisma db init`. Creates tables, indexes, constraints, and writes the contract signature row — using the starter contract `init` generated.
|
|
218
218
|
|
|
219
219
|
Then run the snippet from *Your first arc* above against the `User` model. When the user is ready to extend the contract — add more models, change fields, add relations — chain to `references/contract.md`. For more queries, chain to `references/queries.md`.
|
|
220
220
|
|
|
@@ -222,7 +222,7 @@ Then run the snippet from *Your first arc* above against the `User` model. When
|
|
|
222
222
|
|
|
223
223
|
## Workflow — Brownfield-DB (existing database, no contract)
|
|
224
224
|
|
|
225
|
-
The concept: against an existing database with no Prisma 8 contract, `contract infer` walks the live schema (tables, columns, indexes — including expression and partial ones — constraints, and RLS enablement + policies) and writes a PSL contract that describes it. Where authoring would generate a CHECK constraint the database does not carry (the element-non-null check on a list column), infer writes the list with nullable elements (`String?[]`), which derives no such check, so the contract declares exactly what the database enforces. The reverse gap is closed too: a hand-written CHECK constraint the database enforces that authoring would never have generated comes back as `@@check(expression: <reprint>, map: "<name>")`, so it is a declared object from the first pull instead of an invisible extra a later destructive plan could drop. That inferred check warns (`PN_EXACT_NAME_BODY_COMPARISON`) the next time you run `contract emit` — expected, not a defect: the warning fires on any `map:` body regardless of who wrote it, and the comparison stays sound because both sides are Postgres's own reprint. Columns come back as the convenience types with their defaults, and only the arguments that differ: `int2` as `Int(storage: int2)`, `numeric(10,2)` as `Decimal(precision: 10, scale: 2)`, `varchar(12)` as `String(storage: varchar, length: 12)`, `json` as `Json`, `jsonb` as `Json(storage: jsonb)`, `timestamptz(3)` as `DateTime` (a JavaScript `Date`), a `timestamptz` with no declared precision as `DateTime(precision: 6)`, `timestamp(3)` as `DateTime(storage: timestamp)`, `date` as `Date`, `time` as `Time` and `interval` as `Duration` (ISO strings). A `Date` holds milliseconds, so a timestamp column whose values use microseconds reads with them dropped: change such a field to `DateTime(as: temporal)` or `DateTime(as: string)` to keep them. The result is a *starting point*, not the final contract — review and clean it up, then `db sign` to record the current contract hash as the
|
|
225
|
+
The concept: against an existing database with no Prisma 8 contract, `contract infer` walks the live schema (tables, columns, indexes — including expression and partial ones — constraints, and RLS enablement + policies) and writes a PSL contract that describes it. Where authoring would generate a CHECK constraint the database does not carry (the element-non-null check on a list column), infer writes the list with nullable elements (`String?[]`), which derives no such check, so the contract declares exactly what the database enforces. The reverse gap is closed too: a hand-written CHECK constraint the database enforces that authoring would never have generated comes back as `@@check(expression: <reprint>, map: "<name>")`, so it is a declared object from the first pull instead of an invisible extra a later destructive plan could drop. That inferred check warns (`PN_EXACT_NAME_BODY_COMPARISON`) the next time you run `contract emit` — expected, not a defect: the warning fires on any `map:` body regardless of who wrote it, and the comparison stays sound because both sides are Postgres's own reprint. Columns come back as the convenience types with their defaults, and only the arguments that differ: `int2` as `Int(storage: int2)`, `numeric(10,2)` as `Decimal(precision: 10, scale: 2)`, `varchar(12)` as `String(storage: varchar, length: 12)`, `json` as `Json`, `jsonb` as `Json(storage: jsonb)`, `timestamptz(3)` as `DateTime` (a JavaScript `Date`), a `timestamptz` with no declared precision as `DateTime(precision: 6)`, `timestamp(3)` as `DateTime(storage: timestamp)`, `date` as `Date`, `time` as `Time` and `interval` as `Duration` (ISO strings). A `Date` holds milliseconds, so a timestamp column whose values use microseconds reads with them dropped: change such a field to `DateTime(as: temporal)` or `DateTime(as: string)` to keep them. The result is a *starting point*, not the final contract — review and clean it up, then `db sign` to record the current contract hash as the contract signature (instead of letting `db init` try to recreate the schema from scratch). By default `db sign` also sets the `db` ref and stores the contract snapshot, so the next `migration plan` chains from the adopted schema — even when the database is named with `--db`. `--advance-ref <name>` writes another ref instead and `--no-advance-ref` writes none; in either case the next plan needs `--from` or a `db` ref you set yourself.
|
|
226
226
|
|
|
227
227
|
```bash
|
|
228
228
|
mkdir my-app && cd my-app
|
|
@@ -250,7 +250,7 @@ Then re-emit and sign:
|
|
|
250
250
|
|
|
251
251
|
```bash
|
|
252
252
|
pnpm prisma contract emit
|
|
253
|
-
pnpm prisma db sign # writes the
|
|
253
|
+
pnpm prisma db sign # writes the contract signature and sets the db ref
|
|
254
254
|
pnpm prisma db verify # exit 0 immediately after a pull; exit 4 with findings if the DB drifts later
|
|
255
255
|
```
|
|
256
256
|
|
|
@@ -304,7 +304,7 @@ This skill is intentionally body-only; `prisma orm init --help`, `contract infer
|
|
|
304
304
|
|
|
305
305
|
- [ ] Confirmed which path applies (first-touch orientation / greenfield / brownfield) before proposing commands.
|
|
306
306
|
- [ ] **First-touch orientation:** named the contract path back to the user and framed its role (*source of truth from which query types, migrations, and runtime types flow*) before proposing any commands.
|
|
307
|
-
- [ ] **All paths:** brought the project to the *Your first arc* prerequisites (config, contract source, `db.ts`, `DATABASE_URL`,
|
|
307
|
+
- [ ] **All paths:** brought the project to the *Your first arc* prerequisites (config, contract source, `db.ts`, `DATABASE_URL`, contract signature row) *before* writing application code.
|
|
308
308
|
- [ ] **All paths:** ran the first arc — one `create` + one `select` against the starter (or inferred) model — and got the round-trip working green.
|
|
309
309
|
- [ ] **All paths:** did *not* edit the contract source as part of the first arc. Schema extension is the *next* move, not the first.
|
|
310
310
|
- [ ] **All paths:** did *not* lead with a feature tour, capability inventory, or recital of CLI commands. Commands surfaced as the user's current move required them.
|
|
@@ -314,7 +314,7 @@ This skill is intentionally body-only; `prisma orm init --help`, `contract infer
|
|
|
314
314
|
- [ ] **All paths (application projects):** the project ended up in the canonical `src/prisma/contract.{prisma,ts}` + `src/prisma/db.ts` + `migrations/app/` layout (what `init` scaffolds by default). An extension or aggregate-root package keeps its own `src/contract.{prisma,ts}` + `migrations/<timestamp>_<slug>/` layout — do not relocate it.
|
|
315
315
|
- [ ] **Brownfield path:** ran `contract infer --db "$DATABASE_URL" --output src/prisma/contract.prisma`, reviewed the result, then `contract emit` + `db sign` (which by default also sets the `db` ref, so the next `migration plan` chains from the adopted schema; not with `--no-advance-ref` or `--advance-ref <name>`).
|
|
316
316
|
- [ ] Set `DATABASE_URL` in `.env` and confirmed the value is reachable.
|
|
317
|
-
- [ ] Initialised the DB (`db init` greenfield / first-touch orientation) or signed the
|
|
317
|
+
- [ ] Initialised the DB (`db init` greenfield / first-touch orientation) or signed the database (`db sign` brownfield — by default sets the `db` ref too, with or without `--db`).
|
|
318
318
|
- [ ] Did NOT hand-edit `contract.json` or `contract.d.ts`.
|
|
319
319
|
- [ ] Did NOT set `DATABASE_URL` in `prisma.config.ts`.
|
|
320
320
|
- [ ] Confirmed the user understands what the *next* skill is for their workflow (typically `references/queries.md` for more queries, then `references/contract.md` when they're ready to extend the schema).
|
|
@@ -309,7 +309,7 @@ Order matters: `beforeEncode` runs in registration order for every middleware be
|
|
|
309
309
|
|
|
310
310
|
## Workflow — Configure the connection
|
|
311
311
|
|
|
312
|
-
The concept: the runtime takes one of three binding shapes — `url`, `pg` (a pre-constructed `pg.Pool` or `pg.Client`), or `binding` (an explicit kind tag). They're mutually exclusive. The `pg` form is for projects that already manage their own pool (e.g. a Lambda layer); `url` is the default. Pool tuning is `poolOptions.connectionTimeoutMillis` / `poolOptions.idleTimeoutMillis` / `poolOptions.max` (pool size, 10 by default) — *not* `driverOptions`. Behind a server-side connection pooler, `poolOptions: { max: 1 }` keeps one connection; queries then take turns on it, so a query waits while a transaction is open. Inside `db.transaction(async (tx) => …)` send every query through `tx`: with one connection, a query through `db` waits for the connection its own transaction holds and fails after `connectionTimeoutMillis`. Reads are buffered by default; setting `cursor` (`{ batchSize: 100 }`; `{}` or `{ batchSize: undefined }` for batches of 100; a `batchSize` that is not a positive integer fails the factory call) makes them stream through a server-side cursor, and there is no flag that turns cursors off (see `references/queries.md` § *Streaming*). `postgresServerless()` takes the same `cursor` option. Pass `log` (an object with `info`, `warn`, `error` and an optional `debug`; `console` works, and the type is `Log` from `@prisma/orm-postgres/family-runtime`) to receive what the runtime logs: the
|
|
312
|
+
The concept: the runtime takes one of three binding shapes — `url`, `pg` (a pre-constructed `pg.Pool` or `pg.Client`), or `binding` (an explicit kind tag). They're mutually exclusive. The `pg` form is for projects that already manage their own pool (e.g. a Lambda layer); `url` is the default. Pool tuning is `poolOptions.connectionTimeoutMillis` / `poolOptions.idleTimeoutMillis` / `poolOptions.max` (pool size, 10 by default) — *not* `driverOptions`. Behind a server-side connection pooler, `poolOptions: { max: 1 }` keeps one connection; queries then take turns on it, so a query waits while a transaction is open. Inside `db.transaction(async (tx) => …)` send every query through `tx`: with one connection, a query through `db` waits for the connection its own transaction holds and fails after `connectionTimeoutMillis`. Reads are buffered by default; setting `cursor` (`{ batchSize: 100 }`; `{}` or `{ batchSize: undefined }` for batches of 100; a `batchSize` that is not a positive integer fails the factory call) makes them stream through a server-side cursor, and there is no flag that turns cursors off (see `references/queries.md` § *Streaming*). `postgresServerless()` takes the same `cursor` option. Pass `log` (an object with `info`, `warn`, `error` and an optional `debug`; `console` works, and the type is `Log` from `@prisma/orm-postgres/family-runtime`) to receive what the runtime logs: the contract-signature-verification warnings `CONTRACT.SIGNATURE_MISSING` and `CONTRACT.SIGNATURE_MISMATCH` from the client's first use of the database (its first query, connection or transaction), the warnings `lints()` emits for rules whose severity is `warn`, and the errors a middleware's `activityEnded` or `activityFinalized` hook throws, which the runtime logs and swallows. If `log` has a `debug` method, it also receives debug events, for example when a middleware intercepts a statement. `budgets()` violations reach `log` only in `mode: 'permissive'` (see *Lints and budgets middleware*). Without `log`, the runtime logs to the console: errors to `console.error` and warnings to `console.warn`, which in Node write to standard error, info events to `console.info`, and debug events nowhere. To silence it, pass a logger that does nothing: `log: { info() {}, warn() {}, error() {} }`. `postgresServerless()`, `sqlite()` and `supabase()` take the same option.
|
|
313
313
|
|
|
314
314
|
```typescript
|
|
315
315
|
// Default — URL string, factory constructs the pool.
|
|
@@ -322,7 +322,7 @@ postgres({
|
|
|
322
322
|
// max: 10, // optional: the most connections the pool opens
|
|
323
323
|
},
|
|
324
324
|
// cursor: { batchSize: 100 }, // optional — stream reads in batches instead of buffering
|
|
325
|
-
// log: logger, // optional — where
|
|
325
|
+
// log: logger, // optional — where contract signature and lints() warnings go; the console by default
|
|
326
326
|
});
|
|
327
327
|
|
|
328
328
|
// BYO pool — pass a pg.Pool you already created.
|
|
@@ -415,7 +415,7 @@ export const contract = contractFromJson<Contract>(contractJson);
|
|
|
415
415
|
export const db = sqlite({ contract, path: 'app.db' });
|
|
416
416
|
```
|
|
417
417
|
|
|
418
|
-
`path` is optional at construct time (you can call `db.connect({ path })` later); omit it and the database package still returns a client. The SQLite package exposes the same `db.sql`, `db.orm`, `db.raw`, `db.prepare(...)`, `db.transaction(...)`, `db.close()`, and `[Symbol.asyncDispose]` surfaces as Postgres, with one addressing difference: SQLite has no schemas, so `db.sql` and `db.orm` are the unbound namespace itself (`db.orm.User`, `db.sql.user`) instead of Postgres's `db.orm.public.User` / `db.sql.public.user`. `db.
|
|
418
|
+
`path` is optional at construct time (you can call `db.connect({ path })` later); omit it and the database package still returns a client. The SQLite package exposes the same `db.sql`, `db.orm`, `db.raw`, `db.prepare(...)`, `db.transaction(...)`, `db.close()`, and `[Symbol.asyncDispose]` surfaces as Postgres, with one addressing difference: SQLite has no schemas, so `db.sql` and `db.orm` are the unbound namespace itself (`db.orm.User`, `db.sql.user`) instead of Postgres's `db.orm.public.User` / `db.sql.public.user`. `db.fragment` and `tx.fragment` make a fragment, and `db.orm` holds only the models: `const titled = db.fragment({ title: { codecId: 'sqlite/text@1', nullable: false } }, (rows) => rows.where((r) => r.title.eq('Hello')));` then `await db.orm.Post.with(titled).all();`. The Mongo package shares `db.orm`, `db.close()`, and `[Symbol.asyncDispose]` but has no `db.sql` and no `db.transaction(...)`.
|
|
419
419
|
|
|
420
420
|
The `db.sql` / `db.orm` surfaces stay the same in name; the operators each surface exposes are target-shaped (Mongo has no `JOIN`).
|
|
421
421
|
|
|
@@ -33,11 +33,11 @@ This skill covers using Prisma 8 against a **Supabase** project end-to-end: comp
|
|
|
33
33
|
|
|
34
34
|
## Workflow — Wire the pack into the config
|
|
35
35
|
|
|
36
|
-
The concept: the pack registers the Supabase contract space so your contract can reference it and the planner/verifier know what Supabase owns. Its descriptor is the `pack` export and it goes into the ordinary `extensions` array of the target config, inside the standard envelope (see `references/contract.md` § *Key Concepts*).
|
|
36
|
+
The concept: the pack registers the Supabase contract space so your contract can reference it and the planner/verifier know what Supabase owns. Its descriptor is the `pack` export and it goes into the ordinary `extensions` array of the target config, inside the standard envelope (see `references/contract.md` § *Key Concepts*). It imports `definePrismaConfig` from `prisma/config`, which the project's `prisma` development dependency provides (`prisma orm init` adds it):
|
|
37
37
|
|
|
38
38
|
```typescript
|
|
39
39
|
// prisma.config.ts
|
|
40
|
-
import { definePrismaConfig } from '
|
|
40
|
+
import { definePrismaConfig } from 'prisma/config';
|
|
41
41
|
import supabasePack from '@prisma/orm-extension-supabase/pack';
|
|
42
42
|
import { defineConfig as ormConfig, postgres18, postgresDriver } from '@prisma/orm-postgres/config';
|
|
43
43
|
|
|
@@ -19,28 +19,34 @@ Before changing any code, work out how far the chain can go. The application can
|
|
|
19
19
|
|
|
20
20
|
When the lines disagree, npm refuses the install if the packages that disagree are ones the application lists itself. pnpm, Yarn and Bun install anyway and print a peer dependency warning, so a successful install does not prove that the versions match.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
**Which packages are released with the ORM.** Some Prisma packages are published from the Prisma ORM repository, `prisma/orm`, at every release, such as `@prisma/orm-extension-pgvector`, `@prisma/orm-postgres-contrib` and `@prisma/orm-better-auth`. Each lists the other Prisma packages at that release, so it moves to `<to>` together with the database package in the bump step below, and does not limit how far the application can go. Other packages have versions of their own and are published when their maintainer chooses, even when their name starts with `@prisma/orm-`: Prisma publishes some from other repositories, and a package released with the ORM can move to a repository of its own.
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
Each published version says where it came from, in the `repository.url` of its `package.json`. Decide at each step of the chain: a package is released with the ORM at that step when it has a version in that step's release (`<to>` itself on the `8.0.0` release candidates; from release 8.0, a version in the `<to>` release, as [Version detection](#version-detection) defines it, such as `8.0.1` or `8.0.1-ea.0` and never `8.0.0-rc.25`), and that version's `repository.url` names the repository `prisma/orm` itself, such as `https://github.com/prisma/orm.git`. A repository whose name only starts the same way, such as `prisma/orm-extension-<name>`, is another repository. `pnpm view <name> versions --json` lists the versions, and `pnpm view <name>@<version> repository.url` reads the field; for the installed version, read `node_modules/<name>/package.json`. Any other package has versions of its own at that step: treat it as an extension published by someone else, which this pre-flight covers. Never derive its version from `<to>`, which can name a version that was never published.
|
|
25
|
+
|
|
26
|
+
If you cannot tell which kind a package is, treat it as one with versions of its own. That is safe: the pre-flight takes the newest release that accepts the step, and for a package released with the ORM that is its version in `<to>`.
|
|
26
27
|
|
|
27
28
|
Steps:
|
|
28
29
|
|
|
29
|
-
1. **Read `prisma.config.ts`** (or its TS-discoverable equivalent at the project root) and enumerate the list of extension packages it imports. Each `extensions: [...]` entry corresponds to an installed npm package.
|
|
30
|
-
2. **For each extension**, read its installed `package.json` from `node_modules/<extension-package-name>/package.json` and find every `@prisma/orm-*` entry under `dependencies`, `peerDependencies`, or `optionalDependencies` (`@prisma/orm-framework`, `@prisma/orm-family-sql` or `@prisma/orm-family-mongo`, `@prisma/orm-toolchain`, and a `@prisma/orm-target-*` package). Until release 8.0, by construction those entries are exact-version pins (e.g. `"8.0.0-rc.11"`), set when the extension author last ran their own upgrade.
|
|
31
|
-
3. **Find each extension's releases.** List its published versions with `pnpm view <extension> versions --json`. For each version, read the
|
|
30
|
+
1. **Read `prisma.config.ts`** (or its TS-discoverable equivalent at the project root) and enumerate the list of extension packages it imports. Each `extensions: [...]` entry corresponds to an installed npm package. Add any other package in the project's `package.json` that names an `@prisma/orm-*` package as a peer dependency, such as a library integration. Leave out a package that is released with the ORM at every step of the chain, as described above.
|
|
31
|
+
2. **For each extension**, read its installed `package.json` from `node_modules/<extension-package-name>/package.json` and find every `@prisma/orm-*` entry under `dependencies`, `peerDependencies`, or `optionalDependencies` (`@prisma/orm-framework`, `@prisma/orm-family-sql` or `@prisma/orm-family-mongo`, `@prisma/orm-toolchain`, and a `@prisma/orm-target-*` package), and every entry there on another package that step 1 listed, which has versions of its own whatever its name. Until release 8.0, by construction those entries are exact-version pins (e.g. `"8.0.0-rc.11"`), set when the extension author last ran their own upgrade.
|
|
32
|
+
3. **Find each extension's releases.** List its published versions with `pnpm view <extension> versions --json`. For each version, read the entries step 2 names, under `dependencies`, `peerDependencies` and `optionalDependencies`: `pnpm view <extension>@<version> dependencies peerDependencies optionalDependencies --json`. Then, for each step in the chain below, work out the version each of those packages has at that step, as the bump step of the per-step flow defines it:
|
|
32
33
|
- on the `8.0.0` release candidates, it is `<to>` itself;
|
|
33
|
-
- from release 8.0, it is that package's first version in the `<to>` release, such as `8.0.1` for a GA package and `8.0.1-ea.0` for one below GA.
|
|
34
|
+
- from release 8.0, it is the version the install will take for the entry the bump step writes: the newest published version that entry accepts. The bump step writes the package's first version in the `<to>` release, as [Version detection](#version-detection) defines it, such as `8.0.1` for a GA package and `8.0.1-ea.0` for one below GA, with a caret or a tilde, so once `8.0.2` is published the install takes `8.0.2`, and an extension that names exactly `8.0.1` does not accept it;
|
|
35
|
+
- for a package with versions of its own, such as another extension, it is the release this pre-flight notes for that package at that step.
|
|
34
36
|
|
|
35
|
-
Note the release of each extension whose every entry accepts its package's version at that step.
|
|
36
|
-
4. **Find the last step every extension allows.** Walk the chain from the first step. The chain can go as far as the last step
|
|
37
|
+
Note, for each step, the newest release of each extension whose every entry accepts its package's version at that step. Several releases can accept the same step; take the newest.
|
|
38
|
+
4. **Find the last step every extension allows.** Walk the chain from the first step. A step for which some extension has no release, while a later step of the chain has one for it, does not stop the chain: the steps up to that later step are taken together, as [Steps taken together](#steps-taken-together) describes. The chain can go as far as the last step for which every extension has a release. If that is short of the user's target, tell the user before installing anything: which extension has no release for which Prisma version, how far the upgrade can go, and their options:
|
|
37
39
|
- (a) Wait for, or ask for, a release of the extension for that version, then re-run.
|
|
38
40
|
- (b) Upgrade only as far as the last step every extension allows.
|
|
39
41
|
- (c) Remove the extension, and upgrade without it.
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
If an extension does have a release for the step, but that release pins another package with versions of its own exactly, at a version other than the one this pre-flight noted for that package, say that instead of reporting a missing release: name the extension's release, its pin, and the version noted for the other package.
|
|
44
|
+
|
|
45
|
+
5. **Check the `prisma` command-line tool.** The project needs its own `prisma`: a `prisma` installed globally has its own copy of the ORM packages, and from the first `prisma` release with the check it refuses ORM commands in a project that has the ORM packages. If the project does not list `prisma`, the bump step adds it as a development dependency. Either way, find for each step the `prisma` version that fits it, as [Choosing the `prisma` version](#choosing-the-prisma-version) describes, and treat `prisma` like an extension with versions of its own. A step no `prisma` version fits, while a later step of the chain has one, is taken together with that later step. The chain goes no further than the last step a `prisma` version fits. If that is short of the user's target, tell the user before installing anything, as in step 4: which step has no `prisma` version, and how far the upgrade can go. When the step is to the newest release, a `prisma` version that carries it is normally published within a few days of the ORM, so the user can wait and re-run. For an older step none will come, so the user can only upgrade that far. Do this before steps 2 to 4 compare extensions with a step: the step installs `@prisma/orm-toolchain` and `@prisma/orm-framework` at exactly the versions its `prisma` depends on, so those are the versions each extension must accept.
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
Do not skip a step's upgrade instructions, do not install an extension at a release that names another Prisma version, and do not install past the last step every extension and `prisma` allow.
|
|
48
|
+
|
|
49
|
+
If step 1 finds no extension, skip steps 2 to 4. Step 5 always runs.
|
|
44
50
|
|
|
45
51
|
## Role detection
|
|
46
52
|
|
|
@@ -56,8 +62,9 @@ If the repository also holds an extension, in a `package.json` of its own, run *
|
|
|
56
62
|
- **From-version.** Read the installed Prisma 8 version from `pnpm-lock.yaml` (or `package-lock.json` / `yarn.lock`): take the resolved version of the application's database package, which is `@prisma/orm-postgres`, `@prisma/orm-mongo`, `@prisma/orm-sqlite`, `@prisma/orm-mysql` or `@prisma/orm-mariadb`. Do not read it from an extension published by someone else. Such an extension has its own version, and the pre-flight above deals with it.
|
|
57
63
|
- **On the `8.0.0` release candidates,** compare the full version strings, including the part after the hyphen. `8.0.0-rc.10` and `8.0.0-rc.11` are different versions, and different steps in the chain below.
|
|
58
64
|
- **From release 8.0,** each package has its own patch number or level suffix, and a step is named by the release, which is the major and minor: `8.0-to-8.1`. So the from-version is the release that the database package's version belongs to. `8.0.1-ea.0`, `8.0.1` and `8.0.2` all belong to release `8.0`.
|
|
59
|
-
-
|
|
60
|
-
-
|
|
65
|
+
- **What counts as a version of a release.** Release 8.0 starts at `8.0.1` for a GA package and `8.0.1-ea.0` (or `-preview.0`, `-rc.0`) for one below GA. A version `8.0.0-rc.N` is a release candidate, which is a step of its own, not a version of release 8.0, although its major and minor are `8.0`. A version with `-dev.` in it is a development build and is not a version of any release. Wherever this reference says "a version in the `<to>` release" or "the first version in the `<to>` release", it means this.
|
|
66
|
+
- If the lockfile shows the application's Prisma packages on different releases, which is already a broken state, the **lowest** is the from-version.
|
|
67
|
+
- **To-version.** Either the version the user specified, or whatever `npm view @prisma/orm-postgres dist-tags.latest` reports. Do not assume that is a stable version: `latest` is the newest release promoted to `latest`, which while Prisma 8 is a release candidate is an `8.0.0-rc.N`. If the user wants a stable version specifically, they must name it.
|
|
61
68
|
|
|
62
69
|
Report both back to the user before continuing.
|
|
63
70
|
|
|
@@ -71,9 +78,20 @@ If the from-to delta spans more than one release (e.g. `0.6 → 0.8`), build the
|
|
|
71
78
|
|
|
72
79
|
The [`../upgrading/app/upgrades/`](../upgrading/app/upgrades/) directories name the steps — read the chain off the directory names rather than deriving it arithmetically. Each directory is `<from>-to-<to>`. A step normally spans one stable minor (`0.7-to-0.8`) or one release candidate (`8.0.0-rc.1-to-8.0.0-rc.2`). When intermediate versions were not published, a guide may span a larger hop; follow the available directory chain rather than inventing missing steps. Moving onto the RC line from the last stable minor is a single step of its own (`0.17-to-8.0.0-rc.1`).
|
|
73
80
|
|
|
74
|
-
Apply each step in order, fully: bump, install, run instructions, validate, commit — before moving to the next. Halt the chain on the first failed step; do not skip ahead.
|
|
81
|
+
Apply each step in order, fully: bump, install, run instructions, validate, commit — before moving to the next. The one exception is [steps taken together](#steps-taken-together), which the pre-flight decides. Halt the chain on the first failed step; do not skip ahead.
|
|
82
|
+
|
|
83
|
+
The chain order does not depend on which extensions are installed; the pre-flight has already worked out how far it can go, and which steps are taken together.
|
|
84
|
+
|
|
85
|
+
### Steps taken together
|
|
86
|
+
|
|
87
|
+
An extension with versions of its own may have no release for some steps of the chain and a release for a later one. A release candidate cut after the extension's last release is one such step. The extension at its old release names the old Prisma versions, so the project cannot install those steps with it. The `prisma` command-line tool is the same: for some steps no `prisma` version fits, and a `prisma` command must run on the toolchain of the packages installed at that time. Take those steps, and the later step, together, using the per-step flow's own parts:
|
|
88
|
+
|
|
89
|
+
- Do the bump once, to the later step's versions: the first later step for which every extension has a release and a `prisma` version fits.
|
|
90
|
+
- Install once, and re-sync the skills.
|
|
91
|
+
- Read and apply the upgrade instructions of every step from the first of them to that later step, in the chain's order, with no install in between.
|
|
92
|
+
- Validate once, after the last of them, then commit. Name every step the commit covers in its message.
|
|
75
93
|
|
|
76
|
-
The
|
|
94
|
+
The `prisma` commands that the earlier steps' instructions run, such as `prisma contract emit`, `prisma db sign` and `prisma migration plan`, run on the installed toolchain, which is the later step's. So where an earlier step's guide says what such a command must or must not change, read that against the later step: the command writes the later step's format. If validation fails, report every step taken together, and the change ids whose files the failure names, because the failure can come from any of them.
|
|
77
95
|
|
|
78
96
|
## Per-step flow
|
|
79
97
|
|
|
@@ -82,9 +100,9 @@ For each `(from, to)` step in the chain:
|
|
|
82
100
|
1. **Bump the app's Prisma packages.** Change these entries in the project's `package.json`, under both `dependencies` and `devDependencies`:
|
|
83
101
|
- the database package, such as `@prisma/orm-postgres`;
|
|
84
102
|
- the platform packages that the database package lists as peer dependencies;
|
|
85
|
-
- every extension or library integration
|
|
103
|
+
- every extension or library integration that is [released with the ORM](#pre-flight--extension-compatibility) at this step, such as `@prisma/orm-extension-pgvector`, `@prisma/orm-postgres-contrib` and `@prisma/orm-better-auth`.
|
|
86
104
|
|
|
87
|
-
Each of these is published at every release and lists the other Prisma packages at that release, so one that is left behind disagrees with the rest.
|
|
105
|
+
Each of these is published at every release and lists the other Prisma packages at that release, so one that is left behind disagrees with the rest. A package whose name starts with `@prisma/orm-` but that has versions of its own at this step is not in this list. It moves as an extension published by someone else, below.
|
|
88
106
|
|
|
89
107
|
**What to write, on the `8.0.0` release candidates.** Rewrite every entry to the exact `<to>` version, with no caret and no tilde. All entries move to the same version.
|
|
90
108
|
|
|
@@ -92,13 +110,13 @@ For each `(from, to)` step in the chain:
|
|
|
92
110
|
- beside a GA database package, a GA entry gets a caret and an entry below GA gets a tilde;
|
|
93
111
|
- beside a database package below GA, every entry gets a tilde.
|
|
94
112
|
|
|
95
|
-
**Write a caret only when `<to>` is the newest published release,** which `pnpm view <
|
|
96
|
-
|
|
97
|
-
**`@prisma/orm-extension-paradedb`** has version numbers of its own. Set it to the release the pre-flight noted for this step, as for an extension published by someone else.
|
|
113
|
+
**Write a caret only when `<to>` is the newest published release of every package this step writes,** which `pnpm view <name> versions --json` shows for each: the database package, each platform package the application lists, and each extension or library integration released with the ORM at this step. The packages of a release are not all published at the same moment, so a platform package can have a later release before the database package does. A caret accepts later releases, so at any other step the install would take a release later than `<to>`, whose instructions have not been applied. That is every step before the last one, and the last one too when the user's target is older than the newest release. At such a step write a tilde in place of the caret: a tilde stays within `<to>` and still takes its fixes. If the upgrade ends on a release that is not the newest, say in the final report that those entries have a tilde where [Versions and support](https://github.com/prisma/orm/blob/main/docs/oss/versioning.md#what-an-application-writes) gives a caret.
|
|
98
114
|
|
|
99
115
|
**A peer dependency the project does not list.** If the database package at `<to>` lists an `@prisma/orm-*` peer dependency that the project's `package.json` does not have, add it, written as that package's entry for `<to>` would be. The application lists every one of them, so that it has one copy of each. A monorepo whose applications are on different Prisma releases can still get two copies under npm workspaces and under Bun's hoisted linker; keep such applications on one release, or use pnpm, Yarn or Bun's isolated linker.
|
|
100
116
|
|
|
101
|
-
**Extensions published by someone else
|
|
117
|
+
**Extensions published by someone else,** and Prisma packages with versions of their own. Set each one to the release the pre-flight noted for this step: the one whose every entry the pre-flight reads accepts that package's version at the step. On the `8.0.0` release candidates, write it exactly. From release 8.0, write it as [Versions and support](https://github.com/prisma/orm/blob/main/docs/oss/versioning.md#what-an-application-writes) gives for its level, by the same rules as the entries above: a caret on a GA version beside a GA database package, a tilde otherwise, such as `~8.0.1-ea.0` for a version below GA, and a tilde in place of the caret where the rule above allows no caret. If that range also accepts a later release of the package that the pre-flight did not note, because that release does not accept the step, write the noted release exactly instead: the install takes the newest release a range accepts. If an extension has no such release and the pre-flight did not take this step together with a later one, halt before this step's install. The project stays at the last step that worked, and the user gets the pre-flight's message for that extension and step.
|
|
118
|
+
|
|
119
|
+
**The `prisma` command-line tool.** Move `prisma` too, or add it as a development dependency if the project does not list it, at a version chosen as [Choosing the `prisma` version](#choosing-the-prisma-version) describes. Write the project's `@prisma/orm-toolchain` and `@prisma/orm-framework` lines exactly at the versions that `prisma` depends on, with no caret or tilde, in place of the caret or tilde the rules above give them, so that the install cannot take a later patch. `prisma` runs the ORM commands from its own copy of the toolchain, and that copy must be the application's, so the application's `@prisma/orm-toolchain` and `@prisma/orm-framework` must resolve to the versions `prisma` depends on. The pre-flight has already found the version for this step. A step no `prisma` version fits is taken together with a later one, or is past where the chain stops.
|
|
102
120
|
|
|
103
121
|
The skill itself ships inside the Prisma packages, so bumping them is what updates it. There is no separate skill package to bump.
|
|
104
122
|
|
|
@@ -126,13 +144,28 @@ For each `(from, to)` step in the chain:
|
|
|
126
144
|
chore: upgrade @prisma/orm-* to <to-version>
|
|
127
145
|
```
|
|
128
146
|
|
|
129
|
-
(Or the project's own commit-message convention.) Never squash steps. The user may squash on merge; the in-flight history must be per-step so a failed step is bisectable.
|
|
147
|
+
(Or the project's own commit-message convention.) Never squash steps, except that [steps taken together](#steps-taken-together) are one commit, which names each of them. The user may squash on merge; the in-flight history must be per-step so a failed step is bisectable.
|
|
130
148
|
|
|
131
149
|
Then move on to the next step.
|
|
132
150
|
|
|
151
|
+
## Choosing the `prisma` version
|
|
152
|
+
|
|
153
|
+
The `prisma` command-line tool is published from another repository, [`prisma/prisma-cli`](https://github.com/prisma/prisma-cli). Each of its versions for Prisma 8 depends on one exact version of `@prisma/orm-toolchain`, and runs the ORM commands, such as `prisma contract emit`, from that copy, not from the copy the project lists. So the files those commands write and read come from the toolchain the `prisma` version brings. From `prisma@8.0.0-rc.36` on, each version also lists `@prisma/orm-framework` at the same exact version. Earlier versions do not list it, and get it through the toolchain. Some ORM release candidates, such as `8.0.0-rc.1`, `8.0.0-rc.6`, `8.0.0-rc.9` and `8.0.0-rc.15`, have no `prisma` version that carries them.
|
|
154
|
+
|
|
155
|
+
Its version numbers are its own, though they look like the ORM's: `prisma@8.0.0-rc.36` carries the ORM at `8.0.0-rc.25`. Never choose `prisma` by its own number. Read its dependencies.
|
|
156
|
+
|
|
157
|
+
1. Run `pnpm view prisma dist-tags.latest`, then `pnpm view prisma@<that version> dependencies`.
|
|
158
|
+
2. That version fits the step when its `@prisma/orm-toolchain`, and its `@prisma/orm-framework` if it lists one, are:
|
|
159
|
+
- on the `8.0.0` release candidates, exactly `<to>`, because file formats changed between release candidates;
|
|
160
|
+
- from release 8.0, versions in the `<to>` release as [Version detection](#version-detection) defines it, with any patch number or level suffix. A `8.0.0-rc.N` version does not fit a step to release 8.0: on the day of release 8.0, `latest` may still carry `8.0.0-rc.25`. The tool is meant to stop an ORM command when the project's `@prisma/orm-toolchain` or `@prisma/orm-framework` is not the copy it would run itself, even at the same version ([ADR 329](https://github.com/prisma/orm/blob/main/docs/architecture%20docs/adrs/ADR%20329%20-%20An%20application%20lists%20the%20platform%20packages%20and%20our%20packages%20name%20each%20other%20as%20peers.md#the-prisma-command-line-tool)). So after the step is installed, those packages must resolve to the versions this `prisma` depends on, and `prisma` must be installed in the project, so that the package manager installs one copy for both. A `prisma` installed globally has a copy of its own and is refused.
|
|
161
|
+
3. If `latest` does not fit, look through `pnpm view prisma versions --json` for the highest version that fits. Never take a version with `-dev.` in it, which is a development build, and never one whose dependencies name no `@prisma/orm-toolchain`, which is a Prisma 7 version.
|
|
162
|
+
4. Write the version exactly, with no caret or tilde, so that a later `prisma` carrying another release is not installed. This has a cost: an ordinary update with the package manager moves the Prisma packages to a new release and leaves `prisma` carrying the old one. This upgrade flow moves `prisma` at each step. After an update made any other way, choose its version again by these steps.
|
|
163
|
+
5. After the step is installed, check that the project has one copy of each package: `pnpm why @prisma/orm-toolchain` and `pnpm why @prisma/orm-framework` should each show one version, the one this `prisma` depends on. If either shows two, stop and report which package in the project requires the other version. One version can still be installed twice, in two folders; a `prisma` release with the copy check compares the folders and stops with `CLI.SECOND_PACKAGE_COPY`, whose message names both, so follow that message if an ORM command stops with it. An older `prisma` fails later instead, with an error that names no versions, such as `CONTRACT.SOURCE_LOAD_FAILED`.
|
|
164
|
+
6. If no version fits a step, take it, and every step after it that no version fits either, together with the next step that a `prisma` version fits, as [Steps taken together](#steps-taken-together) describes. A `prisma` command must run on the toolchain of the packages installed at that time, so those steps cannot be installed one by one. If no `prisma` version fits any of the remaining steps, the run is taken together with the last step of the chain. The application flow then stops before installing that run, as step 5 of the pre-flight says, so the chain ends at the last step a `prisma` version fits. The extension flow instead installs it and uses the overrides stopgap that its bump step describes, because an extension author may need to prepare a release before `prisma` catches up. That is the one difference between the two flows.
|
|
165
|
+
|
|
133
166
|
## When the chain is done
|
|
134
167
|
|
|
135
|
-
Report back to the user: the number of steps applied, the SHAs of the commits you made, and any open follow-ups (e.g. tests that were already red before the upgrade and still are).
|
|
168
|
+
Report back to the user: the number of steps applied, the SHAs of the commits you made, and any open follow-ups (e.g. tests that were already red before the upgrade and still are). If the chain stopped short of the user's target because no `prisma` version carries a later step, say so, and say which step to re-run from once one is published.
|
|
136
169
|
|
|
137
170
|
## Failure surfaces
|
|
138
171
|
|