You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.4 KiB

  1. package commands
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/spf13/cobra"
  6. cfg "github.com/tendermint/tendermint/config"
  7. "github.com/tendermint/tendermint/libs/log"
  8. "github.com/tendermint/tendermint/scripts/keymigrate"
  9. )
  10. func MakeKeyMigrateCommand(conf *cfg.Config, logger log.Logger) *cobra.Command {
  11. cmd := &cobra.Command{
  12. Use: "key-migrate",
  13. Short: "Run Database key migration",
  14. RunE: func(cmd *cobra.Command, args []string) error {
  15. ctx, cancel := context.WithCancel(cmd.Context())
  16. defer cancel()
  17. contexts := []string{
  18. // this is ordered to put the
  19. // (presumably) biggest/most important
  20. // subsets first.
  21. "blockstore",
  22. "state",
  23. "peerstore",
  24. "tx_index",
  25. "evidence",
  26. "light",
  27. }
  28. for idx, dbctx := range contexts {
  29. logger.Info("beginning a key migration",
  30. "dbctx", dbctx,
  31. "num", idx+1,
  32. "total", len(contexts),
  33. )
  34. db, err := cfg.DefaultDBProvider(&cfg.DBContext{
  35. ID: dbctx,
  36. Config: conf,
  37. })
  38. if err != nil {
  39. return fmt.Errorf("constructing database handle: %w", err)
  40. }
  41. if err = keymigrate.Migrate(ctx, db); err != nil {
  42. return fmt.Errorf("running migration for context %q: %w",
  43. dbctx, err)
  44. }
  45. }
  46. logger.Info("completed database migration successfully")
  47. return nil
  48. },
  49. }
  50. // allow database info to be overridden via cli
  51. addDBFlags(cmd, conf)
  52. return cmd
  53. }