Fix: Create store only once in cli mode (#70391)

fix: create store only once in cli mode
This commit is contained in:
Serge Zaitsev 2023-06-20 17:28:42 +02:00 committed by GitHub
parent 03bf52b719
commit 47b2e7f1d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,15 +6,12 @@ import (
"github.com/urfave/cli/v2"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/datamigrations"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/secretsmigrations"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/server"
"github.com/grafana/grafana/pkg/services/sqlstore/migrations"
"github.com/grafana/grafana/pkg/setting"
)
@ -41,18 +38,7 @@ func runDbCommand(command func(commandLine utils.CommandLine, sqlStore db.DB) er
return fmt.Errorf("%v: %w", "failed to initialize runner", err)
}
tracer, err := tracing.ProvideService(runner.Cfg)
if err != nil {
return fmt.Errorf("%v: %w", "failed to initialize tracer service", err)
}
bus := bus.ProvideBus(tracer)
sqlStore, err := db.ProvideService(runner.Cfg, nil, &migrations.OSSMigrations{}, bus, tracer)
if err != nil {
return fmt.Errorf("%v: %w", "failed to initialize SQL store", err)
}
sqlStore := runner.SQLStore
if err := command(cmd, sqlStore); err != nil {
return err
}