diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/config/config.go | 27 | ||||
-rw-r--r-- | internal/config/helpers.gen.go | 25 | ||||
-rw-r--r-- | internal/db/bundb/bundb.go | 7 |
3 files changed, 46 insertions, 13 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 79f74cf71..4bb9be0c4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -60,19 +60,20 @@ type Configuration struct { TrustedProxies []string `name:"trusted-proxies" usage:"Proxies to trust when parsing x-forwarded headers into real IPs."` SoftwareVersion string `name:"software-version" usage:""` - DbType string `name:"db-type" usage:"Database type: eg., postgres"` - DbAddress string `name:"db-address" usage:"Database ipv4 address, hostname, or filename"` - DbPort int `name:"db-port" usage:"Database port"` - DbUser string `name:"db-user" usage:"Database username"` - DbPassword string `name:"db-password" usage:"Database password"` - DbDatabase string `name:"db-database" usage:"Database name"` - DbTLSMode string `name:"db-tls-mode" usage:"Database tls mode"` - DbTLSCACert string `name:"db-tls-ca-cert" usage:"Path to CA cert for db tls connection"` - DbMaxOpenConnsMultiplier int `name:"db-max-open-conns-multiplier" usage:"Multiplier to use per cpu for max open database connections. 0 or less is normalized to 1."` - DbSqliteJournalMode string `name:"db-sqlite-journal-mode" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_journal_mode"` - DbSqliteSynchronous string `name:"db-sqlite-synchronous" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_synchronous"` - DbSqliteCacheSize bytesize.Size `name:"db-sqlite-cache-size" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_cache_size"` - DbSqliteBusyTimeout time.Duration `name:"db-sqlite-busy-timeout" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_busy_timeout"` + DbType string `name:"db-type" usage:"Database type: eg., postgres"` + DbAddress string `name:"db-address" usage:"Database ipv4 address, hostname, or filename"` + DbPort int `name:"db-port" usage:"Database port"` + DbUser string `name:"db-user" usage:"Database username"` + DbPassword string `name:"db-password" usage:"Database password"` + DbDatabase string `name:"db-database" usage:"Database name"` + DbTLSMode string `name:"db-tls-mode" usage:"Database tls mode"` + DbTLSCACert string `name:"db-tls-ca-cert" usage:"Path to CA cert for db tls connection"` + DbMaxOpenConnsMultiplier int `name:"db-max-open-conns-multiplier" usage:"Multiplier to use per cpu for max open database connections. 0 or less is normalized to 1."` + DbSqliteJournalMode string `name:"db-sqlite-journal-mode" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_journal_mode"` + DbSqliteSynchronous string `name:"db-sqlite-synchronous" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_synchronous"` + DbSqliteCacheSize bytesize.Size `name:"db-sqlite-cache-size" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_cache_size"` + DbSqliteBusyTimeout time.Duration `name:"db-sqlite-busy-timeout" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_busy_timeout"` + DbPostgresConnectionString string `name:"db-postgres-connection-string" usage:"Full Database URL for connection to postgres"` WebTemplateBaseDir string `name:"web-template-base-dir" usage:"Basedir for html templating files for rendering pages and composing emails."` WebAssetBaseDir string `name:"web-asset-base-dir" usage:"Directory to serve static assets from, accessible at example.org/assets/"` diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index d75956963..f176676e5 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -700,6 +700,31 @@ func GetDbSqliteBusyTimeout() time.Duration { return global.GetDbSqliteBusyTimeo // SetDbSqliteBusyTimeout safely sets the value for global configuration 'DbSqliteBusyTimeout' field func SetDbSqliteBusyTimeout(v time.Duration) { global.SetDbSqliteBusyTimeout(v) } +// GetDbPostgresConnectionString safely fetches the Configuration value for state's 'DbPostgresConnectionString' field +func (st *ConfigState) GetDbPostgresConnectionString() (v string) { + st.mutex.RLock() + v = st.config.DbPostgresConnectionString + st.mutex.RUnlock() + return +} + +// SetDbPostgresConnectionString safely sets the Configuration value for state's 'DbPostgresConnectionString' field +func (st *ConfigState) SetDbPostgresConnectionString(v string) { + st.mutex.Lock() + defer st.mutex.Unlock() + st.config.DbPostgresConnectionString = v + st.reloadToViper() +} + +// DbPostgresConnectionStringFlag returns the flag name for the 'DbPostgresConnectionString' field +func DbPostgresConnectionStringFlag() string { return "db-postgres-connection-string" } + +// GetDbPostgresConnectionString safely fetches the value for global configuration 'DbPostgresConnectionString' field +func GetDbPostgresConnectionString() string { return global.GetDbPostgresConnectionString() } + +// SetDbPostgresConnectionString safely sets the value for global configuration 'DbPostgresConnectionString' field +func SetDbPostgresConnectionString(v string) { global.SetDbPostgresConnectionString(v) } + // GetWebTemplateBaseDir safely fetches the Configuration value for state's 'WebTemplateBaseDir' field func (st *ConfigState) GetWebTemplateBaseDir() (v string) { st.mutex.RLock() diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go index d5071d141..0e58cb7fb 100644 --- a/internal/db/bundb/bundb.go +++ b/internal/db/bundb/bundb.go @@ -396,6 +396,13 @@ func maxOpenConns() int { // deriveBunDBPGOptions takes an application config and returns either a ready-to-use set of options // with sensible defaults, or an error if it's not satisfied by the provided config. func deriveBunDBPGOptions() (*pgx.ConnConfig, error) { + url := config.GetDbPostgresConnectionString() + + // if database URL is defined, ignore other DB related configuration fields + if url != "" { + cfg, err := pgx.ParseConfig(url) + return cfg, err + } // these are all optional, the db adapter figures out defaults address := config.GetDbAddress() |