fix(migrate): confirm before migration

This commit is contained in:
iyear 2023-12-23 16:07:12 +08:00
parent 21803a9357
commit 52e140f502

View File

@ -11,6 +11,17 @@ import (
)
func Migrate(ctx context.Context, to map[string]string) error {
var confirm bool
if err := survey.AskOne(&survey.Confirm{
Message: "It will overwrite the namespace data in the destination storage, continue?",
Default: false,
}, &confirm); err != nil {
return errors.Wrap(err, "confirm")
}
if !confirm {
return nil
}
meta, err := kv.From(ctx).MigrateTo()
if err != nil {
return errors.Wrap(err, "read data")
@ -21,17 +32,6 @@ func Migrate(ctx context.Context, to map[string]string) error {
return errors.Wrap(err, "create dest storage")
}
var confirm bool
if err = survey.AskOne(&survey.Confirm{
Message: "It will overwrite the namespace data in the destination storage, continue?",
Default: false,
}, &confirm); err != nil {
return errors.Wrap(err, "confirm")
}
if !confirm {
return nil
}
if err = dest.MigrateFrom(meta); err != nil {
return errors.Wrap(err, "migrate from")
}