- Notifications
You must be signed in to change notification settings - Fork2k
fix Prisma studio interprets database url as filename#28847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
CLAassistant commentedDec 4, 2025
|
coderabbitaibot commentedDec 4, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
WalkthroughThe changes fix SQLite database creation by stripping query parameters from URLs when initializing databases and deriving credentials. A fallback return is also added to Changes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for usingCodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/migrate/src/utils/ensureDatabaseExists.ts (1)
198-217:Fallback cast inprettifyProviderweakens type safety; consider a safer default strategyThe new fallback:
// Fallback for any other provider type to satisfy TypeScriptreturnproviderasPrettyProvidersatisfies TypeScript but can return strings that are not actually in the
PrettyProviderunion (e.g., ifConnectorTypeis extended or a value is misconfigured), which undermines the usefulness of thePrettyProvidertype and hides missingswitchcases that would otherwise be caught as compile‑time errors.Safer alternatives you might consider:
- Keep the switch exhaustive and add an
assertNever(provider)‑style default that fails to compile whenConnectorTypechanges, or- Widen the return type (and
DatasourceInfo.prettyProvider) tostringorPrettyProvider | string, and in the default branch returnproviderwithout a type assertion, or- Add an explicit
'Unknown'/'Other'entry toPrettyProviderand return that instead of casting.Any of these avoids the unsound cast while still satisfying TypeScript.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
packages/migrate/src/utils/ensureDatabaseExists.ts(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript for new code in the Prisma monorepo
Files:
packages/migrate/src/utils/ensureDatabaseExists.ts
🧠 Learnings (4)
📚 Learning: 2025-12-03T09:46:36.091Z
Learnt from: CRRepo: prisma/prisma PR: 0File: AGENTS.md:0-0Timestamp: 2025-12-03T09:46:36.091ZLearning: Applies to packages/migrate/src/__tests__/fixtures/**/*.config.ts : CLI test fixtures should provide `prisma.config.ts` per schema variant (e.g., `invalid-url.config.ts` next to `prisma/invalid-url.prisma`)Applied to files:
packages/migrate/src/utils/ensureDatabaseExists.ts
📚 Learning: 2025-12-03T09:46:36.091Z
Learnt from: CRRepo: prisma/prisma PR: 0File: AGENTS.md:0-0Timestamp: 2025-12-03T09:46:36.091ZLearning: Applies to packages/migrate/src/__tests__/**/*.test.ts : Use `ctx.setDatasource()` test helper to override config.datasource for connection-specific test scenariosApplied to files:
packages/migrate/src/utils/ensureDatabaseExists.ts
📚 Learning: 2025-12-03T09:46:36.091Z
Learnt from: CRRepo: prisma/prisma PR: 0File: AGENTS.md:0-0Timestamp: 2025-12-03T09:46:36.091ZLearning: Applies to packages/client-generator-js/src/TSClient/PrismaClient.ts : In PrismaClient constructor options, update generated types in `packages/client-generator-js/src/TSClient/PrismaClient.ts` (`buildClientOptions` method)Applied to files:
packages/migrate/src/utils/ensureDatabaseExists.ts
📚 Learning: 2025-12-03T09:46:36.091Z
Learnt from: CRRepo: prisma/prisma PR: 0File: AGENTS.md:0-0Timestamp: 2025-12-03T09:46:36.091ZLearning: Applies to packages/client/src/runtime/core/engines/common/Engine.ts : In PrismaClient constructor options, update engine config in `EngineConfig` interface in `packages/client/src/runtime/core/engines/common/Engine.ts`Applied to files:
packages/migrate/src/utils/ensureDatabaseExists.ts
🧬 Code graph analysis (1)
packages/migrate/src/utils/ensureDatabaseExists.ts (1)
packages/internals/src/index.ts (1)
createDatabase(55-55)
🔇 Additional comments (1)
packages/migrate/src/utils/ensureDatabaseExists.ts (1)
175-178:Stripping query params from SQLite dbLocation is aligned with filesystem behaviorReturning
credentials.uri!.split('?')[0]fortype === 'sqlite'makes the reported database location match the actual file path on disk and avoids confusing CLI output likefile:./dev.db?connection_limit=1. This is consistent with theurlToCreatechange above and resolves the Studio/db creation mismatch.
| // For SQLite, we want to make sure we don't create a file with the query string in the name | ||
| consturlToCreate=provider==='sqlite' ?url.split('?')[0] :url | ||
| if(awaitcreateDatabase(urlToCreate,pathResolutionRoot)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
🧹 Nitpick |🔵 Trivial
SQLite URL sanitization looks correct; consider centralizing query stripping
UsingurlToCreate = provider === 'sqlite' ? url.split('?')[0] : url ensures the filesystem path for SQLite does not include query parameters, whileuriToCredentials(url) still sees the full URL so connection options are preserved. That behavior matches the intent of the fix.
You now have the samesplit('?')[0] logic here and ingetDbLocation; if this pattern spreads further, consider a small helper (e.g.stripUrlQuery(url)) or reusing the sanitized URL for SQLite-related path computations to avoid duplication and keep semantics aligned.
Also applies to: 158-168
🤖 Prompt for AI Agents
packages/migrate/src/utils/ensureDatabaseExists.ts around lines 149-152 and158-168: the code duplicates the sqlite query-stripping logic(url.split('?')[0]) in multiple places; create a small helper function (e.g.,stripUrlQuery(url: string): string) in this module (or a shared utils file) thatreturns url.split('?')[0] for sqlite-style handling and call that helperwherever you currently inline the split, replacing duplicated logic so sqlitepath computation and any other places share the same sanitized URL behavior.
Uh oh!
There was an error while loading.Please reload this page.
Fix: SQLite URLs With Query Parameters Should Not Create Invalid Filenames
This PR fixes an issue where SQLite
DATABASE_URLvalues containing connection parameters(e.g.,
file:./dev.db?connection_limit=1) caused Prisma to create a file literally nameddev.db?connection_limit=1or triggered "Database not found" errors in Prisma Studio.The Problem
ensureDatabaseExistspreviously parsed the SQLite URL incorrectly:file:was treated as the file path.?connection_limit=1were mistakenly included in the filename.Example
Input:
Old Behavior:
Creates a file named:
Expected Behavior:
Create a file named:
while still applying the connection parameters to the client connection.
The Solution
Updates made in
packages/migrate/src/utils/ensureDatabaseExists.tsensure that SQLite URIs are sanitized:ensureDatabaseExists: the URL is split on?, and only the file path portion is used for creating the database.getDbLocation: query parameters are removed so CLI messages show a clean file path.Changes Made
packages/migrate/src/utils/ensureDatabaseExists.ts.packages/migrate/src/utils/__tests__/ensureDatabaseExists.test.tsto validate correct path handling when query parameters are present.
Summary by CodeRabbit
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.