Skip to main content
This guide walks you through the full Prisma Next workflow end to end: installing packages, writing a schema, emitting a contract, initializing the database, and running queries using both the SQL DSL and the ORM client. You need Node.js 24+, pnpm, and a running PostgreSQL database to follow along.
1

Install packages

Install the prisma-next CLI as a dev dependency and the @prisma-next/postgres facade as a runtime dependency.
Prefer to skip manual setup? Run pnpm dlx prisma-next init instead. The init command prompts for your database target, scaffolds the config, schema, and runtime files, installs packages, and emits your first contract in one step.
2

Create prisma-next.config.ts

Create a prisma-next.config.ts file at the root of your project. This file tells the CLI where your schema lives, how to connect to the database, and which extension packs to load.
prisma-next.config.ts
The defineConfig export from @prisma-next/postgres/config pre-wires all Postgres internals (family, target, adapter, driver). You only need to supply your schema path and connection string.Add your database URL to a .env file:
.env
3

Define a schema

Create a prisma/ directory and add a schema.psl file. The schema uses PSL (Prisma Schema Language) — the same language as Prisma ORM.
prisma/schema.psl
The // use prisma-next comment at the top of the file marks it as a Prisma Next schema. It is required.
4

Emit the contract

Run prisma-next contract emit to generate contract.json and contract.d.ts from your schema. These two artifacts — not executable code — are the output of the build step.
The output path is configured via config.contract in prisma-next.config.ts. After emission you will find two files:
  • contract.json — the runtime contract, consumed by the Postgres facade
  • contract.d.ts — TypeScript types for full autocompletion and safety
Commit both files to version control. The contractHash inside contract.json is used by the runtime to verify the database is in sync with the schema before any query runs.
5

Initialize the database

Run prisma-next db init to create the tables described by the emitted contract. This command is additive only — it creates what is missing and leaves existing tables untouched.
For subsequent schema changes, use prisma-next db update (which also handles destructive operations) or the full migration workflow with prisma-next migration plan and prisma-next migration apply.
6

Write and run your first query

Create a src/prisma/db.ts file that initializes the Postgres client with your emitted contract:
src/prisma/db.ts
Now write queries using either the SQL DSL or the ORM client:
Run your script with:
The runtime verifies the contractHash against the database before executing any query. If the database schema has drifted from the emitted contract, you will see a structured error with a stable code and a suggested fix rather than a silent data mismatch.

Next steps

ORM client guide

Learn the full ORM client API: filters, includes, pagination, aggregations, and upserts.

SQL DSL guide

Master the SQL plan builder for lower-level query control and advanced use cases.

Migrations guide

Plan, apply, and verify schema migrations across environments.

CLI reference

Full reference for every prisma-next command and configuration option.