contract infer
Infer a starter contract from an existing database.
contract infer inspects a live database and writes a starter PSL contract. An existing file at the output path is overwritten, with a warning.
Use it when you are adding Prisma 8 to an existing database and want an initial contract to review and edit.
Usage
bunx prisma@latest contract infer --db "$DATABASE_URL"Options
| Option | What it does |
|---|---|
--db <url> | Connects to the database. |
--output <path> | Writes the inferred PSL contract to a specific path. |
--config <path> | Read this config file instead of ./prisma.config.ts. |
--json | Prints a machine-readable result. |
Examples
bunx prisma@latest contract infer --db "$DATABASE_URL"
bunx prisma@latest contract infer --db "$DATABASE_URL" --output ./prisma/contract.prisma
bunx prisma@latest contract infer --db "$DATABASE_URL" --jsonWhat to review
Inference gives you a starting point, not a finished design. Review:
- model and field names
- relation names
- mapped database names
- defaults, indexes, and constraints
- extension-backed column types
The command stops at contract.prisma. Follow it with the emit and sign steps:
bunx prisma@latest contract emit
bunx prisma@latest db sign --db "$DATABASE_URL"
bunx prisma@latest db verify --db "$DATABASE_URL"db sign is the handoff point where you record that the existing database matches the reviewed contract.
