-
Notifications
You must be signed in to change notification settings - Fork 871
Update docs to perform migrations with connection pooling and Prisma config #7266
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AmanVarshney01
merged 2 commits into
prisma-7
from
dc-6267-update-docs-to-perform-migrations-with-connection-pooling
Nov 17, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -336,29 +336,39 @@ datasource db { | |
|
|
||
| Connection poolers like [Prisma Accelerate](/accelerate) and PgBouncer prevent your application from exhausting the database's connection limit. | ||
|
|
||
| If you would like to use the Prisma CLI in order to perform other actions on your database ,e.g. migrations and introspection, you will need to add an environment variable that provides a direct connection to your database in the `datasource.directUrl` property in your Prisma schema: | ||
| To keep Prisma Client on the pooled connection while allowing Prisma CLI commands (for example, migrations or introspection) to connect directly, define two environment variables: | ||
|
|
||
| ```env file=.env highlight=4,5;add showLineNumbers | ||
| ```env file=.env highlight=4-6;add showLineNumbers | ||
| # Connection URL to your database using PgBouncer. | ||
| DATABASE_URL="postgres://root:[email protected]:54321/postgres?pgbouncer=true" | ||
|
|
||
| //add-start | ||
| # Direct connection URL to the database used for migrations | ||
| # Direct connection URL to the database used for Prisma CLI commands. | ||
| DIRECT_URL="postgres://root:[email protected]:5432/postgres" | ||
| //add-end | ||
| ``` | ||
|
|
||
| You can then update your `schema.prisma` to use the new direct URL: | ||
| Configure `prisma.config.ts` to point to the direct connection string. Prisma CLI commands always read from this configuration. | ||
|
|
||
| ```prisma file=schema.prisma highlight=4;add showLineNumbers | ||
| datasource db { | ||
| provider = "postgresql" | ||
| //add-next-line | ||
| directUrl = env("DIRECT_URL") | ||
| } | ||
| ```ts file=prisma.config.ts showLineNumbers | ||
| import 'dotenv/config' | ||
| import { defineConfig, env } from 'prisma/config' | ||
|
|
||
| export default defineConfig({ | ||
| schema: 'prisma/schema.prisma', | ||
| datasource: { | ||
| url: env('DIRECT_URL'), | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| More information about the `directUrl` field can be found [here](/orm/reference/prisma-schema-reference#fields). | ||
| At runtime, instantiate Prisma Client with a driver adapter (for example, `@prisma/adapter-pg`) that uses the pooled connection string: | ||
|
|
||
| ```ts file=src/db/client.ts showLineNumbers | ||
| import { PrismaClient } from '../prisma/generated/client' | ||
| import { PrismaPg } from '@prisma/adapter-pg' | ||
|
|
||
| const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) | ||
| export const prisma = new PrismaClient({ adapter }) | ||
| ``` | ||
|
|
||
| ### Prisma Accelerate | ||
|
|
||
|
|
||
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
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
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
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
Oops, something went wrong.
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.
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.
Keep wording consistent with prisma.config.ts.
Later, the Neon driver section states Migrate/Introspection/Studio “use the connection string defined in the Prisma schema.” With this PR we standardize on
prisma.config.tsfor CLI tools. Please update that sentence for consistency (and add a version note if needed).🤖 Prompt for AI Agents