From 69f873bbc2148b5974b863e36ade8273b8233320 Mon Sep 17 00:00:00 2001 From: Kristof Siket Date: Fri, 6 Nov 2026 13:54:31 +0100 Subject: [PATCH 1/5] feat(prisma-postgres-upgrade): add the Prisma ORM 6 or 7 to Prisma 8 on Compute upgrade skill --- README.md | 20 ++++ prisma-orm-setup/SKILL.md | 2 +- prisma-postgres-upgrade/SKILL.md | 111 ++++++++++++++++++ .../references/client-api-mapping.md | 88 ++++++++++++++ .../references/compute-setup-pr-fixes.md | 86 ++++++++++++++ .../references/migrations-mapping.md | 64 ++++++++++ .../references/schema-contract-mapping.md | 88 ++++++++++++++ .../references/verify-upgrade-checklist.md | 56 +++++++++ 8 files changed, 514 insertions(+), 1 deletion(-) create mode 100644 prisma-postgres-upgrade/SKILL.md create mode 100644 prisma-postgres-upgrade/references/client-api-mapping.md create mode 100644 prisma-postgres-upgrade/references/compute-setup-pr-fixes.md create mode 100644 prisma-postgres-upgrade/references/migrations-mapping.md create mode 100644 prisma-postgres-upgrade/references/schema-contract-mapping.md create mode 100644 prisma-postgres-upgrade/references/verify-upgrade-checklist.md diff --git a/README.md b/README.md index 518cad2..d52a076 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,25 @@ Decision and migration guide for MongoDB projects on Prisma v6, which have no pa --- +### prisma-postgres-upgrade + +Upgrade a PostgreSQL app from Prisma ORM 6 or 7 straight to Prisma 8 and deploy it on Prisma Compute, following the [Prisma ORM 6 or 7 to 8 on Prisma Compute guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute). + +**Use when:** +- A PostgreSQL project on Prisma ORM 6 or 7 wants Prisma 8 +- Deploying a Prisma ORM 6 or 7 app on Prisma Compute +- Finishing the Console's "Set up Prisma Cloud deploys" pull request + +**Topics covered:** +- The Prisma 8 versions the Console's Compute setup pins, and why not `@latest` +- Reading the existing `schema.prisma` with `prisma7Schema(...)`, `contract emit` and `db sign` +- Prisma 8 owning migrations in `migrations/app/` +- Query rewrites and the `@prisma/orm-postgres@8.0.0-rc.20` gotchas +- `service.load().db.client` on Compute and the setup pull request fixes +- Verifying with the repository's own checks, before and after + +--- + ### prisma-client-api Comprehensive Prisma Client API reference. @@ -155,6 +174,7 @@ Or install specific skills: npx skills add prisma/skills --skill prisma-cli npx skills add prisma/skills --skill prisma-upgrade-v7 npx skills add prisma/skills --skill prisma-mongodb-upgrade +npx skills add prisma/skills --skill prisma-postgres-upgrade npx skills add prisma/skills --skill prisma-client-api npx skills add prisma/skills --skill prisma-driver-adapter-implementation npx skills add prisma/skills --skill prisma-orm-setup diff --git a/prisma-orm-setup/SKILL.md b/prisma-orm-setup/SKILL.md index a711519..6c9f9be 100644 --- a/prisma-orm-setup/SKILL.md +++ b/prisma-orm-setup/SKILL.md @@ -29,7 +29,7 @@ Use an existing database when supplied. Load `prisma-postgres-setup` only when P ## 2. Handle requested major upgrades separately -When the user requests a major upgrade, load a workflow that supports the source version and provider. For PostgreSQL 7-to-8, use the [Prisma migration guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql); for MongoDB 6-to-8, use [prisma-mongodb-upgrade](../prisma-mongodb-upgrade/SKILL.md). Other providers need an explicitly supported migration path. `prisma-upgrade-v7` covers **6 to 7**; the package-owned `prisma-8` upgrade reference covers updates within 8. +When the user requests a major upgrade, load a workflow that supports the source version and provider. For PostgreSQL 7-to-8, use the [Prisma migration guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql); for PostgreSQL 6 or 7 to 8 in one pass, ending on Prisma Compute, use [prisma-postgres-upgrade](../prisma-postgres-upgrade/SKILL.md); for MongoDB 6-to-8, use [prisma-mongodb-upgrade](../prisma-mongodb-upgrade/SKILL.md). Other providers need an explicitly supported migration path. `prisma-upgrade-v7` covers **6 to 7**; the package-owned `prisma-8` upgrade reference covers updates within 8. ## 3. Bootstrap a new Prisma 8 application diff --git a/prisma-postgres-upgrade/SKILL.md b/prisma-postgres-upgrade/SKILL.md new file mode 100644 index 0000000..d912469 --- /dev/null +++ b/prisma-postgres-upgrade/SKILL.md @@ -0,0 +1,111 @@ +--- +name: prisma-postgres-upgrade +description: Upgrade a PostgreSQL app from Prisma ORM 6 or 7 straight to Prisma 8 and deploy it on Prisma Compute, keeping the existing schema.prisma, database and data. Use when a Postgres project on Prisma 6 or 7 wants Prisma 8, Prisma Compute, or the Console's "Set up Prisma Cloud deploys" pull request. Triggers on "upgrade prisma 6 to 8", "upgrade prisma 7 to 8", "upgrade to prisma 8 postgres", "move my prisma app to prisma compute", "prisma7Schema", "migrations/app", "service.load().db.client", "@prisma/client did not initialize yet". +license: MIT +metadata: + author: prisma + version: "1.0.0" +--- + +# Prisma Postgres Upgrade: Prisma ORM 6 or 7 to Prisma 8 on Compute + +Move a Node.js server on Prisma ORM 6 or 7 and PostgreSQL to Prisma 8 in one pass, then deploy +it on Prisma Compute through the Console's setup pull request. The schema, the database and its +data stay. At the end, Prisma 8 owns migrations, every query runs through the Prisma 8 client, +and a push deploys the app with its own Prisma Postgres database. + +The [Prisma ORM 6 or 7 to 8 on Prisma Compute (PostgreSQL) guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute) +is the source of truth. Follow its steps in order; this skill adds the rules an agent needs and +the pitfalls found while validating it. + +**Never do either of these:** + +- Never route a PostgreSQL Prisma ORM 6 app through Prisma ORM 7 first. Prisma 8 reads a + Prisma ORM 6 `schema.prisma` unchanged, so `prisma-upgrade-v7` is only for apps that stay on 7. +- Never install `prisma@latest` or `@prisma/orm-postgres@latest` while the Console's Compute + setup pins versions: the setup keeps whatever versions `package.json` declares, and the + latest pair does not work with the Composer version it installs, so the deploy fails. + +## When to Apply + +- A PostgreSQL project on Prisma ORM 6 or 7 asks to upgrade to Prisma 8 +- The user wants to deploy a Prisma ORM 6 or 7 app on Prisma Compute +- The Console opened **Set up Prisma Cloud deploys** on a branch named `prisma-cloud/setup` +- A fresh install fails with `@prisma/client did not initialize yet` after the CLI switched to 8 + +Not for: MongoDB (use `prisma-mongodb-upgrade`), a Prisma ORM 7 app moving one route at a time +beside Prisma 8 (follow the [side-by-side guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql)), +or a new project (use `prisma-orm-setup`). + +## Pinned versions + +Install exactly these, with `--save-exact`: + +| Package | Version | Where | +|---------|---------|-------| +| `prisma` | `8.0.0-rc.27` | `devDependencies` | +| `@prisma/orm-postgres` | `8.0.0-rc.20` | `dependencies` | + +They are `PRISMA_CLI_VERSION` and `ORM_POSTGRES_VERSION` in the Console's Compute setup. When +the setup pull request in the repository lists other versions, use those. Prisma 8 needs +Node.js 22.18+, but `prisma dev` needs Node.js 24.11+, so use 24.11+ throughout. + +## The path + +| Step | What happens | Reference | +|------|--------------|-----------| +| 0 | Record the baseline: run the repo's own checks before any change | `verify-upgrade-checklist` | +| 1 | `npm uninstall prisma`, install the pins, remove `prisma generate` from scripts | this file | +| 2 | `prisma.config.ts` with `prisma7Schema(...)`, `contract emit`, `db sign` | `schema-contract-mapping` | +| 3 | `migration plan --name init` into `migrations/app/`, delete `prisma/migrations` | `migrations-mapping` | +| 4 | `tsconfig.json`: `nodenext`, `resolveJsonModule` | `schema-contract-mapping` | +| 5 | Prisma 8 client from `DATABASE_URL`, rewrite every query | `client-api-mapping` | +| 6 | Console setup PR, then fix it: service in the build, `service.load().db.client` | `compute-setup-pr-fixes` | +| 7 | Remove `@prisma/client`, the adapter and the generated client | this file | +| 8 | Run the same checks again and start the app | `verify-upgrade-checklist` | + +After step 2 writes `prisma.config.ts`, run `npx prisma skills sync`. It installs the +version-matched `prisma-8` and `prisma-platform-core-concepts` skills from the installed +packages; with a Prisma ORM 7 config still in place it fails with `CLI.CONFIG_UNREADABLE`. Run +it again after step 6 to add `prisma-composer-core-concepts`. Use them for API details from +then on. + +Step 1 removes the only command that generated the old client. The generated client on disk +keeps working locally, but a fresh install (CI, a new clone) has none, so rewrite every query +before pushing to a branch that CI builds. Prisma 8 has no `generate` and no seed command: +`prisma generate` exits 2 with `CLI.UNKNOWN_COMMAND`, so strip it from `build` and +`postinstall`. + +## What the user does + +The agent cannot do these; stop and ask the user: + +- Connect the repository in the [Prisma Console](https://console.prisma.io), which opens the + setup pull request. +- Provide the values for environment variables the app reads (`prisma project env add`). +- Approve the push to `prisma-cloud/setup`. Every push deploys a preview, and merging the + pull request deploys production. + +## Reference files + +| Reference | What it covers | +|-----------|----------------| +| `references/schema-contract-mapping.md` | `prisma.config.ts`, `prisma7Schema` on a 6 or 7 schema, emit, sign, tsconfig | +| `references/client-api-mapping.md` | Prisma ORM 6/7 calls to Prisma 8, and the rc.20 gotchas | +| `references/migrations-mapping.md` | Baseline in `migrations/app/`, retiring `prisma/migrations`, the change loop | +| `references/compute-setup-pr-fixes.md` | The edits the Console's setup pull request needs before it deploys | +| `references/verify-upgrade-checklist.md` | Proving the upgrade with the repo's own checks | + +## Verified against + +A Prisma ORM 6.19 app (Express 4, EJS, `tsc`, CommonJS) on PostgreSQL 18, with `prisma` +8.0.0-rc.27, `@prisma/orm-postgres` 8.0.0-rc.20, and `@prisma/composer` / +`@prisma/composer-prisma-cloud` 0.34.0. Steps 1 to 5 and 7 ran end to end, and step 6 ran +locally under `prisma dev`. The Console flow and the Compute runtime were not deployed: those +parts follow the Console's setup code and the Composer types. Before acting on a version-specific +claim, check the installed versions (`npm ls prisma @prisma/orm-postgres`). + +## Hand-off rule + +Once the app runs on Prisma 8, follow the synced `prisma-8` skill for day-to-day work and +`prisma-compute` for deploy operations. This skill covers the upgrade only. diff --git a/prisma-postgres-upgrade/references/client-api-mapping.md b/prisma-postgres-upgrade/references/client-api-mapping.md new file mode 100644 index 0000000..425ae51 --- /dev/null +++ b/prisma-postgres-upgrade/references/client-api-mapping.md @@ -0,0 +1,88 @@ +# client-api-mapping + +Prisma ORM 6 and 7 queries map to the Prisma 8 client the same way; four differences break most rewrites. + +## Priority + +CRITICAL + +## Why It Matters + +The Prisma 8 client chains calls instead of taking one options object, and a schema read through +`prisma7Schema(...)` changes a few types and lookups. At `@prisma/orm-postgres@8.0.0-rc.20`, +some of these compile fine and fail at runtime or write wrong data. + +## The client (local, before Compute) + +```typescript +import "dotenv/config"; +import postgres from "@prisma/orm-postgres/runtime"; +import { contractFromJson } from "@prisma/orm-postgres/static"; +import type { Contract } from "./prisma/contract.d"; +import contractJson from "./prisma/contract.json"; + +export const db = postgres({ + contract: contractFromJson(contractJson), + url: process.env["DATABASE_URL"]!, +}); +``` + +On Compute this file changes to `service.load().db.client`; see `compute-setup-pr-fixes.md`. + +## The mapping + +Queries start at `db.orm.public.` (`public` is the PostgreSQL schema). The last call says +what comes back. + +| Prisma ORM 6 / 7 | Prisma 8 | +|------------------|----------| +| `findMany({ where, orderBy })` | `.where({...}).orderBy((m) => m.field.asc()).all()` | +| `include: { _count: { select: { posts: true } } }` | `.include("posts", (p) => p.count())`; the number lands in `row.posts`, not `row._count.posts` | +| `orderBy: { votes: { _count: "desc" } }` | `.orderBy((p) => p.votes.count().desc())`; several: pass an array | +| `findUnique({ where: { id } })` | `.whereUnique({ id }).first()` | +| `findUnique({ where: { slug } })` (`@unique`) | `.where({ slug }).first()` | +| `findUnique({ where: { a_b: { a, b } } })` (`@@unique`) | `.where({ a, b }).first()` | +| `create({ data: { ..., votes: { create: {...} } } })` | `.create({ ..., votes: (v) => v.create([{...}]) })` | +| `deleteMany({ where })` then `.count` | `.where({...}).deleteAndCount()` | +| `count({ where })` | `.where({...}).aggregate((a) => ({ total: a.count() }))` | +| `` $queryRaw`SELECT 1` `` | `` db.query(db.raw.sql`SELECT 1 AS ok`.returnsRow({ ok: "pg/int4@1" }).build()) `` | +| `Object.values(PostStatus)` from `@prisma/client` | `db.nativeEnums.public.PostStatus.values` | + +What has no Prisma 8 form yet, such as `increment` in an update, is listed in +[Coming from Prisma ORM 7](https://www.prisma.io/docs/orm/coming-from-prisma-orm-7#queries). + +## The rc.20 gotchas + +1. **`whereUnique` only on `{ id }`.** Each `@unique` and `@@unique` becomes the unique index + Prisma ORM created, and `whereUnique` accepts only a primary key or unique constraint. Use + `.where({...}).first()`; it runs the same query. +2. **Enums are under `db.nativeEnums`.** A 6/7 `enum` is a PostgreSQL enum type. `db.enums.public` + is empty, while field values stay the same strings. +3. **`DateTime` reads as a string**, such as `"2026-11-06 09:10:48.497"` (UTC, no offset). + `row.createdAt.toISOString()` throws at runtime, often inside a template that `tsc` never + checks. Grep views and response code for `Date` methods on these fields. Convert with + `new Date(value.replace(" ", "T") + "Z")` where a `Date` is needed. Later releases return a + `Date` again. +4. **`@default(now())` is filled by the database.** A `timestamp` column then gets the + database's local time, where Prisma ORM 6/7 sent UTC. If `SHOW timezone` is not `UTC`, new rows are + off by the offset; tell the user rather than silently changing data. + +## Bad + +```typescript +const board = await db.orm.public.Board.whereUnique({ slug }).first(); // does not compile +const label = post.createdAt.toISOString(); // compiles in an .ejs view, throws at runtime +``` + +## Good + +```typescript +const board = await db.orm.public.Board.where({ slug }).first(); +const label = post.createdAt.slice(0, 10); +``` + +## References + +- [Guide, step 5](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#5-rewrite-your-queries) +- [ORM client reference](https://www.prisma.io/docs/orm/reference/orm-client) +- The synced `prisma-8` skill, authoritative for the installed client diff --git a/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md b/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md new file mode 100644 index 0000000..d15316a --- /dev/null +++ b/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md @@ -0,0 +1,86 @@ +# compute-setup-pr-fixes + +The Console's setup pull request needs these edits before a `tsc`-built app deploys and works. + +## Priority + +CRITICAL + +## Why It Matters + +On Compute, `DATABASE_URL` is a reserved variable holding the placeholder `-`. An app that keeps +reading it deploys, then fails every query with `P1001` and `host: "base"`. And only the build +output (`dist/`) ships, so anything the server loads from outside it is missing at runtime. + +## What the setup pull request adds + +On branch `prisma-cloud/setup`, titled **Set up Prisma Cloud deploys**: +`.github/workflows/prisma-deploy.yml` (deploys every push: default branch to production, others +to previews), `module.mjs`, a root `service.mjs`, a `composer` section in `prisma.config.ts`, and +the Composer packages. It keeps the `prisma` and `@prisma/orm-postgres` versions already in +`package.json`. The setup branch deploys as a preview; merging deploys production. + +## The fixes + +1. **Move the service into the build.** The root `service.mjs` has no types (TS7016 when + imported) and is not in `dist/`, so `require("../service.mjs")` fails on Compute with + `Cannot find module`. Delete it and write `src/service.mts`: + + ```typescript + import node from "@prisma/composer/node"; + import { compute } from "@prisma/composer-prisma-cloud"; + import { postgres, dataContract } from "@prisma/composer-prisma-cloud/orm"; + import type { Contract } from "./prisma/contract.js"; + import contractJson from "./prisma/contract.json" with { type: "json" }; + + export default compute({ + name: "", + deps: { db: postgres(dataContract(contractJson)) }, + build: node({ module: import.meta.url, dir: ".", entry: "server.js", dependencies: "external" }), + }); + ``` + + In `module.mjs`, import `./dist/service.mjs` instead of `./service.mjs`. +2. **Check `entry`.** The setup guesses it and can be wrong (it wrote `index.js` for an app + whose `npm start` runs `server.js`); it is the file in `dist/` that `npm start` runs. +3. **`dependencies: "external"`.** `tsc` does not bundle, so the deploy must ship `node_modules` + packages the entry imports. +4. **Take the client from the service.** + + ```typescript + // src/db.ts + import service from "./service.mjs"; + export const db = service.load().db.client; + ``` + + `service.load().db.url` is there for a library that needs a connection string. Outside a + Composer run, `service.load()` throws `missing required config param "url"`, so run locally + with `npm run build && npx prisma dev module.mjs` (Node.js 24.11+). It starts a local + Prisma Postgres, applies `migrations/app/`, and prints `dev: ready`. That database is empty. +5. **Ship runtime files.** Copy `views/`, `public/` or similar into `dist/` in `build` + (`tsc && cp -R views public dist/`) and resolve them from `__dirname`. Otherwise every + rendered page fails with `Failed to lookup view`. +6. **Environment variables.** Every variable other than the database and `PORT` goes in with + `prisma project env add KEY --role production` and `--role preview`, value read from the + environment. Ask the user for values; never invent secrets. `prisma dev` does not pass shell + variables, so a variable required at startup needs a local default or a service input. + +Then ask the user before pushing. After the push, `npx prisma service list --branch +prisma-cloud/setup` shows the preview URL. + +## Bad + +```typescript +export const db = postgres({ contract, url: process.env["DATABASE_URL"]! }); // "-" on Compute +``` + +## Good + +```typescript +export const db = service.load().db.client; +``` + +## References + +- [Guide, step 6](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#6-deploy-on-prisma-compute) +- `prisma-compute` skill, and the synced `prisma-composer-core-concepts` skill diff --git a/prisma-postgres-upgrade/references/migrations-mapping.md b/prisma-postgres-upgrade/references/migrations-mapping.md new file mode 100644 index 0000000..2694101 --- /dev/null +++ b/prisma-postgres-upgrade/references/migrations-mapping.md @@ -0,0 +1,64 @@ +# migrations-mapping + +Prisma 8 owns migrations in `migrations/app/` while it keeps reading `prisma/schema.prisma`. + +## Priority + +HIGH + +## Why It Matters + +The Compute deploy creates an empty database per branch and applies `migrations/app/` to it. +Without a baseline there, previews and production deploy with no tables. Keeping +`prisma migrate` alongside Prisma 8 splits the migration history in two. + +## Hand over + +After `db sign` (see `schema-contract-mapping.md`): + +```bash +npx prisma migration plan --name init # Planned baseline (N operation(s)) + 0 operation(s) +npx prisma db migrate # (no operations) on the signed database +rm -r prisma/migrations # includes migration_lock.toml +``` + +- The baseline in `migrations/app/_baseline` creates every table, index and foreign + key in the contract, so a signed database skips it and an empty one applies it. +- `--name` is ignored when the plan has no operations of its own beyond the baseline. +- Prisma 8 does not read `prisma/migrations`. Keep `prisma/schema.prisma`: it is still the + contract. +- The `_prisma_migrations` table stays in the database. Prisma 8 ignores it in `db verify` and + `contract infer`; dropping it is the user's call. +- Remove `prisma migrate dev`, `prisma migrate deploy` and `prisma db seed` scripts, and the + `"prisma": { "seed": ... }` key, because Prisma 8 has no seed command; a seed is a `tsx` script that + imports the client. + +## Every later schema change + +Edit `prisma/schema.prisma`, then: + +```bash +npx prisma contract emit +npx prisma migration plan --name +npx prisma db migrate --advance-ref db +npx prisma db verify +``` + +`--advance-ref db` points `migrations/app/refs/db.json` at the new contract, so the next plan diffs from it. + +## Bad + +```bash +npx prisma7 migrate dev # or keeping prisma/migrations "for now" +``` + +## Good + +```bash +npx prisma migration plan --name init && rm -r prisma/migrations +``` + +## References + +- [Guide, step 3](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#3-hand-migrations-to-prisma-8) +- [How migrations work](https://www.prisma.io/docs/orm/migrations/how-migrations-work) diff --git a/prisma-postgres-upgrade/references/schema-contract-mapping.md b/prisma-postgres-upgrade/references/schema-contract-mapping.md new file mode 100644 index 0000000..51558a2 --- /dev/null +++ b/prisma-postgres-upgrade/references/schema-contract-mapping.md @@ -0,0 +1,88 @@ +# schema-contract-mapping + +Prisma 8 reads the existing Prisma ORM 6 or 7 `schema.prisma` as its contract; do not port it. + +## Priority + +CRITICAL + +## Why It Matters + +Porting the schema by hand risks a contract that no longer matches the tables, and a mismatch +makes `db sign` fail or plans a destructive migration. `prisma7Schema(...)` reads the file the +app already has, including a Prisma ORM 6 schema, so the database is never touched. + +## prisma.config.ts + +Create it in the project root. In a Prisma ORM 7 app, replace the existing one: Prisma 8 reads +only its own config format under that name. + +```typescript +import "dotenv/config"; +import { definePrismaConfig } from "prisma/config"; +import { defineConfig, prisma7Schema } from "@prisma/orm-postgres/config"; + +export default definePrismaConfig({ + orm: defineConfig({ + contract: prisma7Schema("prisma/schema.prisma"), + output: "src/prisma", + db: { connection: process.env["DATABASE_URL"] }, + }), +}); +``` + +- Leave `schema.prisma` alone. The `generator client { ... }` block and `url = env(...)` in the + datasource stay; Prisma 8 ignores them. +- `output: "src/prisma"` puts `contract.json` and `contract.d.ts` inside `src/`, where `tsc` + compiles them and the Compute service imports them. +- `view` blocks and some extensions need extra config; see + [Use a Prisma ORM 7 schema](https://www.prisma.io/docs/cli/configuration#use-a-prisma-orm-7-schema). + +## Emit and sign + +```bash +npx prisma contract emit # Emitted contract.json and contract.d.ts +npx prisma db sign # Database signed, Advanced ref "db" +``` + +Commit both emitted files, and run `contract emit` after every edit to `schema.prisma`. `db sign` +checks the tables match, writes a marker, and writes `migrations/app/refs/db.json`; it does not +change tables. Run it once against every other existing database (staging) too. A database the +Compute deploy creates does not need it. + +## tsconfig.json for a tsc + node app + +Prisma 8 packages are ES modules, and the code imports `contract.json`. A CommonJS app compiled +with `tsc` stays CommonJS: + +```json +{ + "compilerOptions": { + "module": "nodenext", + "moduleResolution": "nodenext", + "resolveJsonModule": true + }, + "include": ["src"] +} +``` + +Do not add `"type": "module"`, and keep `include` at `src` so `prisma.config.ts` is not compiled into +`dist/`. For `tsx`, bundlers or ESM apps, see the guide's link to the tsconfig cases. + +## Bad + +```prisma +// Rewriting schema.prisma into a new contract.prisma before the app even runs on Prisma 8 +``` + +## Good + +```typescript +contract: prisma7Schema("prisma/schema.prisma"), // same file, Prisma ORM 6 or 7 +``` + +## References + +- [Guide, step 2](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#2-create-the-contract-from-your-schema) +- [Guide, step 4](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#4-point-typescript-at-the-prisma-8-client) +- The synced `prisma-8` skill, for the contract itself diff --git a/prisma-postgres-upgrade/references/verify-upgrade-checklist.md b/prisma-postgres-upgrade/references/verify-upgrade-checklist.md new file mode 100644 index 0000000..85d00ec --- /dev/null +++ b/prisma-postgres-upgrade/references/verify-upgrade-checklist.md @@ -0,0 +1,56 @@ +# verify-upgrade-checklist + +Prove the upgrade with the repository's own checks, run the same way before and after. + +## Priority + +CRITICAL + +## Why It Matters + +A query rewrite can compile and still return different data, or fail only at runtime. The only +evidence the user can trust is the project's existing checks passing on both sides of the +change. Checks the agent writes for itself prove only what the agent expected. + +## Rules + +- **Use what the repo has.** Find the type check, build, lint and test scripts in `package.json` + and CI config, and run exactly those. +- **Same commands before and after.** Record each command and its result before step 1. Run + the identical commands after step 7. A check that was already failing before is reported as + such, not fixed silently. +- **Do not invent checks.** Do not write new tests, smoke scripts or per-route requests to + stand in for missing ones, and do not change existing tests to make them pass. +- **No tests? Say so.** If the repository has no tests, tell the user plainly that the upgrade + is verified only by type check, build and the app starting, and leave the change for them to + review before it ships. + +## Checklist + +1. **Baseline:** run the type check (`tsc --noEmit` or the repo's script), the build, and the + test script, then start the app with its own start command and confirm it boots and connects. +2. **After step 5:** same commands, against the same local database. No file imports + `@prisma/client` or the generated client. +3. **After step 6:** `npm run build`, then `npx prisma dev module.mjs` reaches `dev: ready`. +4. **After step 7:** the same commands as the baseline, plus `npx prisma db verify` against the + signed database. +5. **Report:** each command, before and after, pass or fail. List what was not verified: the + Console flow, the preview deploy, and any behavior the tests do not cover, including the rc.20 + `DateTime` and `now()` notes in `client-api-mapping.md`. + +## Bad + +```text +"Added tests/upgrade.test.ts that hits every route; all pass." +``` + +## Good + +```text +Before: tsc ok, build ok, npm test 42 passed. After: tsc ok, build ok, npm test 42 passed, +app starts. The preview deploy is not verified. +``` + +## References + +- [Guide, steps 5.3 and 7](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#53-run-the-app-locally) From 8d7ca1751b373743d8380017c0eb2f70abe4f953 Mon Sep 17 00:00:00 2001 From: Kristof Siket Date: Fri, 6 Nov 2026 14:50:07 +0100 Subject: [PATCH 2/5] refactor(prisma-postgres-upgrade): slim to a bridge that hands off to the prisma-8 skill The prisma-8 skill shipped in @prisma/orm-postgres already covers the contract, migrations and queries for the installed version. This skill now covers only what is specific to leaving Prisma ORM 6 or 7 and landing on Compute, and tells the agent to sync and follow prisma-8 for everything Prisma 8 specific. - Merge schema-contract-mapping and migrations-mapping into adopt-schema-and-migrations, keeping only the 6/7-specific parts - Trim client-api-mapping to the old-to-new call table and the four differences that break rewrites - Note that the setup pull request fixes work around current Console gaps, so the agent reads the PR before changing it - Renumber the path and the verify checklist --- README.md | 1 + prisma-postgres-upgrade/SKILL.md | 105 ++++++++---------- .../references/adopt-schema-and-migrations.md | 60 ++++++++++ .../references/client-api-mapping.md | 69 ++++-------- .../references/compute-setup-pr-fixes.md | 4 + .../references/migrations-mapping.md | 64 ----------- .../references/schema-contract-mapping.md | 88 --------------- .../references/verify-upgrade-checklist.md | 8 +- 8 files changed, 139 insertions(+), 260 deletions(-) create mode 100644 prisma-postgres-upgrade/references/adopt-schema-and-migrations.md delete mode 100644 prisma-postgres-upgrade/references/migrations-mapping.md delete mode 100644 prisma-postgres-upgrade/references/schema-contract-mapping.md diff --git a/README.md b/README.md index d52a076..e9dec86 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ Upgrade a PostgreSQL app from Prisma ORM 6 or 7 straight to Prisma 8 and deploy - Query rewrites and the `@prisma/orm-postgres@8.0.0-rc.20` gotchas - `service.load().db.client` on Compute and the setup pull request fixes - Verifying with the repository's own checks, before and after +- Handing Prisma 8 details to the `prisma-8` skill that ships in `@prisma/orm-postgres` (`npx prisma skills sync`) --- diff --git a/prisma-postgres-upgrade/SKILL.md b/prisma-postgres-upgrade/SKILL.md index d912469..6a55d58 100644 --- a/prisma-postgres-upgrade/SKILL.md +++ b/prisma-postgres-upgrade/SKILL.md @@ -11,101 +11,90 @@ metadata: Move a Node.js server on Prisma ORM 6 or 7 and PostgreSQL to Prisma 8 in one pass, then deploy it on Prisma Compute through the Console's setup pull request. The schema, the database and its -data stay. At the end, Prisma 8 owns migrations, every query runs through the Prisma 8 client, -and a push deploys the app with its own Prisma Postgres database. +data stay. + +This skill is the bridge. It covers only what is specific to leaving Prisma ORM 6 or 7 and +landing on Compute. Prisma 8 itself (the contract, migrations, queries, errors) is covered by the +`prisma-8` skill that ships inside `@prisma/orm-postgres`: install it with `npx prisma skills sync` +as soon as step 2 is done, and follow it for anything Prisma 8 specific. It matches the +installed version; this skill does not. The [Prisma ORM 6 or 7 to 8 on Prisma Compute (PostgreSQL) guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute) -is the source of truth. Follow its steps in order; this skill adds the rules an agent needs and -the pitfalls found while validating it. +is the source of truth for the steps. **Never do either of these:** - Never route a PostgreSQL Prisma ORM 6 app through Prisma ORM 7 first. Prisma 8 reads a Prisma ORM 6 `schema.prisma` unchanged, so `prisma-upgrade-v7` is only for apps that stay on 7. - Never install `prisma@latest` or `@prisma/orm-postgres@latest` while the Console's Compute - setup pins versions: the setup keeps whatever versions `package.json` declares, and the - latest pair does not work with the Composer version it installs, so the deploy fails. + setup pins versions: the latest pair does not work with the Composer version the setup + installs, so the deploy fails. ## When to Apply - A PostgreSQL project on Prisma ORM 6 or 7 asks to upgrade to Prisma 8 - The user wants to deploy a Prisma ORM 6 or 7 app on Prisma Compute -- The Console opened **Set up Prisma Cloud deploys** on a branch named `prisma-cloud/setup` -- A fresh install fails with `@prisma/client did not initialize yet` after the CLI switched to 8 +- The Console blocked setup with "move to Prisma ORM 8", or opened **Set up Prisma Cloud + deploys** on `prisma-cloud/setup` Not for: MongoDB (use `prisma-mongodb-upgrade`), a Prisma ORM 7 app moving one route at a time beside Prisma 8 (follow the [side-by-side guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql)), -or a new project (use `prisma-orm-setup`). - -## Pinned versions - -Install exactly these, with `--save-exact`: +a project already on Prisma 8 (use the synced `prisma-8` skill), or a new project (use +`prisma-orm-setup`). -| Package | Version | Where | -|---------|---------|-------| -| `prisma` | `8.0.0-rc.27` | `devDependencies` | -| `@prisma/orm-postgres` | `8.0.0-rc.20` | `dependencies` | +## Versions -They are `PRISMA_CLI_VERSION` and `ORM_POSTGRES_VERSION` in the Console's Compute setup. When -the setup pull request in the repository lists other versions, use those. Prisma 8 needs -Node.js 22.18+, but `prisma dev` needs Node.js 24.11+, so use 24.11+ throughout. +Install exactly the versions the Console's setup uses, with `--save-exact`: today `prisma` +`8.0.0-rc.27` (dev dependency) and `@prisma/orm-postgres` `8.0.0-rc.20`. If the repository +already has a setup pull request, or the Console's message names other versions, use those. +Use Node.js 24.11 or newer; `prisma dev` needs it. ## The path -| Step | What happens | Reference | -|------|--------------|-----------| -| 0 | Record the baseline: run the repo's own checks before any change | `verify-upgrade-checklist` | -| 1 | `npm uninstall prisma`, install the pins, remove `prisma generate` from scripts | this file | -| 2 | `prisma.config.ts` with `prisma7Schema(...)`, `contract emit`, `db sign` | `schema-contract-mapping` | -| 3 | `migration plan --name init` into `migrations/app/`, delete `prisma/migrations` | `migrations-mapping` | -| 4 | `tsconfig.json`: `nodenext`, `resolveJsonModule` | `schema-contract-mapping` | -| 5 | Prisma 8 client from `DATABASE_URL`, rewrite every query | `client-api-mapping` | -| 6 | Console setup PR, then fix it: service in the build, `service.load().db.client` | `compute-setup-pr-fixes` | -| 7 | Remove `@prisma/client`, the adapter and the generated client | this file | -| 8 | Run the same checks again and start the app | `verify-upgrade-checklist` | - -After step 2 writes `prisma.config.ts`, run `npx prisma skills sync`. It installs the -version-matched `prisma-8` and `prisma-platform-core-concepts` skills from the installed -packages; with a Prisma ORM 7 config still in place it fails with `CLI.CONFIG_UNREADABLE`. Run -it again after step 6 to add `prisma-composer-core-concepts`. Use them for API details from -then on. - -Step 1 removes the only command that generated the old client. The generated client on disk -keeps working locally, but a fresh install (CI, a new clone) has none, so rewrite every query -before pushing to a branch that CI builds. Prisma 8 has no `generate` and no seed command: -`prisma generate` exits 2 with `CLI.UNKNOWN_COMMAND`, so strip it from `build` and -`postinstall`. +| Step | What happens | Where the detail is | +|------|--------------|---------------------| +| 0 | Run the repo's own checks and record the results | `verify-upgrade-checklist` | +| 1 | Remove `prisma`, install the versions above | this file | +| 2 | Prisma 8 `prisma.config.ts` reading the existing schema, `contract emit`, `db sign` | `adopt-schema-and-migrations` | +| 2b | `npx prisma skills sync`; from here, use the `prisma-8` skill for Prisma 8 details | `prisma-8` | +| 3 | Baseline migration, retire `prisma/migrations` | `adopt-schema-and-migrations` | +| 4 | Rewrite every query for the Prisma 8 client | `client-api-mapping` | +| 5 | Console setup pull request, then what it gets wrong | `compute-setup-pr-fixes` | +| 6 | Remove `@prisma/client`, the adapter and the generated client | this file | +| 7 | Run the same checks again and start the app | `verify-upgrade-checklist` | + +Step 1 removes the only command that generated the old client. It keeps working locally, but a +fresh install (CI, a new clone) has none, so finish step 4 before pushing to a branch CI builds. +`npx prisma skills sync` fails with `CLI.CONFIG_UNREADABLE` while a Prisma ORM 7 +`prisma.config.ts` is still in place, which is why it waits for step 2. Run it again after +step 5 to add the Composer skill. ## What the user does -The agent cannot do these; stop and ask the user: +The agent cannot do these; stop and ask: - Connect the repository in the [Prisma Console](https://console.prisma.io), which opens the setup pull request. -- Provide the values for environment variables the app reads (`prisma project env add`). -- Approve the push to `prisma-cloud/setup`. Every push deploys a preview, and merging the - pull request deploys production. +- Provide values for the environment variables the app reads (`prisma project env add`). +- Approve the push to `prisma-cloud/setup`. Every push deploys a preview; merging deploys + production. ## Reference files | Reference | What it covers | |-----------|----------------| -| `references/schema-contract-mapping.md` | `prisma.config.ts`, `prisma7Schema` on a 6 or 7 schema, emit, sign, tsconfig | -| `references/client-api-mapping.md` | Prisma ORM 6/7 calls to Prisma 8, and the rc.20 gotchas | -| `references/migrations-mapping.md` | Baseline in `migrations/app/`, retiring `prisma/migrations`, the change loop | -| `references/compute-setup-pr-fixes.md` | The edits the Console's setup pull request needs before it deploys | +| `references/adopt-schema-and-migrations.md` | Keeping `schema.prisma` as the contract, CommonJS `tsconfig`, the baseline, retiring the old migration setup | +| `references/client-api-mapping.md` | Prisma ORM 6/7 calls to Prisma 8, and four differences that break rewrites | +| `references/compute-setup-pr-fixes.md` | What the Console's setup pull request currently gets wrong | | `references/verify-upgrade-checklist.md` | Proving the upgrade with the repo's own checks | ## Verified against -A Prisma ORM 6.19 app (Express 4, EJS, `tsc`, CommonJS) on PostgreSQL 18, with `prisma` -8.0.0-rc.27, `@prisma/orm-postgres` 8.0.0-rc.20, and `@prisma/composer` / -`@prisma/composer-prisma-cloud` 0.34.0. Steps 1 to 5 and 7 ran end to end, and step 6 ran -locally under `prisma dev`. The Console flow and the Compute runtime were not deployed: those -parts follow the Console's setup code and the Composer types. Before acting on a version-specific -claim, check the installed versions (`npm ls prisma @prisma/orm-postgres`). +A Prisma ORM 6.19 app (Express 4, `tsc`, CommonJS) on PostgreSQL 18, with `prisma` +8.0.0-rc.27, `@prisma/orm-postgres` 8.0.0-rc.20 and Composer 0.34.0, run locally under +`prisma dev`. The Console flow and the Compute runtime were not deployed end to end. ## Hand-off rule -Once the app runs on Prisma 8, follow the synced `prisma-8` skill for day-to-day work and +Once the app runs on Prisma 8, use the synced `prisma-8` skill for day-to-day work and `prisma-compute` for deploy operations. This skill covers the upgrade only. diff --git a/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md b/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md new file mode 100644 index 0000000..7e92aca --- /dev/null +++ b/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md @@ -0,0 +1,60 @@ +# adopt-schema-and-migrations + +Keep the Prisma ORM 6 or 7 `schema.prisma` as the contract, and hand migrations to Prisma 8 once. + +## Priority + +CRITICAL + +## Why It Matters + +Porting the schema by hand risks a contract that no longer matches the tables, which makes +`db sign` fail or plans a destructive migration. And the Compute deploy builds each database +from `migrations/app/`, so without a baseline there, previews and production start with no +tables. + +## What is specific to coming from 6 or 7 + +- **`prisma7Schema(...)` also reads a Prisma ORM 6 schema unchanged**, including the + `generator client` block and `url = env(...)`. Do not edit `schema.prisma` or port it to a + `contract.prisma`. Wire it in the Prisma 8 `prisma.config.ts` with `output: "src/prisma"`, so + `contract.json` and `contract.d.ts` land where `tsc` and the Compute service find them. In a + Prisma ORM 7 app, replace the old `prisma.config.ts`: Prisma 8 reads only its own format + under that name. +- **A CommonJS app built with `tsc` stays CommonJS.** Set `"module"` and `"moduleResolution"` + to `"nodenext"`, add `"resolveJsonModule": true`, keep `include` at `src`, and do not add + `"type": "module"`. +- **Sign the existing database, then plan the baseline:** `contract emit`, `db sign`, + `migration plan --name init`. Sign every other existing database (staging) too; databases the + Compute deploy creates do not need it. +- **Retire the old migration setup:** delete `prisma/migrations` (with `migration_lock.toml`), + remove `prisma generate`, `prisma migrate *` and `prisma db seed` from scripts, and remove the + `"prisma": { "seed": ... }` key. Prisma 8 has no `generate` or seed command. The + `_prisma_migrations` table stays in the database; dropping it is the user's call. + +For the config shape, `contract emit`, `db sign`, the migration commands and every later +schema change, follow the synced `prisma-8` skill (`references/contract.md`, +`references/migration-model.md`, `references/migrations.md`). It matches the installed version. + +## Bad + +```bash +# Rewriting schema.prisma into contract.prisma, or keeping prisma/migrations "for now" +npx prisma7 migrate dev +``` + +## Good + +```typescript +contract: prisma7Schema("prisma/schema.prisma"), // the same file, Prisma ORM 6 or 7 +``` + +```bash +npx prisma contract emit && npx prisma db sign && npx prisma migration plan --name init +rm -r prisma/migrations +``` + +## References + +- [Guide, steps 2 and 3](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#2-create-the-contract-from-your-schema) +- The synced `prisma-8` skill, authoritative for the installed version diff --git a/prisma-postgres-upgrade/references/client-api-mapping.md b/prisma-postgres-upgrade/references/client-api-mapping.md index 425ae51..301f4e2 100644 --- a/prisma-postgres-upgrade/references/client-api-mapping.md +++ b/prisma-postgres-upgrade/references/client-api-mapping.md @@ -1,6 +1,6 @@ # client-api-mapping -Prisma ORM 6 and 7 queries map to the Prisma 8 client the same way; four differences break most rewrites. +Map each Prisma ORM 6 or 7 call to the Prisma 8 client; four differences break most rewrites. ## Priority @@ -8,64 +8,43 @@ CRITICAL ## Why It Matters -The Prisma 8 client chains calls instead of taking one options object, and a schema read through -`prisma7Schema(...)` changes a few types and lookups. At `@prisma/orm-postgres@8.0.0-rc.20`, -some of these compile fine and fail at runtime or write wrong data. +The Prisma 8 client chains calls instead of taking one options object, and a schema read +through `prisma7Schema(...)` changes a few lookups and types. Some of these compile and then +fail at runtime or write wrong data. -## The client (local, before Compute) +## Old call to new call -```typescript -import "dotenv/config"; -import postgres from "@prisma/orm-postgres/runtime"; -import { contractFromJson } from "@prisma/orm-postgres/static"; -import type { Contract } from "./prisma/contract.d"; -import contractJson from "./prisma/contract.json"; - -export const db = postgres({ - contract: contractFromJson(contractJson), - url: process.env["DATABASE_URL"]!, -}); -``` - -On Compute this file changes to `service.load().db.client`; see `compute-setup-pr-fixes.md`. - -## The mapping - -Queries start at `db.orm.public.` (`public` is the PostgreSQL schema). The last call says -what comes back. +Queries start at `db.orm.public.`. For the client itself and anything not listed here, +follow the synced `prisma-8` skill (`references/queries.md`, `references/runtime.md`); on +Compute the client comes from `service.load().db.client` (see `compute-setup-pr-fixes.md`). | Prisma ORM 6 / 7 | Prisma 8 | |------------------|----------| | `findMany({ where, orderBy })` | `.where({...}).orderBy((m) => m.field.asc()).all()` | -| `include: { _count: { select: { posts: true } } }` | `.include("posts", (p) => p.count())`; the number lands in `row.posts`, not `row._count.posts` | -| `orderBy: { votes: { _count: "desc" } }` | `.orderBy((p) => p.votes.count().desc())`; several: pass an array | +| `include: { _count: { select: { posts: true } } }` | `.include("posts", (p) => p.count())`; the number is `row.posts` | +| `orderBy: { votes: { _count: "desc" } }` | `.orderBy((p) => p.votes.count().desc())` | | `findUnique({ where: { id } })` | `.whereUnique({ id }).first()` | -| `findUnique({ where: { slug } })` (`@unique`) | `.where({ slug }).first()` | -| `findUnique({ where: { a_b: { a, b } } })` (`@@unique`) | `.where({ a, b }).first()` | +| `findUnique` on an `@unique` or `@@unique` field | `.where({...}).first()` | | `create({ data: { ..., votes: { create: {...} } } })` | `.create({ ..., votes: (v) => v.create([{...}]) })` | | `deleteMany({ where })` then `.count` | `.where({...}).deleteAndCount()` | | `count({ where })` | `.where({...}).aggregate((a) => ({ total: a.count() }))` | -| `` $queryRaw`SELECT 1` `` | `` db.query(db.raw.sql`SELECT 1 AS ok`.returnsRow({ ok: "pg/int4@1" }).build()) `` | | `Object.values(PostStatus)` from `@prisma/client` | `db.nativeEnums.public.PostStatus.values` | What has no Prisma 8 form yet, such as `increment` in an update, is listed in [Coming from Prisma ORM 7](https://www.prisma.io/docs/orm/coming-from-prisma-orm-7#queries). -## The rc.20 gotchas - -1. **`whereUnique` only on `{ id }`.** Each `@unique` and `@@unique` becomes the unique index - Prisma ORM created, and `whereUnique` accepts only a primary key or unique constraint. Use - `.where({...}).first()`; it runs the same query. -2. **Enums are under `db.nativeEnums`.** A 6/7 `enum` is a PostgreSQL enum type. `db.enums.public` - is empty, while field values stay the same strings. -3. **`DateTime` reads as a string**, such as `"2026-11-06 09:10:48.497"` (UTC, no offset). - `row.createdAt.toISOString()` throws at runtime, often inside a template that `tsc` never - checks. Grep views and response code for `Date` methods on these fields. Convert with - `new Date(value.replace(" ", "T") + "Z")` where a `Date` is needed. Later releases return a - `Date` again. -4. **`@default(now())` is filled by the database.** A `timestamp` column then gets the - database's local time, where Prisma ORM 6/7 sent UTC. If `SHOW timezone` is not `UTC`, new rows are - off by the offset; tell the user rather than silently changing data. +## The four differences + +1. **`whereUnique` only on the primary key.** A 6/7 `@unique` or `@@unique` becomes a unique + index, which `whereUnique` does not accept. Use `.where({...}).first()`. +2. **Enums are under `db.nativeEnums`**, not `db.enums`. The values are the same strings. +3. **`DateTime` may read as a string** (`"2026-11-06 09:10:48.497"`, UTC, no offset) at + `@prisma/orm-postgres@8.0.0-rc.20`. `row.createdAt.toISOString()` then throws at runtime, + often in a template `tsc` never checks. Check the installed version's behavior in the + `prisma-8` skill before converting. +4. **`@default(now())` is filled by the database** at rc.20, so a `timestamp` column gets the + database's local time where 6/7 sent UTC. If `SHOW timezone` is not `UTC`, tell the user + rather than changing data. ## Bad @@ -78,11 +57,9 @@ const label = post.createdAt.toISOString(); // compiles in an .ejs view, throws ```typescript const board = await db.orm.public.Board.where({ slug }).first(); -const label = post.createdAt.slice(0, 10); ``` ## References - [Guide, step 5](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#5-rewrite-your-queries) -- [ORM client reference](https://www.prisma.io/docs/orm/reference/orm-client) - The synced `prisma-8` skill, authoritative for the installed client diff --git a/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md b/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md index d15316a..d6cda08 100644 --- a/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md +++ b/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md @@ -12,6 +12,10 @@ On Compute, `DATABASE_URL` is a reserved variable holding the placeholder `-`. A reading it deploys, then fails every query with `P1001` and `host: "base"`. And only the build output (`dist/`) ships, so anything the server loads from outside it is missing at runtime. +Fixes 1 to 3 and 5 work around current gaps in the setup pull request, which the Console is +fixing. Read what the pull request already contains first, and only change what it gets wrong. +For deploy operations beyond these fixes, follow the `prisma-compute` skill. + ## What the setup pull request adds On branch `prisma-cloud/setup`, titled **Set up Prisma Cloud deploys**: diff --git a/prisma-postgres-upgrade/references/migrations-mapping.md b/prisma-postgres-upgrade/references/migrations-mapping.md deleted file mode 100644 index 2694101..0000000 --- a/prisma-postgres-upgrade/references/migrations-mapping.md +++ /dev/null @@ -1,64 +0,0 @@ -# migrations-mapping - -Prisma 8 owns migrations in `migrations/app/` while it keeps reading `prisma/schema.prisma`. - -## Priority - -HIGH - -## Why It Matters - -The Compute deploy creates an empty database per branch and applies `migrations/app/` to it. -Without a baseline there, previews and production deploy with no tables. Keeping -`prisma migrate` alongside Prisma 8 splits the migration history in two. - -## Hand over - -After `db sign` (see `schema-contract-mapping.md`): - -```bash -npx prisma migration plan --name init # Planned baseline (N operation(s)) + 0 operation(s) -npx prisma db migrate # (no operations) on the signed database -rm -r prisma/migrations # includes migration_lock.toml -``` - -- The baseline in `migrations/app/_baseline` creates every table, index and foreign - key in the contract, so a signed database skips it and an empty one applies it. -- `--name` is ignored when the plan has no operations of its own beyond the baseline. -- Prisma 8 does not read `prisma/migrations`. Keep `prisma/schema.prisma`: it is still the - contract. -- The `_prisma_migrations` table stays in the database. Prisma 8 ignores it in `db verify` and - `contract infer`; dropping it is the user's call. -- Remove `prisma migrate dev`, `prisma migrate deploy` and `prisma db seed` scripts, and the - `"prisma": { "seed": ... }` key, because Prisma 8 has no seed command; a seed is a `tsx` script that - imports the client. - -## Every later schema change - -Edit `prisma/schema.prisma`, then: - -```bash -npx prisma contract emit -npx prisma migration plan --name -npx prisma db migrate --advance-ref db -npx prisma db verify -``` - -`--advance-ref db` points `migrations/app/refs/db.json` at the new contract, so the next plan diffs from it. - -## Bad - -```bash -npx prisma7 migrate dev # or keeping prisma/migrations "for now" -``` - -## Good - -```bash -npx prisma migration plan --name init && rm -r prisma/migrations -``` - -## References - -- [Guide, step 3](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#3-hand-migrations-to-prisma-8) -- [How migrations work](https://www.prisma.io/docs/orm/migrations/how-migrations-work) diff --git a/prisma-postgres-upgrade/references/schema-contract-mapping.md b/prisma-postgres-upgrade/references/schema-contract-mapping.md deleted file mode 100644 index 51558a2..0000000 --- a/prisma-postgres-upgrade/references/schema-contract-mapping.md +++ /dev/null @@ -1,88 +0,0 @@ -# schema-contract-mapping - -Prisma 8 reads the existing Prisma ORM 6 or 7 `schema.prisma` as its contract; do not port it. - -## Priority - -CRITICAL - -## Why It Matters - -Porting the schema by hand risks a contract that no longer matches the tables, and a mismatch -makes `db sign` fail or plans a destructive migration. `prisma7Schema(...)` reads the file the -app already has, including a Prisma ORM 6 schema, so the database is never touched. - -## prisma.config.ts - -Create it in the project root. In a Prisma ORM 7 app, replace the existing one: Prisma 8 reads -only its own config format under that name. - -```typescript -import "dotenv/config"; -import { definePrismaConfig } from "prisma/config"; -import { defineConfig, prisma7Schema } from "@prisma/orm-postgres/config"; - -export default definePrismaConfig({ - orm: defineConfig({ - contract: prisma7Schema("prisma/schema.prisma"), - output: "src/prisma", - db: { connection: process.env["DATABASE_URL"] }, - }), -}); -``` - -- Leave `schema.prisma` alone. The `generator client { ... }` block and `url = env(...)` in the - datasource stay; Prisma 8 ignores them. -- `output: "src/prisma"` puts `contract.json` and `contract.d.ts` inside `src/`, where `tsc` - compiles them and the Compute service imports them. -- `view` blocks and some extensions need extra config; see - [Use a Prisma ORM 7 schema](https://www.prisma.io/docs/cli/configuration#use-a-prisma-orm-7-schema). - -## Emit and sign - -```bash -npx prisma contract emit # Emitted contract.json and contract.d.ts -npx prisma db sign # Database signed, Advanced ref "db" -``` - -Commit both emitted files, and run `contract emit` after every edit to `schema.prisma`. `db sign` -checks the tables match, writes a marker, and writes `migrations/app/refs/db.json`; it does not -change tables. Run it once against every other existing database (staging) too. A database the -Compute deploy creates does not need it. - -## tsconfig.json for a tsc + node app - -Prisma 8 packages are ES modules, and the code imports `contract.json`. A CommonJS app compiled -with `tsc` stays CommonJS: - -```json -{ - "compilerOptions": { - "module": "nodenext", - "moduleResolution": "nodenext", - "resolveJsonModule": true - }, - "include": ["src"] -} -``` - -Do not add `"type": "module"`, and keep `include` at `src` so `prisma.config.ts` is not compiled into -`dist/`. For `tsx`, bundlers or ESM apps, see the guide's link to the tsconfig cases. - -## Bad - -```prisma -// Rewriting schema.prisma into a new contract.prisma before the app even runs on Prisma 8 -``` - -## Good - -```typescript -contract: prisma7Schema("prisma/schema.prisma"), // same file, Prisma ORM 6 or 7 -``` - -## References - -- [Guide, step 2](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#2-create-the-contract-from-your-schema) -- [Guide, step 4](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#4-point-typescript-at-the-prisma-8-client) -- The synced `prisma-8` skill, for the contract itself diff --git a/prisma-postgres-upgrade/references/verify-upgrade-checklist.md b/prisma-postgres-upgrade/references/verify-upgrade-checklist.md index 85d00ec..3d9464d 100644 --- a/prisma-postgres-upgrade/references/verify-upgrade-checklist.md +++ b/prisma-postgres-upgrade/references/verify-upgrade-checklist.md @@ -17,7 +17,7 @@ change. Checks the agent writes for itself prove only what the agent expected. - **Use what the repo has.** Find the type check, build, lint and test scripts in `package.json` and CI config, and run exactly those. - **Same commands before and after.** Record each command and its result before step 1. Run - the identical commands after step 7. A check that was already failing before is reported as + the identical commands after step 6. A check that was already failing before is reported as such, not fixed silently. - **Do not invent checks.** Do not write new tests, smoke scripts or per-route requests to stand in for missing ones, and do not change existing tests to make them pass. @@ -29,10 +29,10 @@ change. Checks the agent writes for itself prove only what the agent expected. 1. **Baseline:** run the type check (`tsc --noEmit` or the repo's script), the build, and the test script, then start the app with its own start command and confirm it boots and connects. -2. **After step 5:** same commands, against the same local database. No file imports +2. **After step 4:** same commands, against the same local database. No file imports `@prisma/client` or the generated client. -3. **After step 6:** `npm run build`, then `npx prisma dev module.mjs` reaches `dev: ready`. -4. **After step 7:** the same commands as the baseline, plus `npx prisma db verify` against the +3. **After step 5:** `npm run build`, then `npx prisma dev module.mjs` reaches `dev: ready`. +4. **After step 6:** the same commands as the baseline, plus `npx prisma db verify` against the signed database. 5. **Report:** each command, before and after, pass or fail. List what was not verified: the Console flow, the preview deploy, and any behavior the tests do not cover, including the rc.20 From 2fc9d4eb993a896f9978fb6b77cd9addc63d6958 Mon Sep 17 00:00:00 2001 From: Kristof Siket Date: Fri, 6 Nov 2026 16:36:47 +0100 Subject: [PATCH 3/5] fix(prisma-postgres-upgrade): apply findings from a blind agent run - Write the first Prisma 8 config in this skill and sync right after it; one sync installs all three skills - Explain that prisma-8's 'does not apply' check is expected mid-upgrade - Use .first({ id }) for primary-key lookups, matching prisma-8 - Document the auto-named baseline, the CommonJS JSON import, the seed client and start-command change - Add the files to write without a Console setup pull request, including module: module.mjs in the workflow - Pass env vars as service inputs; flag a non-UTC database time zone as a behavior change --- README.md | 2 +- prisma-postgres-upgrade/SKILL.md | 65 ++++++++------ .../references/adopt-schema-and-migrations.md | 54 +++++++---- .../references/client-api-mapping.md | 23 +++-- .../references/compute-setup-pr-fixes.md | 89 ++++++++++++++++--- .../references/verify-upgrade-checklist.md | 10 ++- 6 files changed, 175 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index e9dec86..b31904e 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Upgrade a PostgreSQL app from Prisma ORM 6 or 7 straight to Prisma 8 and deploy - Reading the existing `schema.prisma` with `prisma7Schema(...)`, `contract emit` and `db sign` - Prisma 8 owning migrations in `migrations/app/` - Query rewrites and the `@prisma/orm-postgres@8.0.0-rc.20` gotchas -- `service.load().db.client` on Compute and the setup pull request fixes +- `service.load().db.client` on Compute, the setup pull request fixes, and the same files without one - Verifying with the repository's own checks, before and after - Handing Prisma 8 details to the `prisma-8` skill that ships in `@prisma/orm-postgres` (`npx prisma skills sync`) diff --git a/prisma-postgres-upgrade/SKILL.md b/prisma-postgres-upgrade/SKILL.md index 6a55d58..a19c270 100644 --- a/prisma-postgres-upgrade/SKILL.md +++ b/prisma-postgres-upgrade/SKILL.md @@ -4,20 +4,22 @@ description: Upgrade a PostgreSQL app from Prisma ORM 6 or 7 straight to Prisma license: MIT metadata: author: prisma - version: "1.0.0" + version: "1.1.0" --- # Prisma Postgres Upgrade: Prisma ORM 6 or 7 to Prisma 8 on Compute Move a Node.js server on Prisma ORM 6 or 7 and PostgreSQL to Prisma 8 in one pass, then deploy -it on Prisma Compute through the Console's setup pull request. The schema, the database and its -data stay. +it on Prisma Compute. The schema, the database and its data stay. This skill is the bridge. It covers only what is specific to leaving Prisma ORM 6 or 7 and landing on Compute. Prisma 8 itself (the contract, migrations, queries, errors) is covered by the -`prisma-8` skill that ships inside `@prisma/orm-postgres`: install it with `npx prisma skills sync` -as soon as step 2 is done, and follow it for anything Prisma 8 specific. It matches the -installed version; this skill does not. +`prisma-8` skill that ships inside `@prisma/orm-postgres`, which step 2 installs. Follow it for +anything Prisma 8 specific; it matches the installed version, and this skill does not. + +`prisma-8` says it does not apply to a project that still has `schema.prisma` and +`@prisma/client`. That is expected mid-upgrade: this skill keeps both until step 6, and +`prisma7Schema(...)` reads that `schema.prisma`. Use `prisma-8` for the Prisma 8 side anyway. The [Prisma ORM 6 or 7 to 8 on Prisma Compute (PostgreSQL) guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute) is the source of truth for the steps. @@ -26,9 +28,9 @@ is the source of truth for the steps. - Never route a PostgreSQL Prisma ORM 6 app through Prisma ORM 7 first. Prisma 8 reads a Prisma ORM 6 `schema.prisma` unchanged, so `prisma-upgrade-v7` is only for apps that stay on 7. -- Never install `prisma@latest` or `@prisma/orm-postgres@latest` while the Console's Compute - setup pins versions: the latest pair does not work with the Composer version the setup - installs, so the deploy fails. +- Never install `prisma@latest`, `@prisma/orm-postgres@latest` or the latest Composer packages + while the Console's Compute setup pins versions: the latest set does not work together, so the + deploy fails. ## When to Apply @@ -45,9 +47,11 @@ a project already on Prisma 8 (use the synced `prisma-8` skill), or a new projec ## Versions Install exactly the versions the Console's setup uses, with `--save-exact`: today `prisma` -`8.0.0-rc.27` (dev dependency) and `@prisma/orm-postgres` `8.0.0-rc.20`. If the repository -already has a setup pull request, or the Console's message names other versions, use those. -Use Node.js 24.11 or newer; `prisma dev` needs it. +`8.0.0-rc.27` (dev dependency), `@prisma/orm-postgres` `8.0.0-rc.20`, and in step 5 +`@prisma/composer` and `@prisma/composer-prisma-cloud` `0.34.0` (the release that peers on +`@prisma/orm-postgres` `8.0.0-rc.20`). If the repository already has a setup pull request, or +the Console's message names other versions, use those. Use Node.js 24.11 or newer; `prisma dev` +needs it. ## The path @@ -55,44 +59,53 @@ Use Node.js 24.11 or newer; `prisma dev` needs it. |------|--------------|---------------------| | 0 | Run the repo's own checks and record the results | `verify-upgrade-checklist` | | 1 | Remove `prisma`, install the versions above | this file | -| 2 | Prisma 8 `prisma.config.ts` reading the existing schema, `contract emit`, `db sign` | `adopt-schema-and-migrations` | -| 2b | `npx prisma skills sync`; from here, use the `prisma-8` skill for Prisma 8 details | `prisma-8` | -| 3 | Baseline migration, retire `prisma/migrations` | `adopt-schema-and-migrations` | +| 2 | Write the Prisma 8 `prisma.config.ts`, then `npx prisma skills sync` | `adopt-schema-and-migrations` | +| 3 | `contract emit`, `db sign`, baseline migration, retire `prisma/migrations` | `adopt-schema-and-migrations` | | 4 | Rewrite every query for the Prisma 8 client | `client-api-mapping` | -| 5 | Console setup pull request, then what it gets wrong | `compute-setup-pr-fixes` | +| 5 | Compute: the Console setup pull request and its fixes, or the same files written by hand | `compute-setup-pr-fixes` | | 6 | Remove `@prisma/client`, the adapter and the generated client | this file | | 7 | Run the same checks again and start the app | `verify-upgrade-checklist` | Step 1 removes the only command that generated the old client. It keeps working locally, but a fresh install (CI, a new clone) has none, so finish step 4 before pushing to a branch CI builds. -`npx prisma skills sync` fails with `CLI.CONFIG_UNREADABLE` while a Prisma ORM 7 -`prisma.config.ts` is still in place, which is why it waits for step 2. Run it again after -step 5 to add the Composer skill. + +The sync in step 2 installs `prisma-8`, `prisma-platform-core-concepts` and +`prisma-composer-core-concepts` in one go, because the CLI depends on Composer. It writes them +for every agent it knows unless `skills.agents` in the config lists only the ones the repository +uses. In a Prisma ORM 7 app, replace the old `prisma.config.ts` before syncing: the sync fails +with `CLI.CONFIG_UNREADABLE` while the old one is in place. + +In step 6, `npm uninstall @prisma/client` leaves the generated client behind; delete +`node_modules/.prisma` too, then run a fresh install and the checks so nothing still imports it. ## What the user does The agent cannot do these; stop and ask: - Connect the repository in the [Prisma Console](https://console.prisma.io), which opens the - setup pull request. + setup pull request, or run `npx prisma git connect`, which is interactive. +- Choose the region for the first deploy. It cannot be changed later. - Provide values for the environment variables the app reads (`prisma project env add`). - Approve the push to `prisma-cloud/setup`. Every push deploys a preview; merging deploys production. +- Decide what to do about a database time zone other than UTC (see `client-api-mapping`). ## Reference files | Reference | What it covers | |-----------|----------------| -| `references/adopt-schema-and-migrations.md` | Keeping `schema.prisma` as the contract, CommonJS `tsconfig`, the baseline, retiring the old migration setup | -| `references/client-api-mapping.md` | Prisma ORM 6/7 calls to Prisma 8, and four differences that break rewrites | -| `references/compute-setup-pr-fixes.md` | What the Console's setup pull request currently gets wrong | +| `references/adopt-schema-and-migrations.md` | The first `prisma.config.ts`, keeping `schema.prisma` as the contract, CommonJS `tsconfig`, the baseline, retiring the old migration setup | +| `references/client-api-mapping.md` | Prisma ORM 6/7 calls to Prisma 8, and the differences that break rewrites | +| `references/compute-setup-pr-fixes.md` | What the Console's setup pull request gets wrong, and the files to write without one | | `references/verify-upgrade-checklist.md` | Proving the upgrade with the repo's own checks | ## Verified against -A Prisma ORM 6.19 app (Express 4, `tsc`, CommonJS) on PostgreSQL 18, with `prisma` -8.0.0-rc.27, `@prisma/orm-postgres` 8.0.0-rc.20 and Composer 0.34.0, run locally under -`prisma dev`. The Console flow and the Compute runtime were not deployed end to end. +A Prisma ORM 6.19 app (Express 4, EJS, `tsc`, CommonJS) on PostgreSQL 18, with `prisma` +8.0.0-rc.27, `@prisma/orm-postgres` 8.0.0-rc.20 and Composer 0.34.0. An agent with only this +skill upgraded it with no setup pull request: pages and API output were identical before and +after against the same database, and `npx prisma dev module.mjs` reached `dev: ready`. The +Console flow and the Compute runtime were not deployed end to end. ## Hand-off rule diff --git a/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md b/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md index 7e92aca..ca3dd69 100644 --- a/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md +++ b/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md @@ -13,28 +13,50 @@ Porting the schema by hand risks a contract that no longer matches the tables, w from `migrations/app/`, so without a baseline there, previews and production start with no tables. +## The first `prisma.config.ts` (step 2) + +```typescript +import "dotenv/config"; // only if the app already uses dotenv +import { defineConfig as orm, prisma7Schema } from "@prisma/orm-postgres/config"; +import { definePrismaConfig } from "prisma/config"; + +export default definePrismaConfig({ + orm: orm({ + contract: prisma7Schema("prisma/schema.prisma"), // the same file, Prisma ORM 6 or 7 + output: "src/prisma", + db: { connection: process.env["DATABASE_URL"]! }, + }), + skills: { agents: ["claude"] }, // only the agents the repository uses +}); +``` + +Then run `npx prisma skills sync`. Step 5 adds a `composer` section to the same config. + ## What is specific to coming from 6 or 7 - **`prisma7Schema(...)` also reads a Prisma ORM 6 schema unchanged**, including the `generator client` block and `url = env(...)`. Do not edit `schema.prisma` or port it to a - `contract.prisma`. Wire it in the Prisma 8 `prisma.config.ts` with `output: "src/prisma"`, so - `contract.json` and `contract.d.ts` land where `tsc` and the Compute service find them. In a - Prisma ORM 7 app, replace the old `prisma.config.ts`: Prisma 8 reads only its own format - under that name. + `contract.prisma`. `output: "src/prisma"` puts `contract.json` and `contract.d.ts` where `tsc` + and the Compute service find them. In a Prisma ORM 7 app, this file replaces the old + `prisma.config.ts`: Prisma 8 reads only its own format under that name. - **A CommonJS app built with `tsc` stays CommonJS.** Set `"module"` and `"moduleResolution"` to `"nodenext"`, add `"resolveJsonModule": true`, keep `include` at `src`, and do not add `"type": "module"`. -- **Sign the existing database, then plan the baseline:** `contract emit`, `db sign`, - `migration plan --name init`. Sign every other existing database (staging) too; databases the - Compute deploy creates do not need it. +- **Sign the existing database, then plan the baseline:** `npx prisma contract emit`, + `npx prisma db sign`, `npx prisma migration plan`. The first plan on a signed database writes + `migrations/app/_baseline/` and ignores `--name`; `db verify` then passes and + `db migrate` has nothing to apply. Sign every other existing database (staging) too; databases + the Compute deploy creates do not need it. - **Retire the old migration setup:** delete `prisma/migrations` (with `migration_lock.toml`), - remove `prisma generate`, `prisma migrate *` and `prisma db seed` from scripts, and remove the - `"prisma": { "seed": ... }` key. Prisma 8 has no `generate` or seed command. The - `_prisma_migrations` table stays in the database; dropping it is the user's call. + remove `prisma generate`, `prisma migrate *` and `prisma db seed` from scripts (including + `postinstall`), and remove the `"prisma": { "seed": ... }` key. Prisma 8 has no `generate` or + seed command; keep the seed script and run it with `tsx` (see `compute-setup-pr-fixes.md`, + fix 4). The `_prisma_migrations` table stays in the database; dropping it is the user's call. -For the config shape, `contract emit`, `db sign`, the migration commands and every later -schema change, follow the synced `prisma-8` skill (`references/contract.md`, -`references/migration-model.md`, `references/migrations.md`). It matches the installed version. +For `contract emit`, `db sign`, the migration commands and every later schema change, follow the +synced `prisma-8` skill (`references/contract.md`, `references/migration-model.md`, +`references/migrations.md`). Where it shows `definePrismaConfig` from another package, use +`prisma/config` as above: that is what the installed CLI exports. ## Bad @@ -45,12 +67,8 @@ npx prisma7 migrate dev ## Good -```typescript -contract: prisma7Schema("prisma/schema.prisma"), // the same file, Prisma ORM 6 or 7 -``` - ```bash -npx prisma contract emit && npx prisma db sign && npx prisma migration plan --name init +npx prisma contract emit && npx prisma db sign && npx prisma migration plan rm -r prisma/migrations ``` diff --git a/prisma-postgres-upgrade/references/client-api-mapping.md b/prisma-postgres-upgrade/references/client-api-mapping.md index 301f4e2..087584f 100644 --- a/prisma-postgres-upgrade/references/client-api-mapping.md +++ b/prisma-postgres-upgrade/references/client-api-mapping.md @@ -1,6 +1,6 @@ # client-api-mapping -Map each Prisma ORM 6 or 7 call to the Prisma 8 client; four differences break most rewrites. +Map each Prisma ORM 6 or 7 call to the Prisma 8 client; five differences break most rewrites. ## Priority @@ -21,9 +21,9 @@ Compute the client comes from `service.load().db.client` (see `compute-setup-pr- | Prisma ORM 6 / 7 | Prisma 8 | |------------------|----------| | `findMany({ where, orderBy })` | `.where({...}).orderBy((m) => m.field.asc()).all()` | -| `include: { _count: { select: { posts: true } } }` | `.include("posts", (p) => p.count())`; the number is `row.posts` | +| `include: { _count: { select: { posts: true } } }` | `.include("posts", (p) => p.count())`; the number is `row.posts`, not `row._count.posts` | | `orderBy: { votes: { _count: "desc" } }` | `.orderBy((p) => p.votes.count().desc())` | -| `findUnique({ where: { id } })` | `.whereUnique({ id }).first()` | +| `findUnique({ where: { id } })` | `.first({ id })` | | `findUnique` on an `@unique` or `@@unique` field | `.where({...}).first()` | | `create({ data: { ..., votes: { create: {...} } } })` | `.create({ ..., votes: (v) => v.create([{...}]) })` | | `deleteMany({ where })` then `.count` | `.where({...}).deleteAndCount()` | @@ -33,10 +33,10 @@ Compute the client comes from `service.load().db.client` (see `compute-setup-pr- What has no Prisma 8 form yet, such as `increment` in an update, is listed in [Coming from Prisma ORM 7](https://www.prisma.io/docs/orm/coming-from-prisma-orm-7#queries). -## The four differences +## The five differences -1. **`whereUnique` only on the primary key.** A 6/7 `@unique` or `@@unique` becomes a unique - index, which `whereUnique` does not accept. Use `.where({...}).first()`. +1. **Unique lookups use `.first(...)` or `.where(...).first()`.** A 6/7 `@unique` or `@@unique` + becomes a unique index, which `whereUnique` does not accept, so do not reach for it. 2. **Enums are under `db.nativeEnums`**, not `db.enums`. The values are the same strings. 3. **`DateTime` may read as a string** (`"2026-11-06 09:10:48.497"`, UTC, no offset) at `@prisma/orm-postgres@8.0.0-rc.20`. `row.createdAt.toISOString()` then throws at runtime, @@ -44,19 +44,24 @@ What has no Prisma 8 form yet, such as `increment` in an update, is listed in `prisma-8` skill before converting. 4. **`@default(now())` is filled by the database** at rc.20, so a `timestamp` column gets the database's local time where 6/7 sent UTC. If `SHOW timezone` is not `UTC`, tell the user - rather than changing data. + rather than changing data: new rows will store a different time than before, which is a + behavior change the user has to decide on. +5. **Templates and other code `tsc` does not check still read the old shapes.** Search views + (`.ejs`, `.hbs`, `.pug`) and plain `.js` files for `_count.`, `.toISOString()` on dates, and + enum imports, and change them with the queries. ## Bad -```typescript +```text const board = await db.orm.public.Board.whereUnique({ slug }).first(); // does not compile -const label = post.createdAt.toISOString(); // compiles in an .ejs view, throws at runtime +<%= post._count.votes %> ``` ## Good ```typescript const board = await db.orm.public.Board.where({ slug }).first(); +const post = await db.orm.public.Post.include("votes", (v) => v.count()).first({ id }); // post.votes ``` ## References diff --git a/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md b/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md index d6cda08..b4b1313 100644 --- a/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md +++ b/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md @@ -1,6 +1,7 @@ # compute-setup-pr-fixes The Console's setup pull request needs these edits before a `tsc`-built app deploys and works. +Without a setup pull request, write the same files by hand. ## Priority @@ -14,7 +15,9 @@ output (`dist/`) ships, so anything the server loads from outside it is missing Fixes 1 to 3 and 5 work around current gaps in the setup pull request, which the Console is fixing. Read what the pull request already contains first, and only change what it gets wrong. -For deploy operations beyond these fixes, follow the `prisma-compute` skill. +For deploy operations beyond these fixes, follow the `prisma-compute` skill. It and the synced +Composer skill show `module.ts`; this skill uses `module.mjs`, because a `tsc` app's service is +loaded from `dist/`. ## What the setup pull request adds @@ -24,6 +27,40 @@ to previews), `module.mjs`, a root `service.mjs`, a `composer` section in `prism the Composer packages. It keeps the `prisma` and `@prisma/orm-postgres` versions already in `package.json`. The setup branch deploys as a preview; merging deploys production. +## Without a setup pull request + +When the user has not connected the repository yet, write these, then apply fixes 1 to 6: + +- Install `@prisma/composer` and `@prisma/composer-prisma-cloud` at the pinned version, with + `--save-exact`. +- Add to `prisma.config.ts`: + + ```typescript + import { defineConfig as composer } from "@prisma/composer/config"; + import { nodeBuild } from "@prisma/composer/node/control"; + import { prismaCloud, prismaState } from "@prisma/composer-prisma-cloud/control"; + // inside definePrismaConfig({ ... }): + composer: composer({ extensions: [prismaCloud(), nodeBuild()], state: prismaState() }), + ``` + +- `module.mjs`, which provisions the database from the same contract the service uses: + + ```javascript + import { module } from "@prisma/composer"; + import { postgres } from "@prisma/composer-prisma-cloud/orm"; + import web, { data } from "./dist/service.mjs"; + + export default module("", ({ provision }) => { + const database = provision(postgres({ name: "database", contract: data, config: "prisma.config.ts" })); + provision(web, { deps: { db: database } }); + }); + ``` + +- `.github/workflows/prisma-deploy.yml` from the `prisma-platform-core-concepts` skill, with + `module: module.mjs` added to the `prisma/cloud-deploy-action` inputs. The action looks for + `module.ts` by default. +- `.prisma/`, `.prisma-composer/` and `.alchemy/` in `.gitignore`. + ## The fixes 1. **Move the service into the build.** The root `service.mjs` has no types (TS7016 when @@ -37,9 +74,11 @@ the Composer packages. It keeps the `prisma` and `@prisma/orm-postgres` versions import type { Contract } from "./prisma/contract.js"; import contractJson from "./prisma/contract.json" with { type: "json" }; + export const data = dataContract(contractJson); + export default compute({ name: "", - deps: { db: postgres(dataContract(contractJson)) }, + deps: { db: postgres(data) }, build: node({ module: import.meta.url, dir: ".", entry: "server.js", dependencies: "external" }), }); ``` @@ -49,7 +88,7 @@ the Composer packages. It keeps the `prisma` and `@prisma/orm-postgres` versions whose `npm start` runs `server.js`); it is the file in `dist/` that `npm start` runs. 3. **`dependencies: "external"`.** `tsc` does not bundle, so the deploy must ship `node_modules` packages the entry imports. -4. **Take the client from the service.** +4. **Take the client from the service, and run under Composer.** ```typescript // src/db.ts @@ -57,17 +96,45 @@ the Composer packages. It keeps the `prisma` and `@prisma/orm-postgres` versions export const db = service.load().db.client; ``` - `service.load().db.url` is there for a library that needs a connection string. Outside a - Composer run, `service.load()` throws `missing required config param "url"`, so run locally - with `npm run build && npx prisma dev module.mjs` (Node.js 24.11+). It starts a local - Prisma Postgres, applies `migrations/app/`, and prints `dev: ready`. That database is empty. + - `service.load().db.url` is there for a library that needs a connection string. + - Listen on `service.port()` and `"0.0.0.0"`, not `process.env.PORT`. + - Outside a Composer run, `service.load()` throws `missing required config param "url"`. So + `npm start`, a `tsx` dev script and any `Procfile` stop working. Run locally with + `npm run build && npx prisma dev module.mjs` (Node.js 24.11+), and make that the `dev` + script. It starts a local Prisma Postgres, applies `migrations/app/`, and prints + `dev: ready`. That database is empty. + - A seed script must not import `db.ts`. Give it its own client, and seed with + `DATABASE_URL="$(npx prisma dev url database)" npx tsx prisma/seed.ts`: + + ```typescript + import postgres from "@prisma/orm-postgres/runtime"; + import { contractFromJson } from "@prisma/orm-postgres/static"; + import type { Contract } from "../src/prisma/contract.js"; + import contractJson from "../src/prisma/contract.json"; // no import attribute in a CommonJS .ts file + + const db = postgres({ contract: contractFromJson(contractJson), url: process.env["DATABASE_URL"]! }); + ``` + + The `with { type: "json" }` attribute the `prisma-8` skill requires is only valid in `.mts` + files such as `service.mts`; in a CommonJS `.ts` file it fails with TS2856. 5. **Ship runtime files.** Copy `views/`, `public/` or similar into `dist/` in `build` (`tsc && cp -R views public dist/`) and resolve them from `__dirname`. Otherwise every rendered page fails with `Failed to lookup view`. -6. **Environment variables.** Every variable other than the database and `PORT` goes in with - `prisma project env add KEY --role production` and `--role preview`, value read from the - environment. Ask the user for values; never invent secrets. `prisma dev` does not pass shell - variables, so a variable required at startup needs a local default or a service input. +6. **Environment variables.** Pass each variable other than the database and the port as a + service input, not through `process.env`: + + ```typescript + // src/service.mts: add to compute({ ... }) + input: type({ sessionSecret: secretString() }), // type from "arktype", secretString from "@prisma/composer/arktype" + // module.mjs: envSecret from "@prisma/composer-prisma-cloud" + provision(web, { deps: { db: database }, input: { sessionSecret: envSecret("SESSION_SECRET") } }); + // src/server.ts + const SESSION_SECRET = service.input().sessionSecret.expose(); + ``` + + Add `arktype` as a direct dependency, at the version `@prisma/composer` uses + (`npm ls arktype`). The user sets the values with `prisma project env add KEY --role + production` and `--role preview`. Ask the user for values; never invent secrets. Then ask the user before pushing. After the push, `npx prisma service list --branch prisma-cloud/setup` shows the preview URL. diff --git a/prisma-postgres-upgrade/references/verify-upgrade-checklist.md b/prisma-postgres-upgrade/references/verify-upgrade-checklist.md index 3d9464d..9c04666 100644 --- a/prisma-postgres-upgrade/references/verify-upgrade-checklist.md +++ b/prisma-postgres-upgrade/references/verify-upgrade-checklist.md @@ -29,14 +29,18 @@ change. Checks the agent writes for itself prove only what the agent expected. 1. **Baseline:** run the type check (`tsc --noEmit` or the repo's script), the build, and the test script, then start the app with its own start command and confirm it boots and connects. + Record `SHOW timezone` on the database. 2. **After step 4:** same commands, against the same local database. No file imports `@prisma/client` or the generated client. 3. **After step 5:** `npm run build`, then `npx prisma dev module.mjs` reaches `dev: ready`. -4. **After step 6:** the same commands as the baseline, plus `npx prisma db verify` against the - signed database. +4. **After step 6:** a fresh install, then the same commands as the baseline, plus + `npx prisma db verify` against the signed database. `npm start` now fails outside Composer + by design (`compute-setup-pr-fixes.md`, fix 4), so start the app with `prisma dev` + instead and report that the start command changed. 5. **Report:** each command, before and after, pass or fail. List what was not verified: the Console flow, the preview deploy, and any behavior the tests do not cover, including the rc.20 - `DateTime` and `now()` notes in `client-api-mapping.md`. + `DateTime` and `now()` notes in `client-api-mapping.md`. If the database's time zone is not + UTC, say so first: new rows store a different time than before. ## Bad From f4bbdbe3bc5e1239f2e0aeb1e8cf8a35822789c1 Mon Sep 17 00:00:00 2001 From: Kristof Siket Date: Mon, 9 Nov 2026 09:35:45 +0100 Subject: [PATCH 4/5] refactor: split upgrading to Prisma 8 from deploying on Compute - prisma-postgres-upgrade covers only the upgrade and keeps the app runnable on any host - Move the setup-PR fixes into prisma-compute as references/deploy-existing-app.md - prisma-compute: pin Composer to the installed ORM, note prisma dev needs Node 24.11 - Fold in the second blind run: drop prisma generate in step 1, commit contract and migrations, client setup, delete-all, createAll and raw SELECT 1, manual page comparison is not a test - Point links at the restructured guides (/postgresql, /postgresql-incremental, /guides/compute/deploy-existing-app) --- README.md | 13 ++- prisma-compute/SKILL.md | 7 +- .../references/app-composer-setup.md | 2 +- .../references/deploy-existing-app.md | 62 ++++++------ prisma-orm-setup/SKILL.md | 2 +- prisma-postgres-upgrade/SKILL.md | 97 ++++++++++--------- .../references/adopt-schema-and-migrations.md | 10 +- .../references/client-api-mapping.md | 30 +++++- .../references/verify-upgrade-checklist.md | 25 ++--- 9 files changed, 138 insertions(+), 110 deletions(-) rename prisma-postgres-upgrade/references/compute-setup-pr-fixes.md => prisma-compute/references/deploy-existing-app.md (72%) diff --git a/README.md b/README.md index b31904e..9c66cf9 100644 --- a/README.md +++ b/README.md @@ -64,19 +64,17 @@ Decision and migration guide for MongoDB projects on Prisma v6, which have no pa ### prisma-postgres-upgrade -Upgrade a PostgreSQL app from Prisma ORM 6 or 7 straight to Prisma 8 and deploy it on Prisma Compute, following the [Prisma ORM 6 or 7 to 8 on Prisma Compute guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute). +Upgrade a PostgreSQL app from Prisma ORM 6 or 7 straight to Prisma 8 in one pass, following the [Prisma ORM 6 or 7 to 8 (PostgreSQL) guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql). To deploy the result on Prisma Compute, use `prisma-compute`. **Use when:** - A PostgreSQL project on Prisma ORM 6 or 7 wants Prisma 8 -- Deploying a Prisma ORM 6 or 7 app on Prisma Compute -- Finishing the Console's "Set up Prisma Cloud deploys" pull request +- A Prisma ORM 6 or 7 app has to reach Prisma 8 before it can deploy on Prisma Compute **Topics covered:** -- The Prisma 8 versions the Console's Compute setup pins, and why not `@latest` +- Exact versions, and why not `@latest` for apps headed to Compute - Reading the existing `schema.prisma` with `prisma7Schema(...)`, `contract emit` and `db sign` - Prisma 8 owning migrations in `migrations/app/` -- Query rewrites and the `@prisma/orm-postgres@8.0.0-rc.20` gotchas -- `service.load().db.client` on Compute, the setup pull request fixes, and the same files without one +- The Prisma 8 client, query rewrites and the `@prisma/orm-postgres@8.0.0-rc.20` gotchas, including a database time zone other than UTC - Verifying with the repository's own checks, before and after - Handing Prisma 8 details to the `prisma-8` skill that ships in `@prisma/orm-postgres` (`npx prisma skills sync`) @@ -148,6 +146,7 @@ Deploy and operate apps on Prisma Compute with the Prisma 8 CLI. Every app deplo **Use when:** - Deploying a new or existing app to Prisma Compute - Porting a project from the removed `@prisma/cli app deploy`, `prisma.compute.ts`, or `compute:deploy` flow +- Deploying an existing Prisma 8 app, or finishing the Console's "Set up Prisma Cloud deploys" pull request - Setting up preview stages, deploy on push, or CI deploys - Reading service logs, promoting, or rolling back versions - Managing environment variables, custom domains, databases, and buckets for a Compute project @@ -224,7 +223,7 @@ The existing `prisma-cli`, `prisma-client-api`, driver adapter, and earlier-vers The `prisma-compute` skill covers the Composer-based deploy flow of the Prisma 8 CLI. For API details it defers to the version-matched `prisma-platform-core-concepts` and `prisma-composer-core-concepts` skills, which `prisma skills sync` installs from the `prisma` and `@prisma/composer` packages. -If you're upgrading from Prisma 6, use the `prisma-upgrade-v7` skill for migration-specific guidance. +To move a PostgreSQL app from Prisma 6 or 7 to Prisma 8, use `prisma-postgres-upgrade`. The `prisma-upgrade-v7` skill is for apps moving from Prisma 6 to 7 and staying there. ## Contributing diff --git a/prisma-compute/SKILL.md b/prisma-compute/SKILL.md index 79c7fe5..c7f7d04 100644 --- a/prisma-compute/SKILL.md +++ b/prisma-compute/SKILL.md @@ -4,7 +4,7 @@ description: Deploy and operate apps on Prisma Compute with the Prisma 8 CLI. Us license: MIT metadata: author: prisma - version: "2.0.0" + version: "2.1.0" --- # Prisma Compute @@ -52,6 +52,7 @@ A repository with `prisma.compute.ts` or a `compute:deploy` script was set up fo ## When to Apply - Deploying a new or existing app to Prisma Compute +- Finishing the Console's **Set up Prisma Cloud deploys** pull request (`prisma-cloud/setup`) - Porting a project that uses `prisma.compute.ts`, `compute:deploy`, or `@prisma/cli app deploy` - Setting up preview stages, deploy on push, or CI deploys - Reading service logs, listing versions, promoting, or rolling back @@ -104,6 +105,7 @@ A repository with `prisma.compute.ts` or a `compute:deploy` script was set up fo - `deploy-auth` - On a workstation the user runs `npx prisma auth login` (browser). In CI set `PRISMA_SERVICE_TOKEN` and `PRISMA_WORKSPACE_ID`. Check `npx prisma auth whoami --json` (`envelope.result.authenticated`, `envelope.result.workspace`) before deploying. - `deploy-link-after` - `deploy` finds or creates the project by the root module name (or `--name`) and does not write `.prisma/local.json`. Run `npx prisma project link ` afterwards, or pass `--project`, before `service`, `git`, or `project env` commands. - `deploy-on-push` - Deploy on push needs both `npx prisma git connect` (interactive) and a workflow running `prisma/cloud-deploy-action@v1`. Connecting alone deploys nothing. +- `deploy-existing-app` - An existing server built with `tsc` deploys through `module.mjs` and `src/service.mts`, takes its client from `service.load().db.client` (`DATABASE_URL` is the placeholder `-` on Compute), and ships `views/`, `public/` and other runtime files inside `dist/`. The Console's setup pull request gets some of this wrong. See [`deploy-existing-app.md`](references/deploy-existing-app.md); a Prisma 6 or 7 app upgrades with `prisma-postgres-upgrade` first. - `deploy-verify-url` - Take each service URL from the deploy output (`--json` result or `--report `) and request it. ### 5. Operations (HIGH) @@ -129,7 +131,7 @@ A repository with `prisma.compute.ts` or a `compute:deploy` script was set up fo ## Preferred Workflow 1. Inspect `package.json` (is `prisma` 8.x a dev dependency, are `@prisma/composer` and `@prisma/composer-prisma-cloud` installed?), `module.ts`, `prisma.config.ts`, the build script, and leftovers from the removed flow (`prisma.compute.ts`, `compute:deploy`). -2. Install what is missing and sync the package skills: +2. Install what is missing and sync the package skills. In an existing project, pin the Composer packages with `--save-exact` to the version that matches the installed `prisma` and `@prisma/orm-postgres` (see [`deploy-existing-app.md`](references/deploy-existing-app.md)); unpinned installs take the latest release, which may not work with them: ```bash npm install @prisma/composer @prisma/composer-prisma-cloud npm install -D prisma @@ -160,6 +162,7 @@ A repository with `prisma.compute.ts` or a `compute:deploy` script was set up fo - [`runtime-requirements.md`](references/runtime-requirements.md): Bun, host and port, 60-second first byte, sleep, keep-awake, regions - [`deploy-cli-and-ci.md`](references/deploy-cli-and-ci.md): `prisma deploy`, stages, credentials, output, CI, teardown - [`deploy-on-push.md`](references/deploy-on-push.md): GitHub connection and the `prisma/cloud-deploy-action` workflow +- [`deploy-existing-app.md`](references/deploy-existing-app.md): an existing `tsc` server, the Console's setup pull request and its fixes, and the same files without one - [`ops-services-and-config.md`](references/ops-services-and-config.md): services, versions, logs, domains, env vars, databases, buckets - [`debug-deploy-failures.md`](references/debug-deploy-failures.md): symptoms, causes, and fixes - [`automation-create-prisma.md`](references/automation-create-prisma.md): scaffolding a new Composer app diff --git a/prisma-compute/references/app-composer-setup.md b/prisma-compute/references/app-composer-setup.md index fc3c731..037c184 100644 --- a/prisma-compute/references/app-composer-setup.md +++ b/prisma-compute/references/app-composer-setup.md @@ -12,7 +12,7 @@ CRITICAL ## Requirements -- Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer (`engines.node` is `^22.18.0 || ^24.11.0 || >=26.0.0` since Composer 0.30.0). Composer loads the `.ts` entry directly; older versions stop at `ERR_UNKNOWN_FILE_EXTENSION`. +- Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer (`engines.node` is `^22.18.0 || ^24.11.0 || >=26.0.0` since Composer 0.30.0). Composer loads the `.ts` entry directly; older versions stop at `ERR_UNKNOWN_FILE_EXTENSION`. `prisma dev` needs 24.11 or newer: on Node.js 22 it stops with `alchemy: node 22.x is not supported`. - Bun. Deployed services run on Bun, and `bun build --target=bun` is the simplest way to produce the single-file entry a service needs. - The packages: diff --git a/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md b/prisma-compute/references/deploy-existing-app.md similarity index 72% rename from prisma-postgres-upgrade/references/compute-setup-pr-fixes.md rename to prisma-compute/references/deploy-existing-app.md index b4b1313..c553259 100644 --- a/prisma-postgres-upgrade/references/compute-setup-pr-fixes.md +++ b/prisma-compute/references/deploy-existing-app.md @@ -1,7 +1,7 @@ -# compute-setup-pr-fixes +# deploy-existing-app -The Console's setup pull request needs these edits before a `tsc`-built app deploys and works. -Without a setup pull request, write the same files by hand. +Deploy an existing Prisma 8 server built with `tsc` on Compute: finish the Console's setup pull +request, or write the same files without one. ## Priority @@ -13,11 +13,22 @@ On Compute, `DATABASE_URL` is a reserved variable holding the placeholder `-`. A reading it deploys, then fails every query with `P1001` and `host: "base"`. And only the build output (`dist/`) ships, so anything the server loads from outside it is missing at runtime. +The app must be on Prisma 8 first. A Prisma ORM 6 or 7 app upgrades with the +`prisma-postgres-upgrade` skill, then comes back here. + Fixes 1 to 3 and 5 work around current gaps in the setup pull request, which the Console is fixing. Read what the pull request already contains first, and only change what it gets wrong. -For deploy operations beyond these fixes, follow the `prisma-compute` skill. It and the synced -Composer skill show `module.ts`; this skill uses `module.mjs`, because a `tsc` app's service is -loaded from `dist/`. + +A `tsc` app loads its service from `dist/`, so it uses `module.mjs` and `src/service.mts` +rather than the `module.ts` and `service.ts` the rest of this skill shows, and deploys with +`dependencies: "external"` instead of a `bun build` bundle. + +## Versions + +Install the Composer packages with `--save-exact` at the version that matches the installed +`@prisma/orm-postgres` (today `0.34.0` for `8.0.0-rc.20`), or the versions the setup pull request +wrote. The latest Composer release does not work with an older `@prisma/orm-postgres`. Use +Node.js 24.11 or newer locally: `prisma dev` refuses Node.js 22. ## What the setup pull request adds @@ -29,10 +40,11 @@ the Composer packages. It keeps the `prisma` and `@prisma/orm-postgres` versions ## Without a setup pull request -When the user has not connected the repository yet, write these, then apply fixes 1 to 6: +When the user has not connected the repository in the Console, write these, then apply fixes 1 +to 6. Connecting it later (Console, or the interactive `npx prisma git connect`) opens a setup +pull request; reconcile it with these files. -- Install `@prisma/composer` and `@prisma/composer-prisma-cloud` at the pinned version, with - `--save-exact`. +- Install `@prisma/composer` and `@prisma/composer-prisma-cloud` at the version above. - Add to `prisma.config.ts`: ```typescript @@ -43,6 +55,8 @@ When the user has not connected the repository yet, write these, then apply fixe composer: composer({ extensions: [prismaCloud(), nodeBuild()], state: prismaState() }), ``` + Leave the region for the user (`prismaCloud({ region })` or `PRISMA_REGION`); see + `app-region`. - `module.mjs`, which provisions the database from the same contract the service uses: ```javascript @@ -56,8 +70,8 @@ When the user has not connected the repository yet, write these, then apply fixe }); ``` -- `.github/workflows/prisma-deploy.yml` from the `prisma-platform-core-concepts` skill, with - `module: module.mjs` added to the `prisma/cloud-deploy-action` inputs. The action looks for +- `.github/workflows/prisma-deploy.yml` from [`deploy-on-push.md`](deploy-on-push.md), with + `module: module.mjs` in the `prisma/cloud-deploy-action` inputs. The action looks for `module.ts` by default. - `.prisma/`, `.prisma-composer/` and `.alchemy/` in `.gitignore`. @@ -100,23 +114,11 @@ When the user has not connected the repository yet, write these, then apply fixe - Listen on `service.port()` and `"0.0.0.0"`, not `process.env.PORT`. - Outside a Composer run, `service.load()` throws `missing required config param "url"`. So `npm start`, a `tsx` dev script and any `Procfile` stop working. Run locally with - `npm run build && npx prisma dev module.mjs` (Node.js 24.11+), and make that the `dev` - script. It starts a local Prisma Postgres, applies `migrations/app/`, and prints - `dev: ready`. That database is empty. - - A seed script must not import `db.ts`. Give it its own client, and seed with - `DATABASE_URL="$(npx prisma dev url database)" npx tsx prisma/seed.ts`: - - ```typescript - import postgres from "@prisma/orm-postgres/runtime"; - import { contractFromJson } from "@prisma/orm-postgres/static"; - import type { Contract } from "../src/prisma/contract.js"; - import contractJson from "../src/prisma/contract.json"; // no import attribute in a CommonJS .ts file - - const db = postgres({ contract: contractFromJson(contractJson), url: process.env["DATABASE_URL"]! }); - ``` - - The `with { type: "json" }` attribute the `prisma-8` skill requires is only valid in `.mts` - files such as `service.mts`; in a CommonJS `.ts` file it fails with TS2856. + `npm run build && npx prisma dev module.mjs`, and make that the `dev` script. It starts a + local Prisma Postgres, applies `migrations/app/`, and prints `dev: ready`. That database is + empty. + - A seed script must not import `db.ts`. Keep its own `postgres({ contract, url })` client, + and seed with `DATABASE_URL="$(npx prisma dev url database)" npx tsx prisma/seed.ts`. 5. **Ship runtime files.** Copy `views/`, `public/` or similar into `dist/` in `build` (`tsc && cp -R views public dist/`) and resolve them from `__dirname`. Otherwise every rendered page fails with `Failed to lookup view`. @@ -153,5 +155,5 @@ export const db = service.load().db.client; ## References -- [Guide, step 6](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#6-deploy-on-prisma-compute) -- `prisma-compute` skill, and the synced `prisma-composer-core-concepts` skill +- [Deploy an existing app on Prisma Compute](https://www.prisma.io/docs/guides/compute/deploy-existing-app) +- The synced `prisma-composer-core-concepts` skill diff --git a/prisma-orm-setup/SKILL.md b/prisma-orm-setup/SKILL.md index 6c9f9be..141f011 100644 --- a/prisma-orm-setup/SKILL.md +++ b/prisma-orm-setup/SKILL.md @@ -29,7 +29,7 @@ Use an existing database when supplied. Load `prisma-postgres-setup` only when P ## 2. Handle requested major upgrades separately -When the user requests a major upgrade, load a workflow that supports the source version and provider. For PostgreSQL 7-to-8, use the [Prisma migration guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql); for PostgreSQL 6 or 7 to 8 in one pass, ending on Prisma Compute, use [prisma-postgres-upgrade](../prisma-postgres-upgrade/SKILL.md); for MongoDB 6-to-8, use [prisma-mongodb-upgrade](../prisma-mongodb-upgrade/SKILL.md). Other providers need an explicitly supported migration path. `prisma-upgrade-v7` covers **6 to 7**; the package-owned `prisma-8` upgrade reference covers updates within 8. +When the user requests a major upgrade, load a workflow that supports the source version and provider. For PostgreSQL 6 or 7 to 8 in one pass, use [prisma-postgres-upgrade](../prisma-postgres-upgrade/SKILL.md); for PostgreSQL 7-to-8 one route at a time, use the [route-by-route guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-incremental); for MongoDB 6-to-8, use [prisma-mongodb-upgrade](../prisma-mongodb-upgrade/SKILL.md). Other providers need an explicitly supported migration path. `prisma-upgrade-v7` covers **6 to 7**; the package-owned `prisma-8` upgrade reference covers updates within 8. ## 3. Bootstrap a new Prisma 8 application diff --git a/prisma-postgres-upgrade/SKILL.md b/prisma-postgres-upgrade/SKILL.md index a19c270..de0fde3 100644 --- a/prisma-postgres-upgrade/SKILL.md +++ b/prisma-postgres-upgrade/SKILL.md @@ -1,73 +1,72 @@ --- name: prisma-postgres-upgrade -description: Upgrade a PostgreSQL app from Prisma ORM 6 or 7 straight to Prisma 8 and deploy it on Prisma Compute, keeping the existing schema.prisma, database and data. Use when a Postgres project on Prisma 6 or 7 wants Prisma 8, Prisma Compute, or the Console's "Set up Prisma Cloud deploys" pull request. Triggers on "upgrade prisma 6 to 8", "upgrade prisma 7 to 8", "upgrade to prisma 8 postgres", "move my prisma app to prisma compute", "prisma7Schema", "migrations/app", "service.load().db.client", "@prisma/client did not initialize yet". +description: Upgrade a PostgreSQL app from Prisma ORM 6 or 7 straight to Prisma 8 in one pass, keeping the existing schema.prisma, database and data. Use when a Postgres project on Prisma 6 or 7 wants Prisma 8, including before deploying it on Prisma Compute, which runs only Prisma 8. Triggers on "upgrade prisma 6 to 8", "upgrade prisma 7 to 8", "upgrade to prisma 8 postgres", "prisma7Schema", "migrations/app", "move off @prisma/client", "Console says move to Prisma 8". license: MIT metadata: author: prisma - version: "1.1.0" + version: "2.0.0" --- -# Prisma Postgres Upgrade: Prisma ORM 6 or 7 to Prisma 8 on Compute +# Prisma Postgres Upgrade: Prisma ORM 6 or 7 to Prisma 8 -Move a Node.js server on Prisma ORM 6 or 7 and PostgreSQL to Prisma 8 in one pass, then deploy -it on Prisma Compute. The schema, the database and its data stay. +Move a Node.js server on Prisma ORM 6 or 7 and PostgreSQL to Prisma 8 in one pass. The schema, +the database and its data stay, and the app keeps running wherever it runs today. -This skill is the bridge. It covers only what is specific to leaving Prisma ORM 6 or 7 and -landing on Compute. Prisma 8 itself (the contract, migrations, queries, errors) is covered by the -`prisma-8` skill that ships inside `@prisma/orm-postgres`, which step 2 installs. Follow it for -anything Prisma 8 specific; it matches the installed version, and this skill does not. +This skill is the bridge. It covers only what is specific to leaving Prisma ORM 6 or 7. Prisma 8 +itself (the contract, migrations, queries, errors) is covered by the `prisma-8` skill that ships +inside `@prisma/orm-postgres`, which step 2 installs. Follow it for anything Prisma 8 specific; +it matches the installed version, and this skill does not. `prisma-8` says it does not apply to a project that still has `schema.prisma` and -`@prisma/client`. That is expected mid-upgrade: this skill keeps both until step 6, and +`@prisma/client`. That is expected mid-upgrade: this skill keeps both until step 5, and `prisma7Schema(...)` reads that `schema.prisma`. Use `prisma-8` for the Prisma 8 side anyway. -The [Prisma ORM 6 or 7 to 8 on Prisma Compute (PostgreSQL) guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute) +The [Prisma ORM 6 or 7 to 8 (PostgreSQL) guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql) is the source of truth for the steps. **Never do either of these:** - Never route a PostgreSQL Prisma ORM 6 app through Prisma ORM 7 first. Prisma 8 reads a Prisma ORM 6 `schema.prisma` unchanged, so `prisma-upgrade-v7` is only for apps that stay on 7. -- Never install `prisma@latest`, `@prisma/orm-postgres@latest` or the latest Composer packages - while the Console's Compute setup pins versions: the latest set does not work together, so the - deploy fails. +- Never install `prisma@latest` or `@prisma/orm-postgres@latest` when the app will deploy on + Prisma Compute: the latest pair does not work with the Composer version the Console's setup + installs, so the deploy fails. ## When to Apply -- A PostgreSQL project on Prisma ORM 6 or 7 asks to upgrade to Prisma 8 -- The user wants to deploy a Prisma ORM 6 or 7 app on Prisma Compute -- The Console blocked setup with "move to Prisma ORM 8", or opened **Set up Prisma Cloud - deploys** on `prisma-cloud/setup` +- A PostgreSQL project on Prisma ORM 6 or 7 asks to upgrade to Prisma 8 in one pass +- A Prisma ORM 6 or 7 app wants to deploy on Prisma Compute, or the Console blocked its setup + with "move to Prisma 8": upgrade here, then deploy with `prisma-compute` -Not for: MongoDB (use `prisma-mongodb-upgrade`), a Prisma ORM 7 app moving one route at a time -beside Prisma 8 (follow the [side-by-side guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql)), +Not for: deploying on Compute (use `prisma-compute`, `deploy-existing-app`), MongoDB (use +`prisma-mongodb-upgrade`), a Prisma ORM 7 app moving one route at a time beside Prisma 8 +(follow the [route-by-route guide](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-incremental)), a project already on Prisma 8 (use the synced `prisma-8` skill), or a new project (use `prisma-orm-setup`). ## Versions -Install exactly the versions the Console's setup uses, with `--save-exact`: today `prisma` -`8.0.0-rc.27` (dev dependency), `@prisma/orm-postgres` `8.0.0-rc.20`, and in step 5 -`@prisma/composer` and `@prisma/composer-prisma-cloud` `0.34.0` (the release that peers on -`@prisma/orm-postgres` `8.0.0-rc.20`). If the repository already has a setup pull request, or -the Console's message names other versions, use those. Use Node.js 24.11 or newer; `prisma dev` -needs it. +Install exact versions with `--save-exact`. For an app headed to Compute, use the versions the +Console's setup uses: today `prisma` `8.0.0-rc.27` (dev dependency) and `@prisma/orm-postgres` +`8.0.0-rc.20`. If the Console's message or an existing setup pull request names other versions, +use those. Use Node.js 24.11 or newer if the app will run under `prisma dev`. ## The path | Step | What happens | Where the detail is | |------|--------------|---------------------| | 0 | Run the repo's own checks and record the results | `verify-upgrade-checklist` | -| 1 | Remove `prisma`, install the versions above | this file | +| 1 | Remove `prisma`, install the versions above, remove `prisma generate` from scripts | this file | | 2 | Write the Prisma 8 `prisma.config.ts`, then `npx prisma skills sync` | `adopt-schema-and-migrations` | | 3 | `contract emit`, `db sign`, baseline migration, retire `prisma/migrations` | `adopt-schema-and-migrations` | -| 4 | Rewrite every query for the Prisma 8 client | `client-api-mapping` | -| 5 | Compute: the Console setup pull request and its fixes, or the same files written by hand | `compute-setup-pr-fixes` | -| 6 | Remove `@prisma/client`, the adapter and the generated client | this file | -| 7 | Run the same checks again and start the app | `verify-upgrade-checklist` | +| 4 | Create the Prisma 8 client and rewrite every query | `client-api-mapping` | +| 5 | Remove `@prisma/client`, the adapter and the generated client | this file | +| 6 | Run the same checks again and start the app | `verify-upgrade-checklist` | -Step 1 removes the only command that generated the old client. It keeps working locally, but a -fresh install (CI, a new clone) has none, so finish step 4 before pushing to a branch CI builds. +In step 1, also remove `prisma generate` from `build`, `postinstall` and any other script: the +Prisma 8 CLI has no `generate` and fails with `CLI.UNKNOWN_COMMAND`. Step 1 removes the only +command that generated the old client. It keeps working locally, but a fresh install (CI, a new +clone) has none, so finish step 4 before pushing to a branch CI builds. The sync in step 2 installs `prisma-8`, `prisma-platform-core-concepts` and `prisma-composer-core-concepts` in one go, because the CLI depends on Composer. It writes them @@ -75,39 +74,43 @@ for every agent it knows unless `skills.agents` in the config lists only the one uses. In a Prisma ORM 7 app, replace the old `prisma.config.ts` before syncing: the sync fails with `CLI.CONFIG_UNREADABLE` while the old one is in place. -In step 6, `npm uninstall @prisma/client` leaves the generated client behind; delete +Commit what Prisma 8 writes: `src/prisma/contract.json`, `src/prisma/contract.d.ts` and the +whole `migrations/` folder. There is no generate step to recreate them in CI. + +In step 5, `npm uninstall @prisma/client` leaves the generated client behind; delete `node_modules/.prisma` too, then run a fresh install and the checks so nothing still imports it. +## Deploying on Compute + +When the upgrade is done and the checks pass, deploy with the `prisma-compute` skill +(`references/deploy-existing-app.md`). Compute runs only Prisma 8, so the upgrade has to be +finished first. + ## What the user does The agent cannot do these; stop and ask: -- Connect the repository in the [Prisma Console](https://console.prisma.io), which opens the - setup pull request, or run `npx prisma git connect`, which is interactive. -- Choose the region for the first deploy. It cannot be changed later. -- Provide values for the environment variables the app reads (`prisma project env add`). -- Approve the push to `prisma-cloud/setup`. Every push deploys a preview; merging deploys - production. - Decide what to do about a database time zone other than UTC (see `client-api-mapping`). +- Sign every other existing database (staging, production) with `npx prisma db sign`. The agent + has only the local one. +- Review the change before it ships, especially when the repository has no tests. ## Reference files | Reference | What it covers | |-----------|----------------| | `references/adopt-schema-and-migrations.md` | The first `prisma.config.ts`, keeping `schema.prisma` as the contract, CommonJS `tsconfig`, the baseline, retiring the old migration setup | -| `references/client-api-mapping.md` | Prisma ORM 6/7 calls to Prisma 8, and the differences that break rewrites | -| `references/compute-setup-pr-fixes.md` | What the Console's setup pull request gets wrong, and the files to write without one | +| `references/client-api-mapping.md` | The Prisma 8 client, Prisma ORM 6/7 calls to Prisma 8, and the differences that break rewrites | | `references/verify-upgrade-checklist.md` | Proving the upgrade with the repo's own checks | ## Verified against A Prisma ORM 6.19 app (Express 4, EJS, `tsc`, CommonJS) on PostgreSQL 18, with `prisma` -8.0.0-rc.27, `@prisma/orm-postgres` 8.0.0-rc.20 and Composer 0.34.0. An agent with only this -skill upgraded it with no setup pull request: pages and API output were identical before and -after against the same database, and `npx prisma dev module.mjs` reached `dev: ready`. The -Console flow and the Compute runtime were not deployed end to end. +8.0.0-rc.27 and `@prisma/orm-postgres` 8.0.0-rc.20. Two agents with no context and only these +skills upgraded it: pages and API output were identical before and after against the same +database, and `prisma db verify` passed. ## Hand-off rule Once the app runs on Prisma 8, use the synced `prisma-8` skill for day-to-day work and -`prisma-compute` for deploy operations. This skill covers the upgrade only. +`prisma-compute` to deploy and operate it on Compute. This skill covers the upgrade only. diff --git a/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md b/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md index ca3dd69..a5fc8d9 100644 --- a/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md +++ b/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md @@ -45,13 +45,13 @@ Then run `npx prisma skills sync`. Step 5 adds a `composer` section to the same - **Sign the existing database, then plan the baseline:** `npx prisma contract emit`, `npx prisma db sign`, `npx prisma migration plan`. The first plan on a signed database writes `migrations/app/_baseline/` and ignores `--name`; `db verify` then passes and - `db migrate` has nothing to apply. Sign every other existing database (staging) too; databases - the Compute deploy creates do not need it. + `db migrate` has nothing to apply, whatever its hint says. Commit `migrations/`. Sign every + other existing database (staging) too; databases the Compute deploy creates do not need it. - **Retire the old migration setup:** delete `prisma/migrations` (with `migration_lock.toml`), remove `prisma generate`, `prisma migrate *` and `prisma db seed` from scripts (including `postinstall`), and remove the `"prisma": { "seed": ... }` key. Prisma 8 has no `generate` or - seed command; keep the seed script and run it with `tsx` (see `compute-setup-pr-fixes.md`, - fix 4). The `_prisma_migrations` table stays in the database; dropping it is the user's call. + seed command; keep the seed script and run it with `tsx` (`client-api-mapping.md` shows its + client). The `_prisma_migrations` table stays in the database; dropping it is the user's call. For `contract emit`, `db sign`, the migration commands and every later schema change, follow the synced `prisma-8` skill (`references/contract.md`, `references/migration-model.md`, @@ -74,5 +74,5 @@ rm -r prisma/migrations ## References -- [Guide, steps 2 and 3](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#2-create-the-contract-from-your-schema) +- [Guide, steps 2 and 3](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql#2-create-the-contract-from-your-schema) - The synced `prisma-8` skill, authoritative for the installed version diff --git a/prisma-postgres-upgrade/references/client-api-mapping.md b/prisma-postgres-upgrade/references/client-api-mapping.md index 087584f..75175c8 100644 --- a/prisma-postgres-upgrade/references/client-api-mapping.md +++ b/prisma-postgres-upgrade/references/client-api-mapping.md @@ -1,6 +1,6 @@ # client-api-mapping -Map each Prisma ORM 6 or 7 call to the Prisma 8 client; five differences break most rewrites. +Create the Prisma 8 client, then map each Prisma ORM 6 or 7 call to it; five differences break most rewrites. ## Priority @@ -12,11 +12,28 @@ The Prisma 8 client chains calls instead of taking one options object, and a sch through `prisma7Schema(...)` changes a few lookups and types. Some of these compile and then fail at runtime or write wrong data. +## The client + +One client for the app and the seed script, reading the same `DATABASE_URL` as before: + +```typescript +// src/db.ts +import postgres from "@prisma/orm-postgres/runtime"; +import { contractFromJson } from "@prisma/orm-postgres/static"; +import type { Contract } from "./prisma/contract.js"; +import contractJson from "./prisma/contract.json"; + +export const db = postgres({ contract: contractFromJson(contractJson), url: process.env["DATABASE_URL"]! }); +``` + +In a CommonJS `.ts` file, import the JSON without the `with { type: "json" }` attribute the +`prisma-8` skill shows: the attribute fails there with TS2856 and is only valid in `.mts` files. +On Compute, `prisma-compute` replaces this client with `service.load().db.client`. + ## Old call to new call -Queries start at `db.orm.public.`. For the client itself and anything not listed here, -follow the synced `prisma-8` skill (`references/queries.md`, `references/runtime.md`); on -Compute the client comes from `service.load().db.client` (see `compute-setup-pr-fixes.md`). +Queries start at `db.orm.public.`. For anything not listed here, follow the synced +`prisma-8` skill (`references/queries.md`, `references/runtime.md`). | Prisma ORM 6 / 7 | Prisma 8 | |------------------|----------| @@ -27,8 +44,11 @@ Compute the client comes from `service.load().db.client` (see `compute-setup-pr- | `findUnique` on an `@unique` or `@@unique` field | `.where({...}).first()` | | `create({ data: { ..., votes: { create: {...} } } })` | `.create({ ..., votes: (v) => v.create([{...}]) })` | | `deleteMany({ where })` then `.count` | `.where({...}).deleteAndCount()` | +| `deleteMany()` with no filter (seeds, tests) | `.where((m) => m.id.isNotNull()).deleteAll()`: writes need a filter | +| `createMany({ data: [...] })` | `.createAll([...])` | | `count({ where })` | `.where({...}).aggregate((a) => ({ total: a.count() }))` | | `Object.values(PostStatus)` from `@prisma/client` | `db.nativeEnums.public.PostStatus.values` | +| ``$queryRaw`SELECT 1` `` (health checks) | ``db.execute(db.raw.sql`SELECT 1`.affectedCount().build())`` | What has no Prisma 8 form yet, such as `increment` in an update, is listed in [Coming from Prisma ORM 7](https://www.prisma.io/docs/orm/coming-from-prisma-orm-7#queries). @@ -66,5 +86,5 @@ const post = await db.orm.public.Post.include("votes", (v) => v.count()).first({ ## References -- [Guide, step 5](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#5-rewrite-your-queries) +- [Guide, step 5](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql#5-rewrite-your-queries) - The synced `prisma-8` skill, authoritative for the installed client diff --git a/prisma-postgres-upgrade/references/verify-upgrade-checklist.md b/prisma-postgres-upgrade/references/verify-upgrade-checklist.md index 9c04666..5d2dc57 100644 --- a/prisma-postgres-upgrade/references/verify-upgrade-checklist.md +++ b/prisma-postgres-upgrade/references/verify-upgrade-checklist.md @@ -17,10 +17,13 @@ change. Checks the agent writes for itself prove only what the agent expected. - **Use what the repo has.** Find the type check, build, lint and test scripts in `package.json` and CI config, and run exactly those. - **Same commands before and after.** Record each command and its result before step 1. Run - the identical commands after step 6. A check that was already failing before is reported as + the identical commands after step 5. A check that was already failing before is reported as such, not fixed silently. -- **Do not invent checks.** Do not write new tests, smoke scripts or per-route requests to - stand in for missing ones, and do not change existing tests to make them pass. +- **Do not invent checks.** Do not write or commit new tests or smoke scripts to stand in for + missing ones, and do not change existing tests to make them pass. +- **Comparing pages by hand is fine, and it is not a test.** Requesting a few read-only pages + before and after, against the same database, catches templates `tsc` never checks. Report it + as a manual comparison, never as test coverage. - **No tests? Say so.** If the repository has no tests, tell the user plainly that the upgrade is verified only by type check, build and the app starting, and leave the change for them to review before it ships. @@ -32,13 +35,11 @@ change. Checks the agent writes for itself prove only what the agent expected. Record `SHOW timezone` on the database. 2. **After step 4:** same commands, against the same local database. No file imports `@prisma/client` or the generated client. -3. **After step 5:** `npm run build`, then `npx prisma dev module.mjs` reaches `dev: ready`. -4. **After step 6:** a fresh install, then the same commands as the baseline, plus - `npx prisma db verify` against the signed database. `npm start` now fails outside Composer - by design (`compute-setup-pr-fixes.md`, fix 4), so start the app with `prisma dev` - instead and report that the start command changed. -5. **Report:** each command, before and after, pass or fail. List what was not verified: the - Console flow, the preview deploy, and any behavior the tests do not cover, including the rc.20 +3. **After step 5:** a fresh install, then the same commands as the baseline, plus + `npx prisma db verify` against the signed database. Start the app with its own start command + again. +4. **Report:** each command, before and after, pass or fail. List what was not verified, + including any behavior the tests do not cover, including the rc.20 `DateTime` and `now()` notes in `client-api-mapping.md`. If the database's time zone is not UTC, say so first: new rows store a different time than before. @@ -52,9 +53,9 @@ change. Checks the agent writes for itself prove only what the agent expected. ```text Before: tsc ok, build ok, npm test 42 passed. After: tsc ok, build ok, npm test 42 passed, -app starts. The preview deploy is not verified. +app starts. Not verified: behavior the tests do not cover. ``` ## References -- [Guide, steps 5.3 and 7](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql-compute#53-run-the-app-locally) +- [Guide, step 5.3](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql#53-run-the-app-locally) From 0d6fde5fb77c242826bdb2a88256fd9b4277e36b Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 9 Nov 2026 12:23:01 +0100 Subject: [PATCH 5/5] fix(prisma-postgres-upgrade): the composer section comes from the Compute deploy, not step 5 Step 5 of this skill removes @prisma/client. The composer section is added when the app deploys on Compute, which prisma-compute owns since the split. Co-Authored-By: Claude Fable 5.1 --- .../references/adopt-schema-and-migrations.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md b/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md index a5fc8d9..4ff4840 100644 --- a/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md +++ b/prisma-postgres-upgrade/references/adopt-schema-and-migrations.md @@ -30,7 +30,8 @@ export default definePrismaConfig({ }); ``` -Then run `npx prisma skills sync`. Step 5 adds a `composer` section to the same config. +Then run `npx prisma skills sync`. Deploying on Compute later adds a `composer` section to the same +config; that belongs to the `prisma-compute` skill, not to this upgrade. ## What is specific to coming from 6 or 7