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({