Skip to content

Commit c458c1d

Browse files
fix(db): throw on invalid SIM_DB_ROLE instead of silently using web pools
1 parent 590bfcb commit c458c1d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

packages/db/db.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ export const DB_POOL_PROFILES = {
2222

2323
type DbRole = keyof typeof DB_POOL_PROFILES
2424

25-
const role = process.env.SIM_DB_ROLE as DbRole | undefined
26-
const profile = (role && DB_POOL_PROFILES[role]) || DB_POOL_PROFILES.web
25+
const roleEnv = process.env.SIM_DB_ROLE?.trim()
26+
if (roleEnv && !(roleEnv in DB_POOL_PROFILES)) {
27+
throw new Error(
28+
`Invalid SIM_DB_ROLE '${roleEnv}' — expected one of ${Object.keys(DB_POOL_PROFILES).join(', ')} (or unset for web)`
29+
)
30+
}
31+
const profile = DB_POOL_PROFILES[(roleEnv as DbRole) || 'web']
2732

2833
const poolOptions = {
2934
prepare: false,

0 commit comments

Comments
 (0)