fix production db

This commit is contained in:
root
2026-05-17 00:35:35 -04:00
parent 1294109c55
commit be98e3e65d
9 changed files with 150 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
const ENABLED_VALUES = new Set(['1', 'true', 'yes'])
function ensureDatabaseUrl(env = process.env) {
const shouldBuildFromPostgres = ENABLED_VALUES.has(
env.DATABASE_URL_FROM_POSTGRES?.trim().toLowerCase() ?? '',
)
if (!shouldBuildFromPostgres) {
return env.DATABASE_URL
}
if (!env.POSTGRES_PASSWORD) {
throw new Error('DATABASE_URL_FROM_POSTGRES is enabled but POSTGRES_PASSWORD is not set')
}
const user = env.POSTGRES_USER ?? 'postgres'
const password = env.POSTGRES_PASSWORD
const host = env.POSTGRES_HOST ?? 'postgres'
const port = env.POSTGRES_PORT ?? '5432'
const database = env.POSTGRES_DB ?? 'rentaldrivego'
env.DATABASE_URL = `postgresql://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${host}:${port}/${encodeURIComponent(database)}`
return env.DATABASE_URL
}
module.exports = {
ensureDatabaseUrl,
}