Files
sim/packages/db/connection-url.ts
T
Theodore Li 0613cebfab feat(db): resolve DATABASE_URL per role (DATABASE_URL_<ROLE> with fallback) (#5276)
* feat(db): resolve DATABASE_URL per role (DATABASE_URL_<ROLE> with fallback)

* fix(db): pin realtime process to SIM_DB_ROLE=realtime so both pools share 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.
2026-06-30 15:17:55 -04:00

13 lines
509 B
TypeScript

/**
* Resolve a connection URL for the active DB role, preferring the role-keyed
* variant (e.g. `DATABASE_URL_TRIGGER`) and falling back to the shared base.
* Lets each deploy point its surface at its own Postgres user + PgBouncer via
* env alone; unset keyed vars preserve the prior single-URL behavior.
*/
export function resolveDbUrl(
base: 'DATABASE_URL' | 'DATABASE_REPLICA_URL',
role: string
): string | undefined {
return process.env[`${base}_${role.toUpperCase()}`] ?? process.env[base]
}