Skip to content

fix(prisma): inherit database region from the project's default region - #2026

Open
kristof-siket wants to merge 1 commit into
alchemy-run:mainfrom
kristof-siket:fix/prisma-inherit-project-default-region
Open

kristof-siket wants to merge 1 commit into
alchemy-run:mainfrom
kristof-siket:fix/prisma-inherit-project-default-region

Conversation

@kristof-siket

Copy link
Copy Markdown
Contributor

Why

The Prisma Management API returns a defaultRegion on every project. When it creates a database with region: "inherit", the server uses that project region. It falls back to the default database's region only when the project has none.

Prisma.Database resolved "inherit" on the client and ignored the project region. It used only the region of the project's default database. This causes two problems today:

  • A project without a default database cannot deploy a database with region: "inherit". The deploy fails with "Cannot resolve Prisma database region 'inherit' because project ... has no default database region". Prisma Composer creates every database with "inherit", so these projects cannot deploy Composer apps. Users have to create a placeholder default database by hand.
  • If someone promotes a database in another region to be the default, the next deploy plans a replacement of every inherited database in the project. A replacement deletes the old database and creates a new one.

What changed

  • resolveDatabaseRegion in Prisma/Database.ts reads the project with getProject. It returns defaultRegion when it is not null.
  • When defaultRegion is null, it uses the default database's region as before. The error for multiple default databases is unchanged.
  • When neither exists, the error now says the project has no default region and no default database region.
  • The region JSDoc describes what "inherit" does.

Plan (diff) and reconcile both use this function, so they resolve the same region.

Other providers do not resolve "inherit" on the client. Prisma.App and Prisma.Compute leave the region out when it is not set, and the server picks the project region. Prisma.Bucket has no region prop. The local dev provider for Prisma.Database does not call the API, so it is not changed.

Tests

New unit tests in test/Prisma/ManagementLifecycle.test.ts run against the in-memory Management API:

  • The project region is set and there is no default database: the database is created in the project region.
  • A default database in another region is then added: the next deploy keeps the same database. It creates and deletes nothing.
  • The project region is null and there is no default database: the deploy fails with the new error and creates nothing.

The existing test for the fallback to the default database still passes. I renamed it to say what it tests.

Ran locally:

  • pnpm test test/Prisma/ManagementLifecycle.test.ts: 19 passed. The two new tests fail on main.
  • pnpm test test/Prisma: 408 passed, 10 skipped. The 34 failures are live tests that need Prisma or Neon credentials. One Next.js artifact test timed out under load and passes alone.
  • pnpm tsc -b, pnpm format:check, pnpm lint:providers, pnpm docs:check-jsdoc, and oxlint on the changed files pass.

I did not run the live Prisma tests, because they need credentials.

Compatibility

Projects without a defaultRegion behave exactly as before. For projects that have one, the API already falls back to the default database's region in that field, so the result matches today's in the common case. The result changes only when the project region differs from the default database's region. In that case alchemy now matches what the server does for "inherit".

🤖 Generated with Claude Code

A database with `region: "inherit"` now takes the project's
`defaultRegion` from the Management API. It falls back to the default
database's region only when the project has no default region. Before,
alchemy used only the default database, so a project without one could
not deploy inherited databases, and promoting a default database in
another region planned a replacement of every inherited database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kristof-siket
kristof-siket marked this pull request as ready for review October 6, 2026 10:16
@alchemy-version-bot

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

pnpm install https://pkg.alchemy.run/alchemy/pr:2026:c7b8089
@alchemy.run (6)
pnpm install https://pkg.alchemy.run/@alchemy.run/better-auth/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@alchemy.run/cloudflare-runtime/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@alchemy.run/node-utils/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@alchemy.run/floci/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@alchemy.run/pkg/pr:2026:c7b8089
@distilled.cloud (16)
pnpm install https://pkg.alchemy.run/@distilled.cloud/core/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/acme/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/aws/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/axiom/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/cloudflare/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/doppler/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/fly-io/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/github/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/hetzner/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/infisical/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/neon/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/prisma/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/planetscale/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/railway/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/stripe/pr:2026:c7b8089
pnpm install https://pkg.alchemy.run/@distilled.cloud/zerossl/pr:2026:c7b8089

Published Oct 6, 2026, 10:17 AM UTC. Expires Oct 13, 2026, 10:17 AM UTC, extended while this pull request is open.

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.

1 participant