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.
This commit is contained in:
parent
a774f92bf7
commit
28d05d1d0e
@ -1,6 +1,7 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@ -36,10 +37,20 @@ type ConfigOptions struct {
|
|||||||
ConnMaxLifetime time.Duration
|
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
|
// DefaultConfigOptions returns the standard configuration options used by API package
|
||||||
func DefaultConfigOptions() ConfigOptions {
|
func DefaultConfigOptions() ConfigOptions {
|
||||||
return ConfigOptions{
|
return ConfigOptions{
|
||||||
ConfigFiles: []string{"database.yaml", "/vault/secrets/database.yaml"},
|
ConfigFiles: getConfigFiles(),
|
||||||
EnablePoolMonitoring: true,
|
EnablePoolMonitoring: true,
|
||||||
PrometheusRegisterer: prometheus.DefaultRegisterer,
|
PrometheusRegisterer: prometheus.DefaultRegisterer,
|
||||||
MaxOpenConns: 25,
|
MaxOpenConns: 25,
|
||||||
@ -51,7 +62,7 @@ func DefaultConfigOptions() ConfigOptions {
|
|||||||
// MonitorConfigOptions returns configuration options optimized for Monitor package
|
// MonitorConfigOptions returns configuration options optimized for Monitor package
|
||||||
func MonitorConfigOptions() ConfigOptions {
|
func MonitorConfigOptions() ConfigOptions {
|
||||||
return ConfigOptions{
|
return ConfigOptions{
|
||||||
ConfigFiles: []string{"database.yaml", "/vault/secrets/database.yaml"},
|
ConfigFiles: getConfigFiles(),
|
||||||
EnablePoolMonitoring: false, // Monitor doesn't need metrics
|
EnablePoolMonitoring: false, // Monitor doesn't need metrics
|
||||||
PrometheusRegisterer: nil, // No Prometheus dependency
|
PrometheusRegisterer: nil, // No Prometheus dependency
|
||||||
MaxOpenConns: 10,
|
MaxOpenConns: 10,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user