mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
* 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.
13 lines
509 B
TypeScript
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]
|
|
}
|