mirror of https://github.com/grafana/grafana.git
SecretsManager: Conditionally lock DB before migrations using config setting (#106003)
Secrets: Conditionally lock DB before migrations using config setting (#105949) Co-authored-by: Matheus Macabu <macabu@users.noreply.github.com>
This commit is contained in:
parent
74b291d03b
commit
5401175562
|
@ -1,6 +1,8 @@
|
|||
package contracts
|
||||
|
||||
import "context"
|
||||
|
||||
// SecretDBMigrator is an interface for running database migrations related to secrets management.
|
||||
type SecretDBMigrator interface {
|
||||
RunMigrations() error
|
||||
RunMigrations(ctx context.Context, lockDatabase bool) error
|
||||
}
|
||||
|
|
|
@ -69,7 +69,10 @@ func RegisterAPIService(
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if err := secretDBMigrator.RunMigrations(); err != nil {
|
||||
// Some DBs that claim to be MySQL/Postgres-compatible might not support table locking.
|
||||
lockDatabase := cfg.Raw.Section("database").Key("migration_locking").MustBool(true)
|
||||
|
||||
if err := secretDBMigrator.RunMigrations(context.Background(), lockDatabase); err != nil {
|
||||
return nil, fmt.Errorf("running secret database migrations: %w", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package migrator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
|
@ -26,12 +27,12 @@ func NewWithEngine(db db.DB) contracts.SecretDBMigrator {
|
|||
return &SecretDB{engine: db.GetEngine()}
|
||||
}
|
||||
|
||||
func (db *SecretDB) RunMigrations() error {
|
||||
func (db *SecretDB) RunMigrations(ctx context.Context, lockDatabase bool) error {
|
||||
mg := migrator.NewScopedMigrator(db.engine, nil, "secret")
|
||||
|
||||
db.AddMigration(mg)
|
||||
|
||||
return mg.Start(true, 0)
|
||||
return mg.RunMigrations(ctx, lockDatabase, 0)
|
||||
}
|
||||
|
||||
func (*SecretDB) AddMigration(mg *migrator.Migrator) {
|
||||
|
|
Loading…
Reference in New Issue