Skip to content

Commit 2de4da9

Browse files
docs(docs): update the Prisma ORM 8 pages for 8.0.0-rc.25
Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io>
1 parent dfbfb87 commit 2de4da9

45 files changed

Lines changed: 269 additions & 112 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/docs/content/docs/(index)/prisma-orm/from-scratch.mdx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ npm pkg set type=module
3939
Install the runtime library, the command-line tool, and the tooling to run a TypeScript file:
4040

4141
```npm
42-
npm install @prisma/orm-postgres dotenv
43-
npm install --save-dev prisma tsx typescript
42+
npm install @prisma/orm-postgres pg dotenv
43+
npm install --save-dev prisma tsx typescript @types/pg
4444
```
4545

46-
`@prisma/orm-postgres` is the library your code imports, and `prisma` is the command-line tool. `dotenv` loads `.env`, `tsx` runs `index.ts` without a build step, and `typescript` 5.9 or newer is a peer dependency of `@prisma/orm-postgres`.
46+
`@prisma/orm-postgres` is the library your code imports, and `prisma` is the command-line tool. `pg` is the PostgreSQL driver, a peer dependency of `@prisma/orm-postgres`, and `@types/pg` gives TypeScript its types. `dotenv` loads `.env`, `tsx` runs `index.ts` without a build step, and `typescript` 5.9 or newer is a peer dependency of `@prisma/orm-postgres`.
4747

4848
`temporal-polyfill` is a peer dependency of `@prisma/orm-postgres` too. It adds `Temporal`, the newer JavaScript date and time API, to runtimes such as Node.js 24 that do not have it built in. npm installs it for you, but with Yarn you add it yourself.
4949

50-
The two Prisma packages have different version numbers, for example `prisma` 8.0.0-rc.34 and `@prisma/orm-postgres` 8.0.0-rc.24. That is normal, and any two `latest` versions work together.
50+
The two Prisma packages have different version numbers, for example `prisma` 8.0.0-rc.34 and `@prisma/orm-postgres` 8.0.0-rc.25. That is normal, and any two `latest` versions work together.
5151

5252
## 2. Create the config file and `.env`
5353

