Make postgres connection string also a ENV var

This commit is contained in:
Owen
2025-09-28 18:21:56 -07:00
parent 0167b30bf1
commit db513b43e7
2 changed files with 17 additions and 4 deletions

View File

@@ -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;

View File

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