# Prisma 8 — Quickstart (Adoption) > **Edit your data contract. Prisma handles the rest.** This skill takes the user from zero (or near-zero) to a first working query against Prisma 8. Fresh setup follows **connect → write → read** before extending the starter schema. Adoption of an existing database starts with a read; test writes require a task that includes writes. - **First-touch orientation** — the user has arrived at a Prisma 8 project for the first time (a scaffold tool like `npx createprisma` dropped them in, they cloned a teammate's repo, or they ran `prisma orm init` themselves and now want to make their first move) and they're asking *"what can I do with Prisma 8?"*, *"where do I start?"*, or *"what's next?"*. Anchor them on the contract, connect to the intended database, and verify a query: a read for an existing database, or a write/read round-trip for fresh setup. - **Greenfield** — new project, fresh database. User runs `prisma orm init` themselves. `init` seeds a starter contract with a sample model, so the path joins the first-touch orientation arc as soon as the database is initialised. - **Brownfield-DB** — existing PostgreSQL database, no contract yet. Infer the contract from the database with `contract infer`, sign the database with `db sign`, then write queries against one of the existing tables. Other built-in targets require a hand-authored or reusable contract; see the target guidance at the start of the brownfield workflow below. This skill does **not** cover migrating from another ORM (Drizzle, Prisma 6/7, Sequelize, TypeORM, Kysely, Knex, raw drivers). Those are separately-installable skills. ## When to Use - User asks *"what can I do with Prisma 8?"*, *"what can I do next with Prisma?"*, *"where do I start?"*, *"what should I do first?"* — and a Prisma 8 project already exists on disk. **First-touch orientation** path below. - User just ran `createprisma` (or equivalent scaffold tool) and is asking what to do next. **First-touch orientation** path. - User is starting a new project and wants to use Prisma 8. **Greenfield** path. - User has an existing PostgreSQL database (no Prisma 8 contract) and wants to introduce Prisma 8. **Brownfield-DB** path. - User typed *"prisma orm init"*, *"get started with Prisma 8"*, *"set up Prisma 8"*, *"how do I scaffold a project"*. **Greenfield** path. - User has an existing database on another engine and no Prisma contract. Follow [Other existing database engines](#other-existing-database-engines), preserving the engine and schema; do not use the PostgreSQL inference workflow. ## When Not to Use - User already has a Prisma 8 project and wants to add a model → `references/contract.md`. - User wants to migrate FROM another ORM → Prisma 8 has no tool for that; see *What Prisma 8 doesn't do yet* below. - User wants to wire `db.ts` in a project that already has a contract → `references/runtime.md`. - User wants to integrate Prisma 8 with a build tool (Vite plugin, Next.js, …) → `references/build.md`. ## Key Concepts - **Contract**: the data model. Authored as `contract.prisma` (PSL, the canonical surface) or `contract.ts` (TypeScript builder). The framework reads it and emits two artefacts: `contract.json` (runtime IR) and `contract.d.ts` (types). - **Target**: the backing store. Today: `postgres` or `mongodb`. Picked at `init` time; baked into the `@prisma/orm-` package the scaffold imports from. - **Authoring mode**: how you write the contract. `psl` (Prisma Schema Language, default) or `typescript` (programmatic builder, optionally paired with the Vite plugin for auto-emit during `vite dev` — see `references/build.md`). - **Database packages.** The scaffold installs one database package for your target: `@prisma/orm-postgres` or `@prisma/orm-mongo`. User code imports from its subpaths: `@prisma/orm-postgres/config`, `@prisma/orm-postgres/runtime`, `@prisma/orm-postgres/static` and `@prisma/orm-postgres/contract-builder`. The database package already contains the wiring of family, target, adapter and driver, so never import from the platform packages directly. See `references/contract.md` for the full list. - **The packages beside it.** The scaffold also installs the platform packages that the database package requires as peer dependencies: `@prisma/orm-framework`, the family, the target and `@prisma/orm-toolchain`. They are from the same release as the database package: one `8.0.0-rc.N` until release 8.0, and from release 8.0 each package's own version in that release. `init` writes these lines for you, together with the other packages the database package requires, such as `temporal-polyfill`. If you install by hand, list every one of them. - **Why the application lists them.** The application must have exactly one copy of each. Prisma does not accept a value that another copy of its own code created, and a package manager takes a peer dependency only from the application's own list. A monorepo whose applications are on different Prisma releases can still get two copies under npm workspaces and under Bun's hoisted linker; keep such applications on one release, or use pnpm, Yarn or Bun's isolated linker. - **Yarn Plug'n'Play.** `prisma orm init` does not support it. With Yarn, set `nodeLinker: node-modules` in `.yarnrc.yml` first. - **`db.ts`**: the runtime entry point. Lives next to the contract source at `src/prisma/db.ts`. Imports the contract artefacts and exports a `db` value the rest of the app uses. - **Contract signature**: a row in the `prisma.signatures` table (Postgres) or a document in the `_prisma_migrations` collection (Mongo) that records the contract hash per contract space. Lets Prisma 8 detect drift between contract and live DB. Created by `db init` (initial setup on an empty database) or `db sign` (adoption of a matching existing database). ### Canonical on-disk layout Every application that consumes Prisma 8 uses the same shape: ```text / ├── prisma.config.ts ← project config at repo root ├── src/ │ └── prisma/ │ ├── contract.prisma ← (or contract.ts) — schema source you author │ ├── contract.json ← emitted by `contract emit` — do not edit │ ├── contract.d.ts ← emitted by `contract emit` — do not edit │ └── db.ts ← runtime entry; the rest of `src/` imports from here └── migrations/ ├── snapshots/ ← content-addressed contract store, shared across spaces │ └── / │ ├── contract.json │ └── contract.d.ts └── app/ ← created on first `migration plan` / `db init` ├── refs/db.json └── _/ ├── migration.json ├── ops.json └── migration.ts ``` Three things to internalise: - **`src/prisma/` is the home for the contract** — source + emitted artefacts + `db.ts` all colocated. The rest of `src/` imports from `./prisma/db` (or `../prisma/db`, depending on file depth). - **`migrations/app/`** — the `app/` segment is the consuming application's space-id. Extensions you depend on get sibling directories under `migrations/` (one per extension contract-space), but you don't write into those — only the `app/` subtree is your migrations. - **`prisma.config.ts` lives at the repo root**, not under `src/`. Every command resolves paths relative to the config's directory. **Contributors building extension packages or aggregate-root monorepo packages use a different layout** — `src/contract.{prisma,ts}` (no `prisma/` subdir) + `migrations/_/` (no `app/` segment). That distinction is intentional; see `references/contract.md` for which path applies to you. `prisma orm init` scaffolds this layout by default: the contract at `src/prisma/contract.prisma` (or `.ts`) and `db.ts` beside it. A project scaffolded by an older init may have a top-level `prisma/` directory instead — read the `contract` path in `prisma.config.ts` rather than assuming either. ## Your first arc — connect, write, read For fresh setup, once the project is scaffolded and the database is reachable, connect, write a row, and read it back against whatever model the contract already declares. Don't extend the starter contract on this first move — do that after the round-trip works. For an existing database, keep its existing contract. If there is no contract and adoption is requested, author or infer one that matches the database using the target-specific workflow below. Confirm a read against an existing model; skip the insert below unless the user's task includes writes. Write the snippet in a fresh file directly under `src/` (e.g. `src/first-arc.ts`) so the relative import resolves to one level deep: ```typescript // src/first-arc.ts import 'dotenv/config'; import { db } from './prisma/db'; // Write a row against the starter model. Adapt the field names to whatever // model your contract source actually declares — read it first. await db.orm.public.User.create({ email: 'alice@example.com' }); // Read it back. const users = await db.orm.public.User.select('id', 'email').all(); console.log(users); ``` If that prints `[{ id: 1, email: 'alice@example.com' }]`, the project is wired end-to-end and the user has crossed from *"I have a project"* to *"I'm building."* `db.orm..` is the default ORM lane — model-shaped, fully typed against the contract, lazily connects to the database on first use (it picks up `DATABASE_URL` from `.env` via the runtime's `dotenv/config`-loaded environment). The deeper `references/queries.md` reference covers the rest of the supported surface (filters, joins, transactions, the SQL builder, raw SQL via `db.raw.sql`, prepared statements) when the user is ready — and names the gaps (TypedSQL is not available). > **SQLite target:** `prisma orm init` scaffolds only `postgres` and `mongodb`; a SQLite project is wired by hand with the `@prisma/orm-sqlite` package (`references/runtime.md` § *Switch between Postgres, SQLite, and Mongo*; `examples/prisma-8-demo-sqlite`). SQLite has no schemas, so that database package exposes the unbound namespace directly — write `db.orm.User` rather than `db.orm.public.User`. > > **Mongo target:** the snippet above is SQL-target shape. On `@prisma/orm-mongo`, `db.orm` is keyed by the collection's storage name (`@@map(...)`, or the lowercased model name if no `@@map`), so the same arc reads `await db.orm.users.create(...)` / `await db.orm.users.select('id', 'email').all()` — not `db.orm.public.User`. Full rule and rewrite recipe in `references/queries.md` § *MongoDB ORM addressing*. **Prerequisites for the arc to work.** All three paths leave these in place by the time you reach the arc: - `prisma.config.ts` exists at the repo root and declares the target + contract source (typically `src/prisma/contract.prisma` or `src/prisma/contract.ts`). - The contract source exists at `src/prisma/contract.{prisma,ts}` (a starter model from `init`, or the inferred contract from `contract infer`, or whatever the bootstrap tool generated). - `src/prisma/db.ts` exists and instantiates the runtime with the emitted contract. - `DATABASE_URL` is set in `.env` (or wherever the runtime's config tells it to look). - The database has been initialised (`db init`) or signed (`db sign`), so its contract signature exists and the schema matches the contract. The workflows below describe how to reach that state. Fresh setup then runs the write/read arc; existing-database adoption verifies a read first. ## Workflow — First-touch orientation Triggers: *"what can I do with Prisma 8?"*, *"what can I do next with Prisma?"*, *"where do I start?"*, *"I just ran createprisma"*, *"what's next?"*, or any close variant — paired with a Prisma 8 project already on disk (scaffolded by `createprisma`, by `prisma orm init`, by a teammate, however). The user's high-level intent is *"I want to be running an application against my database, against this thing called Prisma 8."* Anchor them on the contract and get a query working within their request. For an existing database, begin with a read. A request only to inspect, verify or repair a connection does not authorize adoption, signing, initialization, schema changes or test inserts: follow [connection recovery](database-connection.md), retry the original operation and report remaining findings. Do not continue through setup steps to make those findings disappear. ### Concept — what to communicate first Prisma 8 is contract-first. Everything the framework does — query types, migrations, runtime types, drift detection — flows from a single source of truth: the **contract**. The contract describes the user's application's data model. The framework reads it; the framework derives the rest. Lead with this. The first response to *"what can I do with Prisma 8?"* names the contract path, frames its role in one sentence, and then steers toward getting the user's application running. Don't open with a feature inventory. Don't open with a list of commands. Open with: *"Your contract is at ``. It describes your application — your query types, migrations, and runtime types all flow from it. Let's get you connected to a database so your app can actually run against it."* For fresh setup, the first arc is **connect → write → read**. For an existing database, it is **connect → read**, with writes only when the user's task includes them. The user's win is *I have application code running against my database*. ### Step 1 — Read the project, name the contract Before saying anything specific to the user, read: - `prisma.config.ts` at the repo root — what target (`postgres` / `mongodb`) is wired, what `contract:` path it declares, what extensions are installed. - The contract source the config declares (canonically `src/prisma/contract.prisma` or `src/prisma/contract.ts`; a project scaffolded by an older init may have it at `prisma/contract.{prisma,ts}` instead — check the `contract` field of the config) — what starter models, if any, exist. - `src/prisma/db.ts` (next to the contract) — the runtime entry point. - `.env` / `.env.example` — is `DATABASE_URL` set, or only the example? - Optionally `pnpm prisma db verify` — does the live DB match the contract? (Exit `4` with findings means drift or no contract signature; `2` means it could not run.) Then **say the contract path back to the user, with its role attached**. Something like: *"Your contract is at `src/prisma/contract.prisma`, and it currently declares a `User` model. The contract describes your app — every query type, migration, and runtime type the framework gives you flows from this file. Let's get your app connected to a database next."* The exact wording is up to the agent; what matters is that the user leaves the first response knowing *where the contract is* and *that it is the source of truth*. ### Step 2 — Get the user's app connected and round-tripping The motivation is *"so your app can actually run against your database"*, not *"so the prerequisite checklist passes"*. The mechanics depend on what's already in place from Step 1: - **Everything already wired.** Read an existing model first. Use the write/read snippet above only for fresh setup or a task that includes writes; adapt it to the current contract. - **`DATABASE_URL` not set, or no database yet.** Follow [`database-connection.md`](database-connection.md) first: recover an existing connection or finish the user's chosen setup. For a PostgreSQL project with no database and no provider or local-only choice, recommend Prisma Postgres and follow its create-and-claim steps. Set the variable the config actually reads, then continue according to the database's state below. - **Database is confirmed empty and initial setup is requested.** Run `pnpm prisma db init` to apply the current contract and write the contract signature row. An intentionally empty database in a read-only task stays empty and unsigned. - **Database already has a schema.** With no Prisma contract yet and adoption requested, use the brownfield path below for PostgreSQL; for other built-in targets, follow [Other existing database engines](#other-existing-database-engines) without changing the engine or existing schema. If the project already has a contract, keep it and retry the operation that failed. For a missing signature or drift, follow [`debug.md`](debug.md) only when changing that database is within the task; otherwise report the findings. A missing signature alone does not make the database empty. - **Contract is empty** (bootstrap left the source blank). First establish whether the intended database has a schema or data. Only for confirmed-empty fresh setup, add **one** model with **two** fields (e.g. `User { id, email }`), run `pnpm prisma contract emit`, then `pnpm prisma db init`. For an existing schema, use the adoption route above when requested; do not initialize it from a starter model. If the database state is unknown, establish it before initialization. The user encounters `db init` (and optionally `db update`, `contract emit`) here because they're the commands their current move *requires*. They learn what those commands are by using them. ### Step 3 — Verify an application query For an existing database, run a read against the current model, skipping the insert in the first-arc snippet. For fresh setup or a task that includes writes, run the write/read round-trip. A read-only command-recovery task ends after retrying its original command; it does not require an application query or a test row. ### Step 4 — Hand off to the next move Now ask the user what they want to build. Route to the skill that owns that move: - More queries (filters, joins, transactions) → `references/queries.md`. - Add a model, change a field, add a relation → `references/contract.md`. They'll touch `contract emit` and `db update` (or `migration plan` + `db migrate`) as part of that workflow. - Middleware, environment config, multiple targets → `references/runtime.md`. - Vite / Next.js / dev-server integration → `references/build.md`. - They want a fuller toolbelt overview at this point — *Commands you'll use day-to-day* below is the one-glance summary. ### Anti-patterns on this path - **Leading with a feature tour or capability inventory.** The user asked what they can *do*. Get them doing it. - **Listing commands before any have been used.** Commands belong to specific moves; surface them when the move requires them. - **Diving into migration concepts before one query has run.** Migrations exist; their value lands later. - **Adding several models in one go.** Add one, get one query green, then iterate. - **Walking the user through `prisma.config.ts` keys.** The scaffold's defaults are correct; revisit when the user needs to change something. - **Skipping the contract framing.** Even one line — *"your contract is at ``, it's the source of truth"* — anchors the user; without it, the rest of the workflow lands as disconnected ceremony. ## Workflow — Greenfield The concept: `prisma orm init` is one CLI command that scaffolds config, schema, runtime, dependencies, and the contract emit step. It operates on the current working directory — there is no positional project-name argument. Make the directory, `cd` in, then run init. ```bash mkdir my-app && cd my-app pnpm init # if no package.json yet pnpm dlx prisma@latest orm init # interactive # or non-interactive (CI / agent runs): pnpm dlx prisma@latest orm init --yes --target postgres --authoring psl ``` > **Telemetry is opt-out.** The CLI collects anonymous usage data by default. Every command — including `init` — prints a one-time notice to **stderr** on first use, then sends; there is no interactive consent prompt. Opt out anytime by running `prisma telemetry disable`, or with `DO_NOT_TRACK=1` or `PRISMA_DISABLE_TELEMETRY=1`. The command stores `"enableTelemetry": false` in your user config for you (the CLI's per-user config dir, **not** `prisma.config.ts`). Run `prisma telemetry status` to see what's currently in effect. This is relevant for agent-driven runs — the CLI records that an agent invoked it. What's collected, the per-user config path, and how to fully reset are documented in `docs/Telemetry.md`. The flags `init` accepts (run `prisma orm init --help` for the source of truth): - `--target ` — `postgres`, `mongodb`, or the name of another database package, such as `@prisma/orm-sqlite`. - `--authoring