fix: log Prisma connection status on startup#163
Open
harshitaaa0 wants to merge 1 commit into
Open
Conversation
|
@harshitaaa0 is attempting to deploy a commit to the participationcorner2025-8967's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Codesense Ai: This PR is too large to review automatically. A human maintainer will take a look! |
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.
Description
During local development it wasn't obvious whether Prisma had connected successfully — there was no startup log confirming a healthy connection, and failures only surfaced later as confusing errors on the first database query.
The root cause was that
PrismaClientwas being instantiated separately in 23 different files across the codebase (nearly every route, plus a couple of services). With connections scattered like this, there was no single place to check or log connection status, and as a side effect every dev hot-reload spun up a new, un-closed connection pool.This PR:
app/utils/db.server.ts, a single shared Prisma client that calls$connect()explicitly on startup and logs a clear ✅ success message, or a ❌ message with actionable next steps (checkDATABASE_URL/DIRECT_URL, confirm the database is reachable, re-runnpx prisma generate) if the connection failsglobalThisin development so hot-reloads reuse the same connection instead of leaking new onesnew PrismaClient()to import the shared client from~/utils/db.serverinsteadLogging in only one of many scattered clients wouldn't reflect the app's real connection state, so consolidating to a single shared client was necessary to make the logging meaningful — this also resolves a related connection-pool leak in dev.
prisma/seed.tsandscripts/create-demo-user.tsare standalone one-off scripts and were intentionally left untouched.Related Issues
Fixes #<#83>
Type of Change
Checklist: