Skip to content
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

fix: fix too many clients error on Postgres due to HMR with Drizzle #1766

Merged

Conversation

fuegoio
Copy link
Contributor

@fuegoio fuegoio commented Feb 20, 2024

✅ Checklist

  • I have followed every step in the contributing guide (updated 2022-10-06).
  • The PR title follows the convention we established conventional-commit
  • I performed a functional test on my final commit

Changelog

  • Add a singleton for Postgres connection with Drizzle to avoid creating a new connection on every Hot Reload

With Drizzle and a Postgres connection, we always had the issue of having too many clients already because of the HMR (see https://www.answeroverflow.com/m/1146224610002600067).

Having a singleton to fix that seems to be the best way.

Happy to implement this logic on other databases if needed, or write some tests, but I did not know if the approach would be accepted!

Thanks for your work :)

Copy link

changeset-bot bot commented Feb 20, 2024

🦋 Changeset detected

Latest commit: 011de02

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-t3-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
create-t3-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 1, 2024 4:28pm

Copy link

vercel bot commented Feb 20, 2024

@fuegoio is attempting to deploy a commit to the t3-oss Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@juliusmarminge juliusmarminge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use a similar pattern that we do for prisma to keep code consistency?

https://github.com/t3-oss/create-t3-app/blob/main/cli/template/extras/src/server/db/db-prisma.ts

@fuegoio
Copy link
Contributor Author

fuegoio commented Feb 20, 2024

Should we use a similar pattern that we do for prisma to keep code consistency?

https://github.com/t3-oss/create-t3-app/blob/main/cli/template/extras/src/server/db/db-prisma.ts

You're right I did not see it sorry, changed it on all drizzle databases as well for consistency.

Copy link
Member

@juliusmarminge juliusmarminge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - asked the Drizzle team for their opinion on the change too so will wait with merge until I hear back from them

@fuegoio
Copy link
Contributor Author

fuegoio commented Mar 1, 2024

Changed it to only cache the connection instead of the whole drizzle client instance, clearer you are right ;)

@juliusmarminge juliusmarminge added this pull request to the merge queue Mar 1, 2024
Merged via the queue into t3-oss:main with commit d7695df Mar 1, 2024
266 of 267 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📌 area: cli Relates to the CLI 📌 area: t3-app Relates to the generated T3 App
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants