feat(db): resolve DATABASE_URL per role (DATABASE_URL_<ROLE> with fallback)#5276
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview
Realtime sets Reviewed by Cursor Bugbot for commit 6cdb5a6. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 98c5fdd. Configure here.
Greptile SummaryThis PR adds role-based database URL resolution for each runtime surface. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "fix(db): pin realtime process to SIM_DB_..." | Re-trigger Greptile |
…hare the role Without it, the realtime process left SIM_DB_ROLE unset: the shared @sim/db client defaulted role to 'web' (web pool profile + DATABASE_URL_WEB) while socketDb used 'realtime', so the two pools diverged after cutover. Set it at the process level (bootstrap + dev/start scripts), mirroring DB_APP_NAME, so the shared client and socketDb both resolve the realtime profile and URL.
|
Addressed the Bugbot + Greptile finding (realtime dual-pool role split) in 6cdb5a6. Root cause (real bug): the realtime process never set Fix: pin
Now both realtime pools (shared |
|
@greptile review |

Summary
@sim/dbnow resolves its connection URL per runtime role:DATABASE_URL_<ROLE>(e.g.DATABASE_URL_TRIGGER) when set, falling back to the existingDATABASE_URL— same for the replica (DATABASE_REPLICA_URL_<ROLE>).resolveDbUrl(base, role)inpackages/db/connection-url.ts, consumed by bothpackages/db/db.ts(primary + replica) and the realtimesocketDb(apps/realtime/.../operations.ts) — so both realtime pools land on the realtime URL when set.SIM_DB_ROLEselector (already merged), so the URL and the pool-size profile always agree.@sim/dbreadsprocess.envdirectly).How the cutover works
Provision the users + bouncers (inert), ship this (no-op), then flip one surface at a time by populating its keyed var + restart; roll back by clearing it (falls back to
DATABASE_URL/ the old pooler). Trigger readsDATABASE_URL_TRIGGERfrom its trigger.dev env.Type of Change
Testing
Tested manually. New
packages/dbunit tests forresolveDbUrl(keyed-preferred, base-fallback, undefined-when-unset, replica variant, role uppercasing).bun run lint,check:api-validation:strict,@sim/dbvitest (24/24), andpackages/db+@sim/realtimetypechecks all pass.Checklist