Skip to content

fix: log Prisma connection status on startup - #163

Merged
rushikesh-bobade merged 1 commit into
rushikesh-bobade:mainfrom
harshitaaa0:fix/prisma-connection-logging
Aug 10, 2026
Merged

fix: log Prisma connection status on startup#163
rushikesh-bobade merged 1 commit into
rushikesh-bobade:mainfrom
harshitaaa0:fix/prisma-connection-logging

Conversation

@harshitaaa0

Copy link
Copy Markdown
Contributor

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 PrismaClient was 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:

  • Adds 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 (check DATABASE_URL/DIRECT_URL, confirm the database is reachable, re-run npx prisma generate) if the connection fails
  • Caches the client on globalThis in development so hot-reloads reuse the same connection instead of leaking new ones
  • Updates all 23 files that previously ran new PrismaClient() to import the shared client from ~/utils/db.server instead

Logging 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.ts and scripts/create-demo-user.ts are standalone one-off scripts and were intentionally left untouched.

Related Issues

Fixes #<#83>

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

@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.

@github-actions github-actions Bot added the ECSoC26 Required label for ECSOC Sentinel scoring label Jul 15, 2026
@github-actions

Copy link
Copy Markdown

Codesense Ai: This PR is too large to review automatically. A human maintainer will take a look!

@harshitaaa0

Copy link
Copy Markdown
Contributor Author

Can you please check the PR @rushikesh-bobade

@rushikesh-bobade

Copy link
Copy Markdown
Owner

Hey @harshitaaa0, welcome to the project and thank you for this fantastic first contribution!

You absolutely nailed the root cause here. Creating a new PrismaClient instance in every route is a classic anti-pattern that leads to massive connection pooling leaks during local development (HMR). Your implementation of the singleton in app/utils/db.server.ts using globalThis is the exact textbook solution we needed. The startup logging is also a massive DX improvement!

Everything about your code is approved. ✅

🔴 One Quick Fix Needed (Rebase)

Your branch was created from an older commit on main. Since then, we merged a massive database update (the new Listing model in PR #160).

Because your branch doesn't have those files, GitHub thinks you are trying to delete them! (You can see in the "Files changed" tab that your PR is trying to delete 20260721105841_add_listing_model and revert schema.prisma).

To fix this, you just need to rebase your branch on the latest main:

git fetch origin main
git rebase origin/main

You might get a small merge conflict in prisma/schema.prisma. Just make sure to keep the new Listing model stuff! Once you resolve it, force push your branch (git push -f).

As soon as that diff is clean, I will merge this immediately. Phenomenal work catching this architectural leak!

@harshitaaa0
harshitaaa0 force-pushed the fix/prisma-connection-logging branch from a19d420 to adde383 Compare August 9, 2026 17:46
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codesense Ai: This PR is too large to review automatically. A human maintainer will take a look!

@harshitaaa0

Copy link
Copy Markdown
Contributor Author

Hey, I have done the quick fix needed. @rushikesh-bobade

@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fliptrack Ready Ready Preview Aug 10, 2026 2:59pm

@rushikesh-bobade

Copy link
Copy Markdown
Owner

Perfect rebase! The diff is super clean and all the new main models are fully intact. This is a massive architectural improvement for our local development experience. Approving and merging now!

@rushikesh-bobade
rushikesh-bobade merged commit 53e9bbb into rushikesh-bobade:main Aug 10, 2026
4 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Congratulations @harshitaaa0! 🎉

Your Pull Request has been successfully merged! Thank you so much for your hard work and contribution to FlipTrack. We really appreciate it! 🚀

@rushikesh-bobade rushikesh-bobade added the bug Something isn't working label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ECSoC26-L1 ECSoC26 Required label for ECSOC Sentinel scoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants