Fix production DB connectivity by using Prisma Accelerate correctly#23
Merged
Fix production DB connectivity by using Prisma Accelerate correctly#23
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Production was configured with a Prisma Accelerate
DATABASE_URL, but the API runtime was treating that value like a direct PostgreSQL connection string viapg+@prisma/adapter-pg. That left the app booted and serving non-database routes while every Prisma-backed endpoint returned 500.This PR fixes the runtime split so production uses Prisma Accelerate correctly, while development and test continue using direct PostgreSQL connections.
Root Cause
The deployed service had a
DATABASE_URLwith theprisma+postgres:/// Accelerate format.The current runtime path in
src/db/prisma.tsinstantiated Prisma throughPrismaPg, which expects a direct PostgreSQL connection string. As a result, database-backed handlers failed at runtime even though the process itself still responded successfully on/,/health,/openapi.json, and/api-docs.What Changed
@prisma/extension-accelerateand use it in production.production:new PrismaClient({ accelerateUrl: DATABASE_URL }).$extends(withAccelerate())PrismaPgwith a direct PostgreSQL connection.DIRECT_DATABASE_URLsupport for migrations and any raw direct DB access.prisma.config.tsso Prisma CLI prefersDIRECT_DATABASE_URLwhen present.db:migratefail fast with a clear error if an Accelerate-only environment is missingDIRECT_DATABASE_URL.503responses for DB/Accelerate connectivity failures/healthnow reports database readiness explicitly.env.exampleandREADME.md.Verification
pnpm build.env:SELECT 1viacheckDatabaseConnection()I did not run the full Jest suite because this workspace does not currently have a direct local PostgreSQL URL configured for the non-production path.
Deploy Notes
Production env:
NODE_ENV=productionDATABASE_URL=<Prisma Accelerate URL>DIRECT_DATABASE_URL=<direct postgres URL>only if the deployment runspnpm db:migrateDevelopment / test env:
DATABASE_URL, or setDIRECT_DATABASE_URLExpected Outcome
After deploy, the production service should stop timing out on database-backed routes and resume serving
/v1/*and/api/*successfully through Prisma Accelerate.