ORM config paths resolve against the file that declared them - #30128
Draft
wmadden-electric wants to merge 1 commit into
Draft
ORM config paths resolve against the file that declared them#30128wmadden-electric wants to merge 1 commit into
wmadden-electric wants to merge 1 commit into
Conversation
The unified CLI now discovers `prisma.config.ts` from the working directory up to the repo root and merges the files it finds, one key at a time. An `orm` section declared in `packages/db` therefore reaches a command run from the repo root — and resolving that section's `./migrations` or `./contract.json` against the working directory pointed at the wrong place. `@prisma/cli-engine` 0.3.0 hands a section validator the provenance of the value it validates: which file declared each top-level key. The `orm` section validator now uses it. `contract.source.inputs`, `contract.output` and `migrations.dir` resolve against the directory of the file that declared `contract` or `migrations`, each against its own file when the two came from different files. An absent `migrations` still defaults to `migrations/`, now beside the nearest declaring file rather than beside the caller. Absolute paths pass through untouched. Because the validator now returns absolute paths, `defineOrmCommand` no longer re-resolves the config it hands a handler, and its cwd-anchored `finalizeConfig` call is gone. `loadOrmConfig` returns the engine's new config shape: a chain of files rather than one file. This repo's bin reads a single `prisma.config.ts`, so the chain it returns holds that one file, and every key's provenance names it. `@internal/config-loader` now exports `finalizeContractConfig` and `finalizeMigrationsConfig`, the two halves of `finalizeConfig` the validator needs to resolve each key against its own directory. This needs `@prisma/cli-engine` 0.3.0, which is not published yet (prisma/prisma-cli#233), so the repo's checks stay red until the engine pin moves off 0.2.3. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io>
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
@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-mongo
@prisma/orm-postgres
@prisma/orm-sqlite
@prisma/orm-target-mongo
@prisma/orm-target-postgres
@prisma/orm-target-sqlite
@prisma/orm-toolchain
commit: |
Contributor
size-limit report 📦
|
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.
What this changes
The unified CLI now discovers
prisma.config.tsfrom the working directory up to the repo root and merges every file it finds, one key at a time. That means anormsection declared in, say,packages/db/prisma.config.tsnow reaches a command run from the repo root — and resolving that section's./migrationsor./contract.jsonagainst the working directory pointed at the wrong directory.@prisma/cli-engine0.3.0 gives a section validator the provenance of the value it validates: which file on the chain declared each top-level key. Theormsection validator now uses it.contract.source.inputs,contract.outputandmigrations.dirresolve against the directory of the config file that declaredcontractormigrations. When those two keys come from different files on the chain, each resolves against its own file.migrationsstill defaults tomigrations/, but now beside the nearest declaring file rather than beside the caller.defineOrmCommandno longer re-resolves the config it hands a handler. Its cwd-anchoredfinalizeConfigcall is gone.loadOrmConfigreturns the engine's new config shape — a chain of files rather than one file. This repo's bin reads a singleprisma.config.ts, so the chain holds that one file and every key's provenance names it.@internal/config-loadernow exportsfinalizeContractConfigandfinalizeMigrationsConfig, the two halves offinalizeConfigthe validator needs to resolve each key against its own directory.Verification
@prisma/cli-engine0.3.0 is not on npm yet, so this was verified against a locally packed 0.3.0 tarball wired in through a temporary pnpm override. The override and its lockfile churn were reverted before committing; the diff pins nothing new.Against the real 0.3.0 build:
@internal/cli:pnpm typecheckclean (source and tests),pnpm test1442 tests in 115 files, all passing.@internal/config-loader:pnpm typecheckclean, 46 tests passing.pnpm lint:deps,pnpm check:conformanceandbiome checkon the changed trees: clean.pnpm test:packagesacross the whole workspace: 1172 of 1176 test files pass. The failures are covered below.This does not go green yet
Two things have to happen before CI can pass, and neither belongs in this PR.
1.
@prisma/cli-engine0.3.0 has to publish (prisma/prisma-cli#233). Until then the pin stays at 0.2.3, whereSectionProvenancedoes not exist and the engine callsvalidatewith one argument. The change is inert and red either way, which is why this is a draft.2. The repo has to stop importing
defineConfig. 0.3.0 removes the deprecateddefineConfigalias from@prisma/cli-engine. 306 files in this repo — mostly test fixtures and exampleprisma.config.tsfiles — still imported it, and they fail at runtime under 0.3.0 withdefineConfig is not a function. That is what the two@internal/cli-telemetryfailures in the run above are.#30129 is the prerequisite for this PR and does that rename. It is mergeable today:
definePrismaConfighas existed since engine 0.2.0, and on the pinned 0.2.3 the two names are the same function object, so the sweep is behaviour-neutral. Merge #30129, then move the pin, then this PR goes green.The other two failures in that run are unrelated:
@prisma/orm-framework'smodule-identitytest tripped over a leftover gitignoredskills/prisma-8directory, and one@internal/adapter-postgresplanner test failed under parallel load and passes on its own.Follow-up worth noting
finalizeConfigin@internal/config-loadernow has no production caller — only its own tests. It resolves an entire config against a single directory, which is exactly the behaviour this PR removes. Deleting it (and its test file) is a reasonable cleanup, left out here to keep the diff readable.🤖 Generated with Claude Code