Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
Aaditya29112005 wants to merge1 commit intoprisma:main
base:main
Choose a base branch
Loading
fromAaditya29112005:prisma-fix

Conversation

@Aaditya29112005
Copy link

@Aaditya29112005Aaditya29112005 commentedDec 4, 2025
edited by coderabbitaibot
Loading

Fix: SQLite URLs With Query Parameters Should Not Create Invalid Filenames

This PR fixes an issue where SQLiteDATABASE_URL values containing connection parameters
(e.g.,file:./dev.db?connection_limit=1) caused Prisma to create a file literally named
dev.db?connection_limit=1 or triggered "Database not found" errors in Prisma Studio.

The Problem

ensureDatabaseExists previously parsed the SQLite URL incorrectly:

  • Everything afterfile: was treated as the file path.
  • Query parameters like?connection_limit=1 were 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 inpackages/migrate/src/utils/ensureDatabaseExists.ts ensure that SQLite URIs are sanitized:

  • InensureDatabaseExists: the URL is split on?, and only the file path portion is used for creating the database.
  • IngetDbLocation: query parameters are removed so CLI messages show a clean file path.

Changes Made

  • Modifiedpackages/migrate/src/utils/ensureDatabaseExists.ts.
  • Added a regression test in
    packages/migrate/src/utils/__tests__/ensureDatabaseExists.test.ts
    to validate correct path handling when query parameters are present.

Summary by CodeRabbit

Bug Fixes

  • Fixed SQLite database connection issues when URLs contain query parameters.
  • Improved database location handling for more reliable migration operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign ourContributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let usrecheck it.

@coderabbitai
Copy link
Contributor

coderabbitaibot commentedDec 4, 2025
edited
Loading

Walkthrough

The changes fix SQLite database creation by stripping query parameters from URLs when initializing databases and deriving credentials. A fallback return is also added toprettifyProvider with TypeScript casting for unknown providers.

Changes

Cohort / File(s)Change Summary
SQLite URL Parameter Handling
packages/migrate/src/utils/ensureDatabaseExists.ts
Strip query strings from SQLite URLs during database creation and credential derivation; updategetDbLocation to return URI up to the query delimiter; add TypeScript fallback cast inprettifyProvider

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 66.67% which is insufficient. The required threshold is 80.00%.You can run@coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title directly describes the main issue being fixed: Prisma Studio incorrectly interpreting SQLite database URLs with query parameters as filenames, which is the core change in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for usingCodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment@coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitaicoderabbitaibot left a 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 inprettifyProvider weakens type safety; consider a safer default strategy

The new fallback:

// Fallback for any other provider type to satisfy TypeScriptreturnproviderasPrettyProvider

satisfies TypeScript but can return strings that are not actually in thePrettyProvider union (e.g., ifConnectorType is extended or a value is misconfigured), which undermines the usefulness of thePrettyProvider type and hides missingswitch cases that would otherwise be caught as compile‑time errors.

Safer alternatives you might consider:

  • Keep the switch exhaustive and add anassertNever(provider)‑style default that fails to compile whenConnectorType changes, or
  • Widen the return type (andDatasourceInfo.prettyProvider) tostring orPrettyProvider | string, and in the default branch returnprovider without a type assertion, or
  • Add an explicit'Unknown'/'Other' entry toPrettyProvider and 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

📥 Commits

Reviewing files that changed from the base of the PR and betweenf99bd52 andd54e709.

📒 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 scenarios

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-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 behavior

Returningcredentials.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 theurlToCreate change above and resolves the Studio/db creation mismatch.

Comment on lines +149 to +152
// 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)){
Copy link
Contributor

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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@coderabbitaicoderabbitai[bot]coderabbitai[bot] left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@Aaditya29112005@CLAassistant

[8]ページ先頭

©2009-2025 Movatter.jp