From db513b43e71949a2d5b15d54d501dc8a98e0bd69 Mon Sep 17 00:00:00 2001 From: Owen Date: Sun, 28 Sep 2025 18:21:56 -0700 Subject: [PATCH] Make postgres connection string also a ENV var --- server/db/pg/driver.ts | 19 ++++++++++++++++--- server/lib/readConfigFile.ts | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/server/db/pg/driver.ts b/server/db/pg/driver.ts index c7c292f0..34d16aa1 100644 --- a/server/db/pg/driver.ts +++ b/server/db/pg/driver.ts @@ -7,9 +7,22 @@ function createDb() { const config = readConfigFile(); if (!config.postgres) { - throw new Error( - "Postgres configuration is missing in the configuration file." - ); + // check the environment variables for postgres config + if (process.env.POSTGRES_CONNECTION_STRING) { + config.postgres = { + connection_string: process.env.POSTGRES_CONNECTION_STRING + }; + if (process.env.POSTGRES_REPLICA_CONNECTION_STRINGS) { + const replicas = process.env.POSTGRES_REPLICA_CONNECTION_STRINGS.split(",").map((conn) => ({ + connection_string: conn.trim() + })); + config.postgres.replicas = replicas; + } + } else { + throw new Error( + "Postgres configuration is missing in the configuration file." + ); + } } const connectionString = config.postgres?.connection_string; diff --git a/server/lib/readConfigFile.ts b/server/lib/readConfigFile.ts index 918fa4c4..4ae80ac2 100644 --- a/server/lib/readConfigFile.ts +++ b/server/lib/readConfigFile.ts @@ -150,7 +150,7 @@ export const configSchema = z }), postgres: z .object({ - connection_string: z.string(), + connection_string: z.string().optional(), replicas: z .array( z.object({