diff --git a/setup/base/base.go b/setup/base/base.go index 43f5e782c..0bab77ad8 100644 --- a/setup/base/base.go +++ b/setup/base/base.go @@ -194,17 +194,20 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base // have a separate database config of their own. var db *sql.DB var writer sqlutil.Writer - if cfg.Global.DatabaseOptions != nil && isMonolith { + if cfg.Global.DatabaseOptions.ConnectionString != "" && isMonolith { switch { case cfg.Global.DatabaseOptions.ConnectionString.IsSQLite(): writer = sqlutil.NewExclusiveWriter() default: writer = sqlutil.NewDummyWriter() } - db, err = sqlutil.Open(cfg.Global.DatabaseOptions, writer) + db, err = sqlutil.Open(&cfg.Global.DatabaseOptions, writer) if err != nil { logrus.WithError(err).Panic("Failed to set up global database connections") } + logrus.Info("Using global database connection pool") + } else { + logrus.Info("Not using global database connection pool") } // Ideally we would only use SkipClean on routes which we know can allow '/' but due to @@ -249,7 +252,7 @@ func (b *BaseDendrite) Close() error { // DatabaseConnection sets up a new database connection if appropriate, // or returns the global connection pool if not (monolith mode only). func (b *BaseDendrite) DatabaseConnection(dbProperties *config.DatabaseOptions, writer sqlutil.Writer) (*sql.DB, sqlutil.Writer, error) { - if dbProperties != nil || b == nil { + if dbProperties.ConnectionString != "" || b == nil { db, err := sqlutil.Open(dbProperties, writer) return db, writer, err } diff --git a/setup/config/config_global.go b/setup/config/config_global.go index c827d1da4..d609e2460 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -39,7 +39,7 @@ type Global struct { // connections will be used instead. This way we don't have to manage connection // counts on a per-component basis, but can instead do it for the entire monolith. // In a polylith deployment, this will be ignored. - DatabaseOptions *DatabaseOptions `yaml:"database"` + DatabaseOptions DatabaseOptions `yaml:"database"` // The server name to delegate server-server communications to, with optional port WellKnownServerName string `yaml:"well_known_server_name"`