Skip to content

Migrate prisma init --db to new connection model#29283

Open
kristof-siket wants to merge 7 commits intomainfrom
tml-1927-migrate-prisma-init-db-from-deprecated-connection-fields-to
Open

Migrate prisma init --db to new connection model#29283
kristof-siket wants to merge 7 commits intomainfrom
tml-1927-migrate-prisma-init-db-from-deprecated-connection-fields-to

Conversation

@kristof-siket
Copy link

@kristof-siket kristof-siket commented Mar 2, 2026

Summary

Migrates prisma init --db from reading deprecated database.directConnection fields to the new connections[].endpoints.direct.connectionString from the Management API response (TML-1927).

  • Reads the connection string directly from connections[].endpoints.direct.connectionString — no manual DSN construction needed
  • Throws if no connection string is found (no legacy fallback — the API always returns the new fields)
  • Bumps @prisma/management-api-sdk from 0.2.0 to 1.12.0 to get the new connection model types
  • Updates SDK import names to match v1.12.0 exports (ManagementAPI -> ManagementApiSdk, createManagementAPI -> createManagementApiSdk)
  • Bumps hono from 4.11.7 to 4.12.3 to fix IP spoofing authentication bypass vulnerability

Context

The Management API shipped a new connection model in PR #3365. The deprecated fields (directConnection, apiKeys) will be removed after a deprecation window. This migration ensures prisma init --db works with the new response shape.

Related: PTL-1046 — same migration for prisma/create-db (PR #80)

Test plan

  • prisma init --db creates a project and returns a valid connection string (manual test against production API)
  • Existing CI tests pass

Closes TML-1927

Summary by CodeRabbit

  • Bug Fixes

    • Improved database connection detection to prefer available endpoint types and surface a clearer error when no connection string is found.
  • Chores

    • Updated management API integration to the newer SDK surface.
    • Bumped devDependencies: @prisma/management-api-sdk to v1.12.0 and hono to v4.12.3.

…onnection model

Read the connection string from `connections[0].endpoints.direct.connectionString`
instead of manually constructing a DSN from `database.directConnection` fields.
Falls back to the legacy `directConnection` path when `connections` is absent or
endpoints lack a `connectionString`, for backward compatibility with older API versions.

Also bumps `@prisma/management-api-sdk` from 0.2.0 to 1.12.0, which includes the
new connection model types and renames the SDK exports:
- `ManagementAPI` -> `ManagementApiSdk`
- `createManagementAPI` -> `createManagementApiSdk`

Closes TML-1927
@CLAassistant
Copy link

CLAassistant commented Mar 2, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Update @prisma/management-api-sdk devDependency; rename SDK types/functions to the new API surface; refactor Init to prefer project.database.connections endpoints (direct then pooled) for the connection string and throw if none is found.

Changes

Cohort / File(s) Summary
Dependency Update
packages/cli/package.json
Bump devDependency @prisma/management-api-sdk from 0.2.0 to 1.12.0; also update hono version.
SDK API Migration
packages/cli/src/management-api/auth-client.ts, packages/cli/src/management-api/auth.ts
Rename imports/types and factory to match new SDK surface: ManagementAPIManagementApiSdk, createManagementAPIcreateManagementApiSdk; update function return/type annotations and initialization calls.
Connection String Extraction
packages/cli/src/Init.ts
Replace unconditional use of project.database.directConnection with logic that searches project.database.connections for an endpoint direct or pooled and uses its connectionString; remove prior fallback and throw Missing connection string in response if none found.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: migrating the prisma init --db command to use the Management API's new connection model, which is reflected throughout the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tml-1927-migrate-prisma-init-db-from-deprecated-connection-fields-to

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

The API doesn't guarantee ordering of connections[], so the first entry
might be an accelerate connection without direct/pooled endpoints.
Use .find() to locate a connection that has a connectionString available,
and also try pooled endpoint before falling back to legacy directConnection.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

size-limit report 📦

Path Size
packages/client/runtime/index-browser.js 2.23 KB (0%)
packages/client/runtime/index-browser.d.ts 3.28 KB (0%)
packages/cli/build/index.js 2.5 MB (+0.01% 🔺)
packages/client/prisma-client-0.0.0.tgz 26.81 MB (+0.01% 🔺)
packages/cli/prisma-0.0.0.tgz 12.84 MB (+0.01% 🔺)
packages/bundle-size/da-workers-libsql/output.tgz 1.33 MB (0%)
packages/bundle-size/da-workers-neon/output.tgz 1.39 MB (0%)
packages/bundle-size/da-workers-pg/output.tgz 1.38 MB (0%)
packages/bundle-size/da-workers-planetscale/output.tgz 1.33 MB (0%)
packages/bundle-size/da-workers-d1/output.tgz 1.3 MB (0%)

kristof-siket and others added 3 commits March 2, 2026 13:17
Use connectionString directly from the connections endpoint array.
Drop the directConnection fallback — the API always returns
the connections array with connectionString populated.
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 2, 2026

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 30 skipped benchmarks1


Comparing tml-1927-migrate-prisma-init-db-from-deprecated-connection-fields-to (87e8626) with main (6738298)

Open in CodSpeed

Footnotes

  1. 30 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Fixes IP spoofing authentication bypass vulnerability (GHSA-xxxxx).
The previous override (>=4.11.10) allowed 4.12.0-4.12.1 which are
vulnerable to authentication bypass by IP spoofing (GHSA-xh87-mx6m-69f3).
The transitive dependency @prisma/dev>hono resolved to a version in
that range.
"overrides": {
"form-data": ">=4.0.4",
"hono": ">=4.11.10",
"hono": ">=4.12.2",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to pnpm audit issue

@kristof-siket kristof-siket requested a review from FGoessler March 2, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants