mirror of
https://github.com/fosrl/pangolin.git
synced 2026-09-15 23:30:17 +02:00
Support _FILE env vars
Closes https://github.com/fosrl/docs-v2/issues/141
This commit is contained in:
+13
-9
@@ -1,5 +1,6 @@
|
||||
import { drizzle as DrizzlePostgres } from "drizzle-orm/node-postgres";
|
||||
import { readConfigFile } from "@server/lib/readConfigFile";
|
||||
import { readEnvOrFile } from "@server/lib/getEnvOrYaml";
|
||||
import { withReplicas } from "drizzle-orm/pg-core";
|
||||
import { createPool } from "./poolConfig";
|
||||
|
||||
@@ -7,17 +8,20 @@ function createDb() {
|
||||
const config = readConfigFile();
|
||||
|
||||
// check the environment variables for postgres config first before the config file
|
||||
if (process.env.POSTGRES_CONNECTION_STRING) {
|
||||
const envConnectionString = readEnvOrFile("POSTGRES_CONNECTION_STRING");
|
||||
if (envConnectionString) {
|
||||
config.postgres = {
|
||||
connection_string: process.env.POSTGRES_CONNECTION_STRING
|
||||
connection_string: envConnectionString
|
||||
};
|
||||
if (process.env.POSTGRES_REPLICA_CONNECTION_STRINGS) {
|
||||
const replicas =
|
||||
process.env.POSTGRES_REPLICA_CONNECTION_STRINGS.split(",").map(
|
||||
(conn) => ({
|
||||
connection_string: conn.trim()
|
||||
})
|
||||
);
|
||||
const replicaConnectionStrings = readEnvOrFile(
|
||||
"POSTGRES_REPLICA_CONNECTION_STRINGS"
|
||||
);
|
||||
if (replicaConnectionStrings) {
|
||||
const replicas = replicaConnectionStrings
|
||||
.split(",")
|
||||
.map((conn) => ({
|
||||
connection_string: conn.trim()
|
||||
}));
|
||||
config.postgres.replicas = replicas;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { drizzle as DrizzlePostgres } from "drizzle-orm/node-postgres";
|
||||
import { readConfigFile } from "@server/lib/readConfigFile";
|
||||
import { readEnvOrFile } from "@server/lib/getEnvOrYaml";
|
||||
import { withReplicas } from "drizzle-orm/pg-core";
|
||||
import { build } from "@server/build";
|
||||
import { db as mainDb } from "./driver";
|
||||
@@ -17,7 +18,7 @@ function createLogsDb() {
|
||||
const logsConfig = config.postgres_logs;
|
||||
|
||||
// Check environment variable first
|
||||
let connectionString = process.env.POSTGRES_LOGS_CONNECTION_STRING;
|
||||
let connectionString = readEnvOrFile("POSTGRES_LOGS_CONNECTION_STRING");
|
||||
let replicaConnections: Array<{ connection_string: string }> = [];
|
||||
|
||||
if (!connectionString && logsConfig) {
|
||||
@@ -26,13 +27,15 @@ function createLogsDb() {
|
||||
}
|
||||
|
||||
// If POSTGRES_LOGS_REPLICA_CONNECTION_STRINGS is set, use it
|
||||
if (process.env.POSTGRES_LOGS_REPLICA_CONNECTION_STRINGS) {
|
||||
replicaConnections =
|
||||
process.env.POSTGRES_LOGS_REPLICA_CONNECTION_STRINGS.split(",").map(
|
||||
(conn) => ({
|
||||
connection_string: conn.trim()
|
||||
})
|
||||
);
|
||||
const replicaConnectionStrings = readEnvOrFile(
|
||||
"POSTGRES_LOGS_REPLICA_CONNECTION_STRINGS"
|
||||
);
|
||||
if (replicaConnectionStrings) {
|
||||
replicaConnections = replicaConnectionStrings
|
||||
.split(",")
|
||||
.map((conn) => ({
|
||||
connection_string: conn.trim()
|
||||
}));
|
||||
}
|
||||
|
||||
// If no logs database is configured, fall back to main database
|
||||
|
||||
Reference in New Issue
Block a user