From fa7ea6ee0064c72db5223c1bfa38d61dac632101 Mon Sep 17 00:00:00 2001 From: maicon Date: Mon, 7 Apr 2025 17:23:47 -0300 Subject: [PATCH] UniStore: Add non interactive mode for CLI migration (#103407) Signed-off-by: Maicon Costa --- pkg/cmd/grafana-cli/commands/commands.go | 7 +++++++ .../datamigrations/to_unified_storage.go | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/pkg/cmd/grafana-cli/commands/commands.go b/pkg/cmd/grafana-cli/commands/commands.go index e977deb84eb..9e95f5220f6 100644 --- a/pkg/cmd/grafana-cli/commands/commands.go +++ b/pkg/cmd/grafana-cli/commands/commands.go @@ -148,6 +148,13 @@ var adminCommands = []*cli.Command{ Name: "to-unified-storage", Usage: "Migrates classic SQL data into unified storage", Action: runDbCommand(datamigrations.ToUnifiedStorage), + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "non-interactive", + Usage: "Non interactive mode. Just run the migration.", + Value: false, + }, + }, }, }, }, diff --git a/pkg/cmd/grafana-cli/commands/datamigrations/to_unified_storage.go b/pkg/cmd/grafana-cli/commands/datamigrations/to_unified_storage.go index 05c16edd255..913e6173b68 100644 --- a/pkg/cmd/grafana-cli/commands/datamigrations/to_unified_storage.go +++ b/pkg/cmd/grafana-cli/commands/datamigrations/to_unified_storage.go @@ -67,6 +67,26 @@ func ToUnifiedStorage(c utils.CommandLine, cfg *setting.Cfg, sqlStore db.DB) err nil, provisioning, sort.ProvideService(), ) + if c.Bool("non-interactive") { + client, err := newUnifiedClient(cfg, sqlStore) + if err != nil { + return err + } + + opts.Store = client + opts.BlobStore = client + rsp, err := migrator.Migrate(ctx, opts) + if err != nil { + return err + } + fmt.Printf("Unified storage export: %s\n", time.Since(start)) + if rsp != nil { + jj, _ := json.MarshalIndent(rsp, "", " ") + fmt.Printf("%s\n", string(jj)) + } + return nil + } + yes, err := promptYesNo(fmt.Sprintf("Count legacy resources for namespace: %s?", opts.Namespace)) if err != nil { return err