# ADR 325 — `init` gets everything about a target from the target package **Status:** Accepted **Date:** 2026-11-18 --- `prisma orm init` sets up Prisma 8 in a project. It writes a handful of files and installs what they need: ```text $ prisma orm init --target postgres prisma.config.ts imports defineConfig from the target package prisma/contract.prisma a starter contract prisma/db.ts creates the client prisma-8.md a quick reference .env.example the connection string to fill in tsconfig.json, .gitignore, .gitattributes, package.json scripts ``` Most of what goes into these files depends on the target: which package to import, what a starter contract looks like, what the connection string looks like, which driver to install. This record decides where `init` gets that from. A **target** is the database an application uses, such as Postgres or MongoDB. A **target package** is the package an application installs to use that target, such as `@prisma/orm-postgres`. ## Decision `init` gets it from the target package. The package exports an **init contribution** as the default export of its `init` entrypoint. `init` installs the package, loads the contribution and writes the project from it. ```ts // @prisma/orm-postgres/init import type { InitContribution } from '@prisma/orm-toolchain/cli/init-contribution'; export default { label: 'PostgreSQL', configModule: '@prisma/orm-postgres/config', peerPackages: [], authoringModes: ['psl', 'typescript'], starterContract: (mode) => (mode === 'psl' ? starterPsl : starterTs), contractSample: (mode) => (mode === 'psl' ? samplePsl : sampleTs), databaseFile: () => dbFile, envExample: () => 'DATABASE_URL="postgresql://user:password@localhost:5432/mydb"\n', quickReference: (input) => renderQuickReference(input), serverRequirement: { minVersion: POSTGRES_MIN_SERVER_VERSION, checkCommand: 'SELECT version()' }, probe: (databaseUrl) => probePostgres(databaseUrl), } satisfies InitContribution; ``` The CLI holds no template, driver name, connection string or server check for any target. It works the same way for a target package Prisma publishes and one anyone else publishes. ## What the contribution supplies and what the CLI keeps | Member | What `init` does with it | | --- | --- | | `label` | Shows it as the target's name in the quick reference | | `configModule` | Writes `prisma.config.ts` importing `defineConfig` from it | | `peerPackages` | Installs these driver packages into the application | | `authoringModes` | Offers these ways to write the contract: PSL, TypeScript or both | | `starterContract(mode)` | Writes it as the starter contract | | `contractSample(mode)` | Shows it in the quick reference | | `databaseFile()` | Writes it as `db.ts`, beside the emitted contract | | `envExample()` | Writes it into `.env.example`, and into `.env` when the user asks for one | | `quickReference(input)` | Writes it as the quick reference | | `readme(input)` | Optional. Writes it as the README in a project that already has `src/index.ts` | | `serverRequirement` | Optional. States the minimum server version in the quick reference | | `probe(databaseUrl)` | Optional. Connects and reports the server's version, for `--probe-db` | | `prisma7QuickReference(input)` | Optional. The quick reference for a project that keeps its Prisma 7 schema as the contract source | The CLI keeps everything that is the same for every target: which files exist and where they go, package manager detection, `prisma.config.ts` around `configModule` (for a starter contract and for a Prisma 7 schema), `tsconfig.json`, `.gitignore`, `.gitattributes`, the `package.json` scripts, the questions it asks and what it prints. Two facts are shared by the CLI and every contribution, and the interface states them: the connection string is read from `DATABASE_URL`, and `dotenv` is installed with the target package, so `db.ts` may import `dotenv/config`. The `init` entrypoint may import types from the framework but no framework code that runs. The CLI that loads it can be a different installed copy of the framework from the one the target package depends on, and two copies in one process do not recognise each other's values. A probe reports one of three results: the server's version, a missing driver, or a connection that worked whose version could not be read. It rejects only when it cannot connect. ## The target package is installed first The files come from the target package, so it has to be present before `init` can write anything. ```text check the flags → resolve the target package → install it, with dotenv → load its contribution → ask: authoring mode, contract path, and consent to replace files if the project is already set up → write the files → install the driver packages, the CLI and the rest → emit the contract → check the server, when asked to ``` `init` asks nothing before installing the target package. The user named it, and installing it is what they asked for. Any refusal that depends only on the flags happens before the install. When a refusal comes after the install, the error says the package was added and gives the command to remove it. With `--skip-install`, `init` installs nothing, so the target package must already be there. If it is not, `init` stops before changing anything and prints the install command. A failed install stops `init`, as [ADR 323](ADR%20323%20-%20Prisma%208%20is%20not%20a%20package%20manager%20and%20does%20not%20second-guess%20one.md) requires. ## How the user names the target ```sh prisma orm init --target postgres # a short name prisma orm init --target prisma-orm-cockroachdb # a package name ``` The CLI holds a list of known target packages. `--target` is looked up in it, and a value that is not in the list is taken as a package name. Until package names are accepted, `--target` takes the short names only. | Short name | Aliases | Package | Name in this repository | Label | Provider in an earlier Prisma schema | Driver for the Prisma 6 setup | | --- | --- | --- | --- | --- | --- | --- | | `postgres` | `postgresql` | `@prisma/orm-postgres` | `@internal/postgres` | PostgreSQL | `postgresql`, written by Prisma 7 | none | | `mongodb` | `mongo` | `@prisma/orm-mongo` | `@internal/mongo` | MongoDB | `mongodb`, written by Prisma 6 | `mongodb` | - **A target package is listed because Prisma vouches for it.** Who wrote it does not matter, and a community package can be listed. - **The list holds names and the facts `init` needs before anything is installed.** The picker shows the label before the package is installed. A Prisma 6 project gets printed setup instructions and no install at all, so the instructions name the driver from the list. - **A listed package runs the same code as an unlisted one.** Listing gives a short name, a line in the interactive picker, and the mapping from an earlier Prisma's provider. - **The list must agree with the contributions.** A test loads each listed package's published contribution and checks that its label, driver packages and config module match the list entry. ## Projects coming from Prisma 6 and Prisma 7 `init` reads the `provider` from an existing Prisma schema and finds the target package through the list. Only listed packages take part. A provider with no entry is refused, with advice to name a package with `--target` and start a fresh project. - **A provider only Prisma 6 wrote**, such as `mongodb`, marks a Prisma 6 project. `init` changes nothing and prints how to set Prisma 8 up beside it. - **A Prisma 7 schema** can be kept as the contract source. A target package can take one when its `configModule` exports `prisma7Schema`. The CLI then writes the config around it, and the contribution must give `prisma7QuickReference`. A package without `prisma7Schema` cannot take a Prisma 7 schema, and `init` sets up a fresh project instead. ## Output The `--json` result reports `target`: the short name for a listed package. When package names are accepted, it also reports `package`, the name of the target package that was installed. ## Why - **The framework knows nothing about any target.** A starter contract and a connection string are facts about a target, so they belong to that target's package. - **Every target package is treated the same.** Prisma's own have no path through `init` that another author's lacks. - **The CLI depends on no target package.** It loads a contribution from the one the user chose, after installing it into the user's project. - **An extension is installed one way.** `init` adds a package and writes a config that imports it. Nothing is registered anywhere else. ## Consequences - Any target package gets `init` by exporting one entrypoint, with no change to the CLI and no entry in the list. - A target package without a runtime client cannot provide a contribution, because there is no `db.ts` to write. - `init` cannot write a project for a target package that is not installed. `--skip-install` in a project without it is refused. - `init` runs code from the package the user names. It is the same package the config loads a moment later. - The minimum server version has one source, the target package's code. The CLI keeps no copy of it. ## Alternatives considered ### The CLI depends on the target packages and registers their contributions The published CLI would depend on each target package and hold their templates, so they are available before anything is installed and `--skip-install` works in an empty project. Rejected. It works only for packages the CLI depends on, so a target package from another author has no way in, and every installation of the CLI would carry every target package. ### Registration in `package.json` The application names the target package in a `package.json` field, and the package describes itself in another. Rejected because an extension is installed by importing it in the config, and a second place to declare the target can disagree with the first. ### Templates as static files or metadata, with no code This keeps package code from running before the project is set up. Rejected because `init` loads the config and emits immediately afterwards, which runs the same package, and a server check cannot be data. ### The contribution writes the Prisma 7 config Each target package would carry its own copy of the config the CLI already writes for a starter contract, differing only in the contract line. A change to that text would have to be made in every target package, and the contribution's member would be a second answer to whether the package can take a Prisma 7 schema, beside the `prisma7Schema` export. Rejected. ### Package names only, with no list `prisma orm init --target @prisma/orm-postgres` for everyone. Rejected because a first-time user cannot discover the package name, and the interactive picker would have nothing to show. ### A prompt before installing a package that is not in the list A question, or a typed consent, before `init` installs and runs an unlisted package. Rejected because it interrupts the run to confirm a name the user has just typed, and it would make an unlisted package behave differently from a listed one. ### The list lives outside the framework's CLI Considered so that the framework names no target at all. Rejected as unnecessary. The list decides no behaviour that depends on the target, and the rule against target names in the framework exists to prevent such behaviour.