2020-12-07 20:36:43 +00:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
2021-09-21 18:11:16 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/cmd"
|
2021-09-16 09:46:29 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/runtime/tos"
|
2021-03-03 17:05:37 +00:00
|
|
|
validatordb "github.com/prysmaticlabs/prysm/validator/db"
|
|
|
|
"github.com/sirupsen/logrus"
|
2020-12-07 20:36:43 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
2021-03-03 17:05:37 +00:00
|
|
|
var log = logrus.WithField("prefix", "db")
|
|
|
|
|
|
|
|
// Commands for interacting with the Prysm validator database.
|
|
|
|
var Commands = &cli.Command{
|
2020-12-07 20:36:43 +00:00
|
|
|
Name: "db",
|
|
|
|
Category: "db",
|
2021-03-03 17:05:37 +00:00
|
|
|
Usage: "defines commands for interacting with the Prysm validator database",
|
2020-12-07 20:36:43 +00:00
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "restore",
|
|
|
|
Description: `restores a database from a backup file`,
|
|
|
|
Flags: cmd.WrapFlags([]cli.Flag{
|
|
|
|
cmd.RestoreSourceFileFlag,
|
|
|
|
cmd.RestoreTargetDirFlag,
|
|
|
|
}),
|
|
|
|
Before: tos.VerifyTosAcceptedOrPrompt,
|
|
|
|
Action: func(cliCtx *cli.Context) error {
|
2021-03-03 17:05:37 +00:00
|
|
|
if err := validatordb.Restore(cliCtx); err != nil {
|
2022-08-05 10:52:02 +00:00
|
|
|
log.WithError(err).Fatal("Could not restore database")
|
2020-12-07 20:36:43 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2021-01-15 21:35:21 +00:00
|
|
|
{
|
|
|
|
Name: "migrate",
|
|
|
|
Category: "db",
|
|
|
|
Usage: "Defines commands for running validator database migrations",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "up",
|
|
|
|
Usage: "Runs up migrations for the validator database",
|
|
|
|
Flags: cmd.WrapFlags([]cli.Flag{
|
|
|
|
cmd.DataDirFlag,
|
|
|
|
}),
|
|
|
|
Before: tos.VerifyTosAcceptedOrPrompt,
|
|
|
|
Action: func(cliCtx *cli.Context) error {
|
2021-03-03 17:05:37 +00:00
|
|
|
if err := validatordb.MigrateUp(cliCtx); err != nil {
|
2022-08-05 10:52:02 +00:00
|
|
|
log.WithError(err).Fatal("Could not run database migrations")
|
2021-01-15 21:35:21 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "down",
|
|
|
|
Usage: "Runs down migrations for the validator database",
|
|
|
|
Flags: cmd.WrapFlags([]cli.Flag{
|
|
|
|
cmd.DataDirFlag,
|
|
|
|
}),
|
|
|
|
Before: tos.VerifyTosAcceptedOrPrompt,
|
|
|
|
Action: func(cliCtx *cli.Context) error {
|
2021-03-03 17:05:37 +00:00
|
|
|
if err := validatordb.MigrateDown(cliCtx); err != nil {
|
2022-08-05 10:52:02 +00:00
|
|
|
log.WithError(err).Fatal("Could not run database migrations")
|
2021-01-15 21:35:21 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-12-07 20:36:43 +00:00
|
|
|
},
|
|
|
|
}
|