migrate: Report why an migration cannot be applied

Just returning that `Migration upgrade cannot be applied: check failed`
is not too useful when running `migrate upgrade_repo_v2`.
This commit is contained in:
Michael Eischer
2022-09-03 11:49:31 +02:00
parent 6c69f08a7b
commit 8b4dd70013
5 changed files with 20 additions and 13 deletions
+6 -3
View File
@@ -45,7 +45,7 @@ func checkMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repos
found := false
for _, m := range migrations.All {
ok, err := m.Check(ctx, repo)
ok, _, err := m.Check(ctx, repo)
if err != nil {
return err
}
@@ -70,14 +70,17 @@ func applyMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repos
for _, name := range args {
for _, m := range migrations.All {
if m.Name() == name {
ok, err := m.Check(ctx, repo)
ok, reason, err := m.Check(ctx, repo)
if err != nil {
return err
}
if !ok {
if !opts.Force {
Warnf("migration %v cannot be applied: check failed\nIf you want to apply this migration anyway, re-run with option --force\n", m.Name())
if reason == "" {
reason = "check failed"
}
Warnf("migration %v cannot be applied: %v\nIf you want to apply this migration anyway, re-run with option --force\n", m.Name(), reason)
continue
}