‎apps/docs/content/docs/cli/configuration.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export default definePrismaConfig({
278278

279279
Set `newline` when anyone works on the project from Windows; `"LF"` is the usual choice. Without it, on Windows `contract format` writes `CRLF` but the [Prisma editor extension](/orm/contract-authoring/editor-support) writes `LF`. Each one rewrites every line the other wrote, so Git shows the whole file as changed. The editor extension reads `formatter` from `prisma.config.ts` too, so once `newline` is set, the command and the editor write the same line endings on every machine.
280280

281-
`formatter` needs `@prisma/orm-postgres` or `@prisma/orm-mongo` at `8.0.0-rc.24` or later. An earlier release ignores the setting without an error, and `contract format` still indents with two spaces. `npm ls @prisma/orm-postgres`, or the same command with `@prisma/orm-mongo`, prints the release you have.
281+
`@prisma/orm-postgres` and `@prisma/orm-mongo` read `formatter` since `8.0.0-rc.24`. An earlier release ignores the setting without an error, and `contract format` still indents with two spaces. `npm ls @prisma/orm-postgres`, or the same command with `@prisma/orm-mongo`, prints the release you have.
282282

283283
If `indent` or `newline` has a value the table does not allow, every command that reads the config fails with `CLI.CONFIG_FIELD_INVALID`. The message names the field, as in `formatter.indent must be at least 1 (was 0)`.
284284

‎apps/docs/content/docs/cli/contract-infer.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ In a list column's type, a `?` means something different depending on where it i
5858

5959
A list column that Prisma ORM migrations created cannot hold `NULL` elements, because the migration adds a check that stops it, so it gets no `?` before the brackets. Any other list column gets one.
6060

61-
Each column gets a type such as `String(storage: varchar, length: 20)`, `Int(storage: int2)`, `Bit(8)`, `Varbit(16)`, `Xml`, `Money`, or `Duration(precision: 3)`, written with the fewest parameters that describe the column exactly. Where a [convenience type](/orm/contract-authoring/psl-syntax#models-and-fields) gives the column's type, the contract writes it with only the arguments that differ from its defaults. The types come from Prisma ORM's types for your database and from the extension packs listed under `extensions` in `prisma.config.ts`. An extension pack is the Prisma ORM package for a database extension, such as pgvector.
61+
Each column gets a type such as `String(storage: varchar, length: 20)`, `Int(storage: int2)`, `Json(storage: jsonb)`, `Bit(8)`, `Varbit(16)`, `Xml`, `Money`, or `Duration(precision: 3)`, written with the fewest parameters that describe the column exactly. Where a [convenience type](/orm/contract-authoring/psl-syntax#models-and-fields) gives the column's type, the contract writes it with only the arguments that differ from its defaults. The types come from Prisma ORM's types for your database and from the extension packs listed under `extensions` in `prisma.config.ts`. An extension pack is the Prisma ORM package for a database extension, such as pgvector.
6262

6363
When a column has a type that none of these provide, the command writes no file. It fails with `CONTRACT.INFER_COLUMN_TYPE_UNCLAIMED` and lists every such column, such as `public.doc.meta: hstore`. To get past the error, do one of the following for each listed column:
6464

‎apps/docs/content/docs/cli/db-migrate.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metaTitle: db migrate | Prisma ORM CLI
66
metaDescription: Learn how to apply pending Prisma ORM on-disk migrations with the db migrate command.
77
---
88

9-
`db migrate` applies the migrations on disk that the database has not run yet, including the ones that extension packages ship. It runs the extensions' migrations first, in alphabetical order of extension, and then yours. It never writes a new migration; [`migration plan`](/cli/migration-plan) does that.
9+
`db migrate` applies the migrations on disk that the database has not run yet, including the ones that extension packages ship. It runs the extensions' migrations first, in alphabetical order of extension, and then yours. It never writes a new migration; [`migration plan`](/cli/migration-plan) does that. It obeys the database's [policies](/orm/migrations/database-policies): a database whose change policy does not include `migrate` refuses it, and one whose data protection policy forbids an operation in a pending migration refuses the whole run before it applies anything.
1010

1111
Prisma ORM keeps one migration history for your own models, called the `app` space, in `migrations/app/`, and one for each [extension package](/orm/extensions/using-extensions) that ships its own migrations, such as pgvector. Each of these histories is a [contract space](/orm/migrations/the-migration-graph#terms-used-on-this-page).
1212

@@ -26,6 +26,7 @@ npx prisma db migrate --db "$DATABASE_URL"
2626
| `--to <contract>` | Applies migrations up to a target contract state. Accepts a [contract reference](/cli/migration-ref#contract-reference-forms): a hash, a hash prefix, a [ref name](#contract-references), a migration directory name, [`<dir>^`](#contract-references), [`@contract`](#contract-references), [`@db`](#contract-references), or [`@empty`](#contract-references). |
2727
| `--advance-ref <name>` | After a successful run, points the named [ref](/cli/migration-ref) at the contract state the database now matches. Pass `--advance-ref db` in development. |
2828
| `--show` | Prints the migrations `db migrate` would run, and runs nothing. |
29+
| `--permit-policy-change` | With `--to <ref>`, checks the run against the ref's declared [policies](/orm/migrations/database-policies) and writes them into the database when it succeeds. Without it, a ref whose policies differ from the database's fails with `MIGRATION.POLICY_MISMATCH`. |
2930
| `--from <contract>` | Use it with `--show`, where it sets the starting state for the preview. Accepts a [contract reference](/cli/migration-ref#contract-reference-forms): a hash, a hash prefix, a [ref name](#contract-references), a migration directory name, [`<dir>^`](#contract-references), [`@contract`](#contract-references), [`@db`](#contract-references), or [`@empty`](#contract-references). |
3031
| `--config <path>` | Read this config file instead of `./prisma.config.ts`. |
3132
| `--json` | Prints a machine-readable result. |

‎apps/docs/content/docs/cli/db-update.mdx‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ metaDescription: Learn how to reconcile a database with the current Prisma ORM c
1010

1111
Like Prisma ORM 7's `db push`, use it when you want a database to match your contract and do not need a migration file for the change, for example on your development database while you try out a contract change.
1212

13+
A database whose [change policy](/orm/migrations/database-policies) does not include `reconcile` refuses `db update` with `MIGRATION.CHANGE_POLICY_FORBIDS`. Its [data protection policy](/orm/migrations/database-policies#data-protection-policy) decides whether the update asks before it loses data or changes access, refuses, or goes ahead without asking.
14+
1315
## Usage
1416

1517
```npm
@@ -27,6 +29,7 @@ npx prisma db update --db "$DATABASE_URL"
2729
| `--delete <subject>` | Lets the update lose the data of a model, a field, a table no model stores, every model of a namespace the contract removed, or, on PostgreSQL and SQLite, an enum value the contract removed, a field of a value object, or the rows of a variant. Repeatable. |
2830
| `--convert <Variant>` | On PostgreSQL and SQLite, rewrites the stored discriminator value of a variant whose value changed. Repeatable. |
2931
| `--allow <Model>` | Lets one operation change who can read or write the model's data. Repeatable. |
32+
| `--permit-policy-change` | With `--to <ref>`, checks the run against the ref's declared [policies](/orm/migrations/database-policies) and writes them into the database when it succeeds. Without it, a ref whose policies differ from the database's fails with `MIGRATION.POLICY_MISMATCH`. |
3033
| `--advance-ref <name>` | After the update, points the named [ref](/cli/migration-ref) at the contract state the database now matches. Without it, `db update` points the `db` ref there when you leave out `--db`, and changes no ref when you pass `--db`. |
3134
| `--config <path>` | Read this config file instead of `./prisma.config.ts`. |
3235
| `--json` | Prints a machine-readable result. |
@@ -60,6 +63,16 @@ In a terminal, the command asks the questions you did not answer with a flag. In
6063

6164
Dropping an index, a unique or foreign-key constraint, a check, a default or a native enum type loses no data, so the update asks nothing about it.
6265

66+
### A changed stored name [#a-changed-stored-name]
67+
68+
On PostgreSQL and SQLite, a model, field or enum member that keeps its name in the contract is the same object, even when what it is stored as changes. When only its `@@map`, its `@map`, or the value an enum member stores changes, the update renames the table or column, with the constraints and indexes named after it, or replaces the stored value in the rows, and asks nothing. A table or column is renamed only when its control policy is `managed` in both contracts. A `--delete` for such a change fails with `CLI.CONSENT_UNUSED`, because nothing asks about it.
69+
70+
To start with an empty table under the new name instead, make two changes, each applied before the next: remove the model and answer `--delete`, then add it back with its new `@@map`.
71+
72+
Swaps, chains and takeovers are refused with `MIGRATION.PLANNING_FAILED`: two models or fields that trade tables or columns, one that moves to a name another frees, one that takes the storage of one the change removes, and enum members that trade stored values. Make the change in two steps through a name nothing uses, such as `prisma_swap_users`, applied one after the other.
73+
74+
MySQL and MongoDB plan these changes as before. Before `8.0.0-rc.25`, a changed `@@map` was planned as dropping the table and creating an empty one, and asked for `--delete`.
75+
6376
`db update` names each subject by model and field from the contract the database was last updated to, which it stores when it advances a ref. With `--db`, pass `--advance-ref <name>` on every run so that contract is stored for the next run. Without a stored contract, each subject is its storage name, and a run with `--rename` fails with `MIGRATION.STATEMENT_ORIGIN_UNKNOWN`. Adding `--advance-ref` to that run does not help, because the missing contract is the one the database is at before it. To store it, emit the contract the database is at, run `db update --advance-ref db --dry-run` with the same `--db`, and check that it plans no operations. Then run it again without `--dry-run`, which changes nothing in the database and stores the contract. Then emit the new contract and run the rename.
6477

6578
On PostgreSQL, a namespace is renamed, moved or removed with the same flags. `--rename billing:finance` renames the schema, and everything in it stays in it. `--rename public.Invoice:billing.Invoice` moves the model's table to another schema with its rows, constraints, indexes and policies, and creates the schema first when the database does not have it. Namespace renames run before the other renames, whatever order you give them in. `public` and a schema another contract space declares are not renamed.
@@ -74,12 +87,12 @@ The schema can also hold objects that no contract declares. A table created by h
7487

7588
The command leaves alone a schema that no contract declared, such as Supabase's `auth`, and a namespace that only another contract space declares. Before `8.0.0-rc.20`, the command did not ask about a removed namespace and left its tables in place.
7689

77-
On PostgreSQL and SQLite, removing a member from an `enum` block, or changing the value a member stores, is asked about too, because rows may hold the old value. The update asks once for each value, however many columns hold it:
90+
On PostgreSQL and SQLite, removing a member from an `enum` block is asked about too, because rows may hold its value. The update asks once for each value, however many columns hold it:
7891

7992
- If you renamed the member, answer with `--rename Status.ARCHIVED:Status.RETIRED`. The update changes the stored value in every column and list that holds it.
8093
- To let the value go, answer with `--delete Status.ARCHIVED`. Optional columns that hold it are set to `NULL`, and lists lose it. A required column cannot take `NULL`, so while any of its rows hold the value, the apply fails with `MIGRATION.PRECHECK_FAILED` before it changes anything. The error counts those rows and says how to keep them.
8194

82-
A member you rename while keeping its stored value, such as `RETIRED = "archived"` in place of `ARCHIVED = "archived"`, changes no rows, so nothing is asked. A member that keeps its name but stores a new value, and two members that swap their stored values, can only be answered with `--delete`. `db update` cannot keep those rows in one run. Its question says to plan the change with [`migration plan --from <hash>`](/cli/migration-plan#renames-and-data-loss) instead, or, for a member that keeps its name, to rename it to a new member and back in two runs of `db update`. For a swap, only the migration works.
95+
A member you rename while keeping its stored value, such as `RETIRED = "archived"` in place of `ARCHIVED = "archived"`, changes no rows, so nothing is asked. A member that keeps its name but stores a new value is [a changed stored name](#a-changed-stored-name): the update replaces the value in the rows and asks nothing. Two members that swap their stored values are refused; make the swap in two runs through a value nothing uses.
8396

8497
Native PostgreSQL enums (`pg.enum(...)`) are not affected. Before `8.0.0-rc.21`, PostgreSQL failed at apply when a row held the removed value, and SQLite planned nothing.
8598

@@ -96,7 +109,7 @@ A [variant](/orm/contract-authoring/psl-syntax#base-models-and-variants) whose d
96109
- `--rename Bug:Defect` of a variant whose value also changed rewrites the value in the same way.
97110
- `--delete Bug` deletes the rows that hold the old value, then drops a removed variant's own table or the columns only it used.
98111

99-
On MongoDB, `--rename` of a value object field or of a variant whose discriminator value changes is refused, and so is `--convert` of a variant.
112+
On MongoDB, changes inside documents are asked about too, since `8.0.0-rc.25`: a field a value object or an embedded model loses, a stored value an enum loses, and a variant that is removed or whose discriminator value changes. They take the same answers as in [`migration plan`](/cli/migration-plan#renames-and-data-loss). With `--no-interactive` and no answers, the update fails with `CLI.CONSENT_REQUIRED` and lists the flags to add.
100113

101114
On MongoDB, a field type change that can lose values is asked about, as on SQL. Answer with `--delete` and the field, as in `--delete User.age`, which keeps the field and casts its stored values with `$convert`. To write the conversion yourself, use `migration plan --convert` instead, because `db update` writes no migration for you to edit.
102115

0 commit comments

Comments
 (0)