Documentation Index
Fetch the complete documentation index at: https://mintlify.com/prisma/prisma-next/llms.txt
Use this file to discover all available pages before exploring further.
prisma-next contract infer connects to a live database, introspects its schema, and writes an inferred Prisma Schema Language (PSL) contract file to disk. This is the recommended starting point for brownfield adoption: run contract infer once to generate a contract.prisma that reflects your existing schema, then refine it, run contract emit, and sign the database with db sign.
Synopsis
Options
Database connection string (e.g.,
postgresql://user:pass@localhost/db). Optional if db.connection is set in your config file.Path to
prisma-next.config.ts. Accepts relative or absolute paths. Defaults to ./prisma-next.config.ts in the current working directory if the file is present. The CLI does not search upward.Write the inferred PSL contract to this path. When omitted, the output path is resolved automatically (see Default output path).
Emit a JSON result envelope to stdout instead of the default human-readable TTY output. The envelope includes
psl.path with the resolved output path.Suppress all output except errors.
Print debug information and timing data.
Print deep internal trace output including stack traces. Intended for debugging the CLI itself.
Force-enable or force-disable ANSI color in output. By default, color is enabled when stdout is a TTY.
Config file requirements
contract infer requires a driver in your config to establish a database connection. A contract field is not required — infer works even before you have a contract.
prisma-next.config.ts
Either
db.connection in the config or the --db flag must resolve to a connection string. If neither is present, the command exits with PN-CLI-4005.Default output path
When--output is not provided, the output path is resolved in this order:
--output <path>, if provided.contract.prismaplaced next toconfig.contract.output(the configuredcontract.jsonpath).contract.prismain the current working directory.
Examples
Introspection process
Connect to database
Creates a driver instance by calling
config.driver.create(url), using the URL from --db or config.db.connection.Create family instance
Calls
createControlStack() from @prisma-next/framework-components/control to assemble a ControlStack, then passes it to config.family.create(stack) to produce a ControlFamilyInstance.Introspect
Calls
familyInstance.introspect(), which queries the database catalog to discover tables, columns, constraints, indexes, and extensions. Returns a family-specific schema IR (e.g., SqlSchemaIR for the SQL family).Transform to schema view
Calls
familyInstance.toSchemaView() to project the family-specific schema IR into a CoreSchemaView used for display and PSL generation.Introspection output uses native database types (e.g.,
int4, text, timestamptz) rather than mapped codec IDs (e.g., pg/int4@1). These reflect the actual database state and may be enriched with type mappings after you edit the inferred contract.Output format
TTY (default)
When stdout is a TTY, the command prints a human-readable summary:JSON (--json)
With --json, the command prints a single JSON object and exits. The psl.path field contains the resolved output path.
Error codes
| Code | Meaning | Fix |
|---|---|---|
PN-CLI-4005 | Missing database connection | Provide --db <url> or set db.connection in config |
PN-CLI-4010 | Missing driver in config | Add a driver descriptor to prisma-next.config.ts |