prysm-pulse/validator/db/migrate.go
Raul Jordan eebcd52ee6
Miscellaneous Packages from Shared Into Proper Folders (#9638)
* slashutil

* builds

* interop

* viz

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-09-21 18:11:16 +00:00

49 lines
1.2 KiB
Go

package db
import (
"context"
"path"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/cmd"
"github.com/prysmaticlabs/prysm/io/file"
"github.com/prysmaticlabs/prysm/validator/db/kv"
"github.com/urfave/cli/v2"
)
// MigrateUp for a validator database.
func MigrateUp(cliCtx *cli.Context) error {
dataDir := cliCtx.String(cmd.DataDirFlag.Name)
if !file.FileExists(path.Join(dataDir, kv.ProtectionDbFileName)) {
return errors.New("No validator db found at path, nothing to migrate")
}
ctx := context.Background()
log.Info("Opening DB")
validatorDB, err := kv.NewKVStore(ctx, dataDir, &kv.Config{})
if err != nil {
return err
}
log.Info("Running migrations")
return validatorDB.RunUpMigrations(ctx)
}
// MigrateDown for a validator database.
func MigrateDown(cliCtx *cli.Context) error {
dataDir := cliCtx.String(cmd.DataDirFlag.Name)
if !file.FileExists(path.Join(dataDir, kv.ProtectionDbFileName)) {
return errors.New("No validator db found at path, nothing to rollback")
}
ctx := context.Background()
log.Info("Opening DB")
validatorDB, err := kv.NewKVStore(ctx, dataDir, &kv.Config{})
if err != nil {
return err
}
log.Info("Running migrations")
return validatorDB.RunDownMigrations(ctx)
}