Repository navigation
feat: generated files import from the module the target package names, so a target built outside this repository can emit - #31078
Merged
Merged
Conversation
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Signed-off-by: willbot <[email protected]>
Add two optional strings to existing config sections: contract.typesModule, the module generated contract types import from, and migrations.module, the module rendered migration files import from. The loader validates both as strings and keeps them as written. Nothing reads them yet. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Signed-off-by: willbot <[email protected]>
The shell build defines __PRISMA_PUBLISHED_PACKAGE_NAME__ as the shell's published name. A package that names its own modules reads it and falls back to its workspace name when it is not defined, which is the case for its own workspace build and for its source run under vitest. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Signed-off-by: willbot <[email protected]>
… config Add a generated-types entrypoint that re-exports, as types only, everything a generated contract.d.ts imports from the framework contract types, the SQL family contract types and the Postgres codec and operation types. The facade's defineConfig names <own name>/generated-types as contract.typesModule and <own name>/migration as migrations.module, so the workspace package names @internal/postgres/... and the published package names @prisma/orm-postgres/.... Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Signed-off-by: willbot <[email protected]>
The all-shells tarball test now fails when __PRISMA_PUBLISHED_PACKAGE_NAME__ is left in any published package's built code, which happens only when the shell build did not define it and the package would fall back to its workspace name. The build README says the name check must live in each package's own source, because the shell build defines the constant only in the code it bundles into that shell. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Signed-off-by: willbot <[email protected]>
…ports The all-shells tarball test loads every published target package's defineConfig and fails unless contract.typesModule and migrations.module are exports of that package, for the packages listed as naming them, and fails if an unlisted package names any. The unfilled-constant case now also fails when it reads no built file for a package. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Signed-off-by: willbot <[email protected]>
The shell build now defines __PRISMA_PUBLISHED_MODULE_BASE__, derived from the shell table: the shell's name plus the entry its one internal package is published under, so a package published under a prefix such as @prisma/orm-postgres-contrib/citext gets a base whose subpaths exist. A shell that bundles several internal packages gets no definition, since one global cannot differ between them. Postgres still names @prisma/orm-postgres/... The Postgres README lists the generated-types entrypoint. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Signed-off-by: willbot <[email protected]>
…sion module names change Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…y target config MongoDB, SQLite, MySQL and MariaDB get what Postgres got: a module-base.ts in their own source, a generated-types entrypoint that re-exports, as types only, what a generated contract.d.ts imports for that target, and a defineConfig that names <base>/generated-types and <base>/migration. MongoDB gains a migration entrypoint re-exporting its target's migration module, so the workspace name resolves too. MariaDB passes its own module base to MySQL's createMysqlDefineConfig. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…the module base arktype-json, citext, paradedb, pgvector and postgis state their codec and operation type modules as <module base>/..., from a module-base.ts in their own source. In the workspace the string is the same private name as before; in the published package it is the published module, including citext's @prisma/orm-postgres-contrib/citext prefix. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ports All five target packages are now listed as naming both modules. A new case loads each published extension's control descriptor and fails unless every module it states for its types is an export of that installed package. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… names The only change is the package string of extension codec and operation type metadata recorded in emitted contracts, from the private workspace name to the published name, for contracts emitted through published extension packages. No import line and no hash changes. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ge touches Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…kage README The published Postgres, MongoDB, SQLite, MySQL and MariaDB READMEs list /generated-types, the types a generated contract.d.ts imports. MongoDB's also lists its new /migration entrypoint. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…mports; run that dispatch next Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
enrichContract no longer copies an extension's type-import declarations (codecTypes.import, typeImports and parameterizedOutputTypes, and the import of operationTypes and queryOperationTypes) into contract.extensions. Nothing read them back: the emitter writes import lines from the descriptors. A key left empty is dropped. Hashes do not cover extensions, and validation still accepts a contract that carries the old record. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ecords The only change is the removal of the type-import declarations from each extension's record under extensions in contract.json and contract.d.ts, with any key left empty dropped. No import line and no hash changes. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e list Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ed half runs now Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…tion never holds a workspace name Amends the generated imports record: a target and an adapter are the same kind of thing as an extension and declare their types the same way. A target package restates its components' declarations with its own module. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
….module MigrationPlanWithAuthoringSurface.renderTypeScript takes the module a rendered migration.ts imports from, instead of a function that translates private module names. Every target's call nodes name a MIGRATION_MODULE placeholder, which the renderer replaces with that module. migration new and migration plan pass the config's migrations.module, and stop before writing anything with CONFIG.MIGRATION_MODULE_MISSING when the config names none. MySQL's control target no longer carries a migration module of its own. resolveRequirementSpecifiers, whose only users were the renderers, is removed; the translation function stays for contract types. In-repo configs assembled by hand that render migrations name the module they rendered against before. The import-root tests for migration files are replaced by tests that the rendered imports come from the config. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…odule Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ating it run as one dispatch Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…es restate it The shell build now defines one module base per internal package it bundles, as __PRISMA_PUBLISHED_MODULE_BASE__<PACKAGE>, from the shells table, so the Postgres target and adapter, bundled into one published package, each get their own. Every package that names its own modules reads its own identifier. Every target and adapter type declaration names its published module through its base; the Postgres and MongoDB adapters take their target's base from the target's new module-base export. No declaration in a published package holds a workspace name. Each target package's defineConfig hands the config copies of its target and adapter whose type declarations name its own generated-types module, through restateTypeDeclarations in the new @internal/target-package-config. The all-shells test checks that no build leaves a module base identifier, that each target platform package's components name its own exports, that a target package's config names its generated-types module, and that no type declaration in built or declaration files names an @internal module. The allowed list of internal names in published dist drops the 23 entries that no longer have a cause. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…mports The only change is in the import lines of target and adapter types: a contract emitted through a target package's defineConfig imports them from that package's generated-types module, as one line, where it imported them from the target's and adapter's own modules. The imported names and aliases, every other line and every hash are unchanged. A fixture that replaces the target package's adapter with the workspace one keeps the adapter's own modules. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… import Each extension's own config names @internal/target-postgres/migration, the module every committed extension migration imports and a dependency of all five, instead of the Postgres target package's module, which paradedb does not depend on. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e and the shared target packages are listed The framework package's README lists its /target-package-config and /type-implementations entrypoints, and the layering docs list the new shared target package beside @internal/type-implementations. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…arget and adapter Each target package makes its restated target and adapter once, in src/config/components.ts, and both its defineConfig and its control client take them from there, so contract types emitted through the control client import the target's and adapter's types from the package's generated-types module. MySQL's createMysqlDefineConfig uses the components it is given, and MariaDB passes its own restated ones. The all-shells test emits through every published target package's control client and checks those imports. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Contributor
WalkthroughWarning Review details and warnings were omitted to fit the comment limit. |
@prisma/orm-extension-arktype-json
@prisma/orm-extension-middleware-cache
@prisma/orm-extension-paradedb
@prisma/orm-extension-pgvector
@prisma/orm-extension-postgis
@prisma/orm-extension-supabase
@prisma/orm-family-mongo
@prisma/orm-family-sql
@prisma/orm-framework
@prisma/orm-mariadb
@prisma/orm-mongo
@prisma/orm-mysql
@prisma/orm-postgres
@prisma/orm-postgres-contrib
@prisma/orm-sqlite
@prisma/orm-target-mariadb
@prisma/orm-target-mongo
@prisma/orm-target-mysql
@prisma/orm-target-postgres
@prisma/orm-target-sqlite
@prisma/orm-toolchain
commit: |
Contributor
size-limit report 📦
|
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden
approved these changes
Nov 17, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 17, 2026
3 tasks done
…nerated-imports Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # packages/1-framework/3-tooling/cli/src/orm/db/update.ts # packages/1-framework/3-tooling/cli/src/orm/migrate.ts
wmadden
enabled auto-merge
November 17, 2026 23:56
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 18, 2026
…ontract types module The database policies journey and the pgvector ref-aware journey wrote Postgres configs by hand without contract.typesModule or migrations.module, so contract emit stopped with CONFIG.CONTRACT_TYPES_MODULE_MISSING. They now name the Postgres facade's contract-types and migration modules, as the shared fixtures do. contract-imports asserted the old @internal/sql-contract/types import. It now emits with @internal/postgres/contract-types as the types module, asserts the declarations import from it and not from the old roots, and compiles them against that module. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
github-merge-queue
Bot
removed this pull request from the merge queue due to invalid changes in the merge commit
Nov 18, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 18, 2026
…nerated-imports Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # packages/0-config/tsdown/shell-testkit.ts
wmadden
enabled auto-merge
November 18, 2026 02:11
…nerated-imports Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # packages/0-shared/publish-surface/test/import-roots.test.ts # packages/3-targets/mysql/1-mysql/9-facade/test/config/create-define-config.test.ts # packages/3-targets/mysql/2-mariadb/9-facade/README.md # packages/3-targets/mysql/2-mariadb/9-facade/package.json # packages/3-targets/mysql/2-mariadb/9-facade/tsdown.config.ts # pnpm-lock.yaml
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-prisma__orm
that referenced
this pull request
Nov 19, 2026
…s, not from templates in the CLI (prisma#31093) ## At a glance `prisma orm init` writes the same files as before. What changes is where their text comes from. ```text $ prisma orm init --target postgres --authoring psl … src/prisma/contract.prisma prisma.config.ts src/prisma/db.ts prisma-8.md .env.example tsconfig.json .gitignore .gitattributes package.json ✔ Done. Open prisma-8.md to get started. ``` Before, the CLI held the Postgres and MongoDB starter contracts, `db.ts`, `.env.example`, quick references, driver names and server probes, and chose between them with `if (target === 'postgres')`. Now each target package exports them from a new `init` entrypoint, and the CLI loads them from the package it has just installed: ```ts // @prisma/orm-postgres/init export default { label: 'PostgreSQL', configModule: '@prisma/orm-postgres/config', peerPackages: [], authoringModes: ['psl', 'typescript'], starterContract: (mode) => …, databaseFile: () => …, envExample: () => 'DATABASE_URL="postgresql://user:password@localhost:5432/mydb"\n', quickReference: (input) => …, serverRequirement: { minVersion: POSTGRES_MIN_SERVER_VERSION, checkCommand: 'SELECT version()' }, probe: (databaseUrl) => …, } satisfies InitContribution; ``` A package without the entrypoint is refused with nothing written: ```text ✘ [CLI.INIT_CONTRIBUTION_UNAVAILABLE] @prisma/orm-postgres does not support init why: @prisma/orm-postgres has no `@prisma/orm-postgres/init` entrypoint, so it does not support `prisma orm init`. @prisma/orm-postgres is installed; no file was written. → Write prisma.config.ts by hand, importing defineConfig from @prisma/orm-postgres as its README describes. ``` ## What this PR changes 1. A type, `InitContribution`, published as `@prisma/orm-toolchain/cli/init-contribution`. It is what a target package's `init` entrypoint exports. 2. `@prisma/orm-postgres/init` and `@prisma/orm-mongo/init`, holding the templates, markdown and probes moved out of the CLI. The text is unchanged. 3. `init` installs the target package first, then loads its contribution, then asks its questions and writes files. 4. The CLI names no target outside one list of the target packages Prisma vouches for. The framework vocabulary threshold drops from 209 to 139. 5. Three new errors: `CLI.INIT_TARGET_PACKAGE_NOT_INSTALLED`, `CLI.INIT_CONTRIBUTION_UNAVAILABLE` and `CLI.INIT_AUTHORING_UNSUPPORTED`. 6. The design record, ADR 325, and corrections to the version-support records, which described a copy of the server floors the CLI no longer keeps. `--target` still takes only `postgres` and `mongodb`, and the `--json` output is unchanged. Accepting a package name is the next change. ## Why A team at Microsoft is building a SQL Server target in their own repository. Since prisma#31078 their package can emit files that compile. `init` could not reach it, because every starter file lived in the framework's CLI and was chosen by target name. The CLI depends on no target package, so before this PR it had nothing else to read templates from. Moving the templates into the target package gives every target, ours or theirs, the same way in. ## How `init` runs now ```text check the flags → install the target package, with dotenv and its drivers → load <package>/init from the project and check its shape → ask: authoring mode, contract path, consent to replace files → write the files → install the CLI and the rest → emit the contract → probe the server, when asked to ``` - **Installing comes first** because the files come from the package. With `--skip-install` the package must already be installed; otherwise `init` stops with nothing changed and prints the install command. - **Refusals that need only the flags** happen before the install. A refusal after the install says which packages `init` added and gives the command to remove them. - **A failed install stops `init`**, as ADR 323 requires. - **Loading from the project.** `src/orm/project-modules.ts` lets Node resolve `<package>/init` from the project folder, by running `import.meta.resolve` in a short child process, so the package's export map is read by Node's own rules. It tells apart a package that is not installed, one with no `init` export, and one whose module is missing or throws while loading. - **No framework code runs in the entrypoint.** The CLI that loads it may be a different installed copy of the framework, and two copies in one process do not recognise each other's values. An integration test follows the built entrypoints' imports to check this. ## What the CLI keeps Everything that is the same for every target: which files exist and where they go, `prisma.config.ts` around the contribution's `configModule`, `tsconfig.json`, the git files, the `package.json` scripts, the questions and the output. That includes the config for a project that keeps its Prisma 7 schema: a target package takes a Prisma 7 schema when its config module exports `prisma7Schema`, and then supplies only the matching quick reference. ## The list of known target packages `src/commands/init/target-packages.ts` is the only place the CLI names a target. Each entry has the short name and aliases `--target` takes, the package and its name in this repository, the label the picker shows before anything is installed, the provider an earlier Prisma schema names, and the driver the printed Prisma 6 setup installs. A listed package runs the same code as an unlisted one. An integration test checks that each entry agrees with its package's contribution on label, drivers and config module. ## Decisions made during the work - **The drivers install with the target package**, as on main: `add @prisma/orm-postgres dotenv pg`. A target package declares its driver as a required peer dependency (ADR 219), so it must be in the same install. The list names each listed package's drivers, because they are needed before the package is installed. - **The install before the questions changes no version the project chose.** It leaves out `dotenv`, drivers and the target package itself when the project already declares and has them. A target the project declares but has not installed is still requested by name, because the package-manager library `init` uses can only add named packages; the refusal report then names the rewritten range and its old value. - **The undo instruction comes from `package.json`**, read before and after the install, so it names only what the install actually added or rewrote. - **`readme` is optional.** It describes a project that already has `src/index.ts`. - **A probe has four results:** the server's version, a missing driver, a driver that fails to load, or a connection that worked whose version could not be read. Before, the last two were reported as "could not connect". `init` gives every probe 60 seconds and then aborts it through an `AbortSignal`. - **The CLI test fixture installs `@internal/postgres` and `@internal/mongo`.** A workspace build of a contribution names its modules by the workspace name, as generated imports do since ADR 324. ## Tests - Template snapshots moved into the facades' `test/init/` unchanged and pass without updating; `test/integration/test/cli.init-templates.e2e.test.ts` emits the same contract hashes. - `packages/1-framework/3-tooling/cli/test/orm/init-target-package.test.ts` covers each refusal, the undo instruction, the install order and the files written. `test/orm/project-modules.test.ts` covers the loader. - `test/integration/test/cli.init-target-packages.test.ts` checks the list against the published contributions. - `test/integration/test/cli.init-facade-imports.e2e.test.ts` checks that no entrypoint loads framework code. - The init journey (all four target and authoring combinations) passed locally. - By hand: `init` for Postgres with PSL and MongoDB with TypeScript against the built packages, and the refusals for an uninstalled package, a bad target and a package with no `init` entrypoint. ## Alternatives considered - **The CLI depends on every target package.** Only packages the CLI depends on could take part, and every install of the CLI would carry every target. - **Templates as static files.** A server probe cannot be data, and `init` runs the package's code a moment later anyway, when it loads the config. - **The contribution writes the Prisma 7 config.** Every target package would copy the config the CLI already writes, and the member would be a second answer to whether the package takes a Prisma 7 schema. - **Resolving export maps in the CLI process**, by hand or with the `resolve.exports` package. Both differ from Node in edge cases, such as a condition with no match inside it, so `init` could load a different module from the one the config loads. Fixes TML-3702. Agent: isildur-87 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-prisma__orm
that referenced
this pull request
Nov 24, 2026
…t builder errors no longer show the internal name __unbound__ (prisma#31191) ## At a glance This pull request closes a finished project and deletes its working folder: ```text projects/external-target-integration/ deleted (spec, plan, review notes, a document for an outside team) drive/ what the project taught us, recorded for the next project ``` The project is called "external target integration". A target package is the package an application installs to talk to one kind of database, such as `@prisma/orm-postgres`. The project made `prisma orm init --target <package>` and `prisma contract emit` work for a target package that Prisma did not write. That is released and works. One small code fix rides along, because the project's last test run found it. On SQLite, errors from the TypeScript contract builder showed an internal name the user never wrote: ```text before: A table in namespace "__unbound__" is named "__proto__" … after: A table is named "__proto__" … before: Table "audit_rows" in namespace "__unbound__" is declared by two table nodes. after: Table "audit_rows" is declared by two table nodes. ``` ## The decisions in this PR 1. **The project is closed although one of its own criteria is not met.** The outside team that asked for this (they build a SQL Server target) has been sent the released versions and has not yet confirmed that their package works. The project owner decided to close without waiting: nothing in this repository depends on their answer, and a problem they report will be handled as a bug report. 2. **The project folder is deleted, including the document written for that team.** A note already sent to the team links to that document, so the link stops working when this merges. The page to send in its place is the guide for authors of a target package, `skills/prisma-8/references/build-a-target-package.md`. The pull request also rewrites the project's two decision records so that someone without our context can read them (section 5). No decision in them changes. The rest of the description explains each change, then gives the evidence that the project did what it was for. ## 1. The project folder is deleted A folder under `projects/` holds working documents and is deleted when the project ends. What should last moves to permanent docs first. Here that had already happened, in the pull requests that built each part: - **The two design decisions** are accepted decision records under `docs/architecture docs/adrs/`: ADR 324 "Generated files import from the module the target package names" and ADR 325 "`init` gets everything about a target from the target package". - **The instructions for a package author** are in the author guide named above. - **How `init` works** is in the CLI subsystem document and the CLI Style Guide. | File | What happens | Why | | --- | --- | --- | | `spec.md`, `plan.md`, `slices/**`, `reviews/**` (the specs, plans and review notes of each part of the work) | deleted | They coordinated the work. The spec has no decision log; its two decisions are the two decision records | | `learnings.md` | deleted | Each lesson is now in `drive/` (section 2), except one the build procedure already states: set up the review file before the first implementer is briefed | | `sql-server-team.md` | deleted | Its instructions for a package author are in the author guide. The rest answers the team's original proposal and describes a workaround for the time before the release; both are out of date | Nothing outside the folder links into it: a search of the repository for `projects/external-target-integration` finds nothing. ## 2. What the project taught us `drive/` holds this repository's notes on how we run projects: checklists that are read when the next project is planned, briefed and closed. The project's final review of its own process (its retro) is recorded there: - `drive/retro/README.md` has the project's entry: one line for each thing that went wrong, linked to the checklist item it produced. - `drive/calibration/dod.md` (the "done" checklists) has a new project check, "Reached the user": before a project is called done, the spec's opening example is run from published packages, a report from the intended user is answered, and release notes are checked against the release's tag. This project was first reported finished when its changes were merged but not yet released. - `drive/calibration/dor.md` (the "ready to start" checklists) has seven additions on writing the design, planning, and briefing an implementer. Each says what went wrong here. - `drive/project/README.md` says a plan's close-out section should point to the close-out procedure and carry no checklist of its own. This close-out first started from the plan's own checklist and skipped steps, as two earlier projects did. ## 3. The error messages A contract is the description of an application's data model that Prisma emits and checks. It groups tables into namespaces; on PostgreSQL a namespace is a schema. A target without namespaces, such as SQLite, keeps every table under one internal namespace, called the unbound namespace, whose id is the placeholder `__unbound__`. The TypeScript contract builder (`packages/2-sql-family/2-authoring/contract-ts`) printed that id in its errors wherever it said which namespace something is in: a name that cannot be used, a table declared twice, a foreign key to a table that does not exist, and duplicate target-specific entities. Every such message now goes through one helper, `inNamespace`, which writes ` in namespace "<name>"` for a named namespace and nothing for the unbound one. A message about a namespace the user wrote themselves is unchanged. The errors' machine-readable data still carries the id. On PostgreSQL a table with no schema stated goes to `public`, so this changes nothing there, with one exception: a contract can put a table in the unbound namespace on purpose (`namespace unbound { … }`), to bind it to a schema later. Its errors now also leave the namespace out, which is accurate, because that table has no schema yet. ## 4. The author guide Three facts that were in the team document and not in the guide are added: - A user names a target package in `--target` by its package name. Short names such as `postgres` exist only for the packages in the CLI's list of targets Prisma vouches for, which today is Postgres and MongoDB. - With `--skip-install`, the target package must already be installed, because `init` loads the package's `/init` entrypoint before it writes anything and reads the required keyword from the installed copy. - A check with a package that borrows another target's parts behind its own name proves only the wiring. A target written from scratch also needs its own descriptors, types, migration planner and renderer, serialiser and client. ## 5. The two decision records are rewritten for a cold reader ADR 324 "Generated files import from the module the target package names" and ADR 325 "`init` gets everything about a target from the target package" record the project's two decisions. A reader with none of our context read each one and listed where they stumbled. The rewrites answer that: - **ADR 324** now states, before the decision, the three facts that make the question hard. It has a small flow diagram, a config sample trimmed to the two lines that matter, and a definition for each term where it first appears. The target package's three obligations move from Consequences into the decision. - **ADR 325** stated one decision and made five. All five are now in the Decision section, "Why" follows it, and naming the target comes before the install order that depends on it. The check on a package's keyword leads with the mistake it prevents. The two installs have one name each. - Both lose sentences that answered designs a future reader never saw, and wording such as "yet" and "for now". A reviewer compared each rewrite with the old text statement by statement and with the code. It found fourteen places where the first draft dropped a decision or said something the code does not do. All are corrected, and its second pass found two more, also corrected. ## Did the project do what it was for? The spec's purpose: a team outside Prisma can build a target package in its own repository, and an application uses it with `init` and `contract emit` exactly as it uses Prisma's Postgres package. Checked on 2026-11-23 from what a user can install: the `prisma` CLI 8.0.0-rc.35 and the ORM packages 8.0.0-rc.25 (the CLI is released separately and has its own version numbers). In a clean project, with no version forced: | Step | Result | | --- | --- | | `prisma orm init --target @prisma/orm-sqlite --authoring psl --write-env --yes` | passed; the config imports `@prisma/orm-sqlite/config` | | `prisma contract emit` | passed | | `prisma migration plan --name init` | passed | | `prisma db migrate --yes` | passed | | typecheck | passed | | one query that creates a row and reads it back | passed | Prisma's SQLite package stands in for an outside package. The CLI has no list entry, template or special case for it, so it takes the same path an outside package takes. One real attempt was made during the project. The outside team's first try failed on a table named `constructor`. That was fixed, together with the wider defect behind it (names such as `constructor` and `__proto__` used as object keys), in prisma#31148, prisma#31173 and prisma#31185. One smaller gap is known and ticketed, and does not block the close: if a target package is published only under a tag other than `latest`, `init` stops and says the package was not found. Installing the package first and running `init` again works, and the message says so ([TML-3931](https://linear.app/prisma-company/issue/TML-3931)). ## The project's definition of done | Criterion | Result | Evidence | | --- | --- | --- | | A test application outside the monorepo, on a stand-in target package that is in no list in this repository, runs `init`, `contract emit`, `migration plan` and a typecheck, and no generated file imports a private or framework package | met | The packaging test from prisma#31078, extended in prisma#31128 | | No code in the CLI branches on a target's name | met | prisma#31093 and prisma#31128. The one file that names targets is the list of short names, which ADR 325 allows | | The CLI does not read `package.json` to choose import names | met | The file that did it is gone (prisma#31078) | | The `init` tests pass for Postgres and MongoDB, for a contract written as a Prisma schema and as TypeScript | met | prisma#31093 | | `init --target @prisma/orm-sqlite` and `--target @prisma/orm-mysql` each set up a project that emits and typechecks, and the SQLite project runs a query | met | prisma#31128, and the run above | | Both decision records are accepted and the docs describe the shipped flow | met | ADR 324 and ADR 325 are `Accepted` and in the index | | The outside team has confirmed that their package works from a published release | not met | Decision 1 above | | The two older tickets the project took over are closed | met | Both are Done | Every review thread is resolved on the six pull requests that built the project: prisma#31078, prisma#31093, prisma#31128, prisma#31148, prisma#31173 and prisma#31185. Linear project: [Targets built outside the ORM repo work with init and generated files](https://linear.app/prisma-company/project/targets-built-outside-the-orm-repo-work-with-init-and-generated-files-fd0afcc6f7f2). Seven follow-up tickets stay open in the backlog. None blocks this pull request or the project's purpose; each is written to be read on its own. ## Tests In `packages/2-sql-family/2-authoring/contract-ts/test/`, each changed message has a case with the unbound namespace and a case with a named one: `named-entries.test.ts`, `merge-tables.test.ts`, `table-node.refusals.test.ts`, `table-node.foreign-keys.test.ts`, `pack-entities.test.ts` (new) and `entity-handle-lowering.test.ts`, which goes through the public `defineContract` builder. The unbound cases fail without the fix; the named cases show the old wording is unchanged. ## Alternatives considered - **Keep the project open until the outside team confirms.** Rejected: nothing here waits on their answer, and an open project folder invites more work on a finished project. - **Keep the team document, under `docs/` or as a stub that points to the author guide.** Rejected: a file under `docs/` has a different address, so the link in the note breaks either way, and a stub left in `projects/` keeps a finished project's folder alive for one link. Most of the document is also out of date. - **Put the error fix in its own pull request.** Rejected: it is one helper used in six files, and a second pull request costs a second review for no gain. - **Show a friendlier label in place of `__unbound__`,** such as "the default namespace". Rejected: a SQLite user has no namespace at all, so any label names something they cannot find in their contract. Agent: osiris-43 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Error messages for duplicate names, unknown tables, and related contract issues now omit namespace wording when no namespace is bound, while retaining namespace details when applicable. * **Documentation** * Updated target-package setup guidance and expanded architecture guidance for target contributions, generated files, and installation flows. * Updated project checklists and close-out guidance, including terminology, dispatch hand-offs, and release verification. * Clarified decision-record and project close-out practices, and added a recurring-pattern review. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At a glance
An application installs a target package that is not one of Prisma's, here a stand-in called
prisma-orm-standin, and runsprisma contract emit.Before, the generated
contract.d.tsdoes not compile, because it imports from a package that exists only inside this repository:After, it imports from the module the target package's config names:
Prisma's own target packages go through the same mechanism. The SQLite demo's
contract.d.tshad three import statements, from@prisma/orm-sqlite/contract/types,@prisma/orm-sqlite/family-contract/typesand@prisma/orm-sqlite/adapter/codec-types. It now has one, from@prisma/orm-sqlite/contract-types.What this PR changes
contract.typesModule, the module a generatedcontract.d.tsimports its types from, andmigrations.module, the module a generatedmigration.tsimports from.@prisma/orm-postgres,-mongodb,-sqlite,-mysql,-mariadb) exports acontract-typesmodule and sets both members in itsdefineConfig. An application that calls a target package'sdefineConfigchanges nothing and re-runsprisma contract emit.package.json, and no table of Prisma's package names is consulted when a file is generated.CONFIG.CONTRACT_TYPES_MODULE_MISSINGorCONFIG.MIGRATION_MODULE_MISSING. Nothing is guessed.contract.jsonno longer records where an extension's types are imported from. Nothing read it, and it held private package names.About 340 of the 814 changed files are regenerated
contract.d.tsandcontract.jsonfiles. The regeneration is in commits of its own.Why the old mechanism could not serve an outside target
Inside this repository, packages have private names such as
@internal/contract. They are published under other names, such as@prisma/orm-postgres/contract/types. When the emitter wrote an import, it translated the private name to a published one. To pick the published name, it read the application'spackage.jsonto see which Prisma package was installed, and looked the name up in a table of Prisma's packages.A target built outside this repository is not in that table, so the private name was written as it was. Adding the package to the table would mean Prisma has to know about every target in advance.
What replaces it
The target package says where generated files import from, in the config, because the config is already the one place a target is installed. The design is recorded in
docs/architecture docs/adrs/ADR 323 - Generated files import from the module the target package names.md.The contract types module. A target package exports one module that re-exports everything a
contract.d.tsneeds: the framework's contract types, the family's, and the target's codec and operation types. ItsdefineConfigsetscontract.typesModuleto that module's name. The emitter writes one import statement from it. An application can import only from packages it depends on directly, which is why the generated file must name the target package and not the packages it is built from.Types that components declare. A target, adapter or extension declares the types it contributes, each with the module to import it from. Those declarations used to hold private names for the emitter to translate. Now each holds a name importable from outside. The helper
restateTypeDeclarations(descriptor, module)returns a copy of a descriptor whose declarations name the module given, so a target package points its target and adapter at its owncontract-typesmodule. It refuses a descriptor that would import one name from two modules.The migration module. A target's migration renderer used to hold the module name its
migration.tsimports from.renderTypeScriptnow takes it as an argument, and the CLI passes the config'smigrations.module.Imports as data. A family's
getFamilyImportsreturned lines of import text. It now returns import requirements, so the emitter merges everything from one module into one statement.Module names the loader refuses. An empty string, a path or a URL. Generated files are written into more than one folder (the contract output folder, and a snapshot folder beside each migration), so a relative path is right for at most one of them. A package-private name such as
#contract-typesworks and is what the extensions in this repository use for their own contracts.Stable output. Names in generated files were sorted by the machine's locale. They are now sorted by UTF-16 code unit, so output is the same on every machine.
Files generated earlier keep working. The modules they import are still exported. No command rewrites an existing migration or snapshot.
Changes in
packages/1-frameworkThe repository rule is not to change the framework domain without a decision. Will directed this change. What changed there: the two config members and their validation, the two error codes, the
getFamilyImportsandrenderTypeScriptsignatures, the removal of the manifest read (project-import-root.ts,CLI.PROJECT_MANIFEST_INVALID,CLI.PROJECT_MANIFEST_UNREADABLE) and of@prisma/orm-toolchain/publish-surface. No descriptor field, registry or runtime interface is added.Decisions made during the work
contract emitwarns about packages that are not installed by resolving each imported package from the output folder with Node's own resolution. It does not read a manifest.db migratefinds an unfinished migration without the config. It refuses a migration with no operations whosemigration.tsstill callsplaceholder(...). It recognisesplaceholderimported from any package, not only frommigrations.module, so a migration written by an earlier release is still caught.db migrate,db init,db updateanddb signneedcontract.typesModuleonly when they advance a ref, because only then do they write a contract type file.Left for later
Tests
test/integration/test/packaging/standin-target.test.tspacks the Prisma packages and a stand-in target that is in no list in this repository, installs them in an application outside the workspace, runscontract emitandmigration plan, typechecks withskipLibCheckoff, runs the plannedmigration.tsunder Node, and asserts no generated file names@internal/or@prisma/orm-framework.packages/9-public/@prisma/orm-framework/test/all-shells-tarball.test.tschecks every published package's built files for private names.upgrade-instructions/pending/target-packages-name-generated-file-modules/.By hand, in
examples/prisma-8-demo-sqlite:contract emitleaves the committed files unchanged,migration planwrites amigration.tsimporting from@prisma/orm-sqlite/migrationand a snapshot importing from@prisma/orm-sqlite/contract-types,db migrateapplies it, and a config withtypesModuleremoved fails withCONFIG.CONTRACT_TYPES_MODULE_MISSING.Alternatives considered
package.json. That is a second way to install an extension beside importing it in the config, and it keeps the CLI reading manifests.Fixes TML-3830. Closes TML-3143.
Agent: isildur-87
🤖 Generated with Claude Code