From 28d05d1d0ee6a8f671a2e039871449960370bd72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Sun, 3 Aug 2025 12:20:35 -0700 Subject: [PATCH] feat(database): add DATABASE_CONFIG_FILE env override Allow overriding default database.yaml paths via DATABASE_CONFIG_FILE environment variable. When set, uses single specified file instead of default ["database.yaml", "/vault/secrets/database.yaml"] search paths. Maintains backward compatibility when env var not set. --- database/config.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/database/config.go b/database/config.go index a4209a2..edf3f92 100644 --- a/database/config.go +++ b/database/config.go @@ -1,6 +1,7 @@ package database import ( + "os" "time" "github.com/prometheus/client_golang/prometheus" @@ -36,10 +37,20 @@ type ConfigOptions struct { ConnMaxLifetime time.Duration } +// getConfigFiles returns the list of config files to search for database configuration. +// If DATABASE_CONFIG_FILE environment variable is set, it returns that single file. +// Otherwise, it returns the default paths. +func getConfigFiles() []string { + if configFile := os.Getenv("DATABASE_CONFIG_FILE"); configFile != "" { + return []string{configFile} + } + return []string{"database.yaml", "/vault/secrets/database.yaml"} +} + // DefaultConfigOptions returns the standard configuration options used by API package func DefaultConfigOptions() ConfigOptions { return ConfigOptions{ - ConfigFiles: []string{"database.yaml", "/vault/secrets/database.yaml"}, + ConfigFiles: getConfigFiles(), EnablePoolMonitoring: true, PrometheusRegisterer: prometheus.DefaultRegisterer, MaxOpenConns: 25, @@ -51,7 +62,7 @@ func DefaultConfigOptions() ConfigOptions { // MonitorConfigOptions returns configuration options optimized for Monitor package func MonitorConfigOptions() ConfigOptions { return ConfigOptions{ - ConfigFiles: []string{"database.yaml", "/vault/secrets/database.yaml"}, + ConfigFiles: getConfigFiles(), EnablePoolMonitoring: false, // Monitor doesn't need metrics PrometheusRegisterer: nil, // No Prometheus dependency MaxOpenConns: 10,