diff --git a/cmd/icingadb/main.go b/cmd/icingadb/main.go index 1123d813..016f981f 100644 --- a/cmd/icingadb/main.go +++ b/cmd/icingadb/main.go @@ -74,9 +74,19 @@ func run() int { } logger.Info("Starting database schema auto import") + + db, err := cmd.Database(logs.GetChildLogger("database")) + if err != nil { + logger.Fatalw("Can't create database connection pool from config", zap.Error(err)) + } + db.SetMaxOpenConns(1) + if err := icingadb.ImportSchema(context.Background(), db, cmd.Flags.DatabaseSchemaDir); err != nil { logger.Fatalw("Can't import database schema", zap.Error(err)) } + + _ = db.Close() + logger.Info("The database schema was successfully imported") case err != nil: logger.Fatalf("%+v", err) diff --git a/pkg/icingadb/schema.go b/pkg/icingadb/schema.go index 608bb859..47dd1d13 100644 --- a/pkg/icingadb/schema.go +++ b/pkg/icingadb/schema.go @@ -80,6 +80,9 @@ func CheckSchema(ctx context.Context, db *database.DB) error { // ImportSchema performs an initial schema import in the db. // // This function assumes that no schema exists. So it should only be called after a prior CheckSchema call. +// +// Note: Running a schema file may have side effects, such as altering SQL system variables. Unless you are certain that +// the schema update will not interfere with future queries, consider using a dedicated database connection. func ImportSchema( ctx context.Context, db *database.DB,