Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ 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 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
- A Prisma ORM 6 or 7 app has to reach Prisma 8 before it can deploy on Prisma Compute

**Topics covered:**
- 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/`
- 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`)

---

### prisma-client-api

Comprehensive Prisma Client API reference.
Expand Down Expand Up @@ -128,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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -203,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

Expand Down
7 changes: 5 additions & 2 deletions prisma-compute/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <app-name>` 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 <path>`) and request it.

### 5. Operations (HIGH)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion prisma-compute/references/app-composer-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
159 changes: 159 additions & 0 deletions prisma-compute/references/deploy-existing-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# deploy-existing-app

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

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.

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.

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

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.

## Without a setup pull request

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 version above.
- 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() }),
```

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
import { module } from "@prisma/composer";
import { postgres } from "@prisma/composer-prisma-cloud/orm";
import web, { data } from "./dist/service.mjs";

export default module("<app name>", ({ provision }) => {
const database = provision(postgres({ name: "database", contract: data, config: "prisma.config.ts" }));
provision(web, { deps: { db: database } });
});
```

- `.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`.

## 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 const data = dataContract<Contract>(contractJson);

export default compute({
name: "<keep the name the setup wrote>",
deps: { db: postgres(data) },
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, and run under Composer.**

```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.
- 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`, 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`.
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.

## Bad

```typescript
export const db = postgres({ contract, url: process.env["DATABASE_URL"]! }); // "-" on Compute
```

## Good

```typescript
export const db = service.load().db.client;
```

## References

- [Deploy an existing app on Prisma Compute](https://www.prisma.io/docs/guides/compute/deploy-existing-app)
- The synced `prisma-composer-core-concepts` skill
2 changes: 1 addition & 1 deletion prisma-orm-setup/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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

Expand Down
Loading
Loading