Skip to content

Commit

Permalink
add 'ipfs repo migrate' command
Browse files Browse the repository at this point in the history
this command allows to run the repo migration without starting the
daemon.

fixes ipfs#7471
  • Loading branch information
zaibon committed Sep 7, 2020
1 parent 2ae5c52 commit bf789d6
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
"text/tabwriter"

humanize "github.com/dustin/go-humanize"
oldcmds "github.com/ipfs/go-ipfs/commands"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
migrate "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"

cid "github.com/ipfs/go-cid"
bstore "github.com/ipfs/go-ipfs-blockstore"
Expand All @@ -39,6 +41,7 @@ var RepoCmd = &cmds.Command{
"fsck": repoFsckCmd,
"version": repoVersionCmd,
"verify": repoVerifyCmd,
"migrate": repoMigrateCmd,
},
}

Expand All @@ -49,8 +52,9 @@ type GcResult struct {
}

const (
repoStreamErrorsOptionName = "stream-errors"
repoQuietOptionName = "quiet"
repoStreamErrorsOptionName = "stream-errors"
repoQuietOptionName = "quiet"
repoAllowDowngradeOptionName = "allow-downgrade"
)

var repoGcCmd = &cmds.Command{
Expand Down Expand Up @@ -371,3 +375,36 @@ var repoVersionCmd = &cmds.Command{
}),
},
}

var repoMigrateCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Apply any outstanding migrations to the repo.",
},
Options: []cmds.Option{
cmds.BoolOption(repoAllowDowngradeOptionName, "Allow downgrading to a lower repo version"),
},
NoRemote: true,
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
cctx := env.(*oldcmds.Context)

_, err := fsrepo.Open(cctx.ConfigRoot)
if err != fsrepo.ErrNeedMigration {
fmt.Println("Repo does not require migration")
return nil
}

fmt.Println("Found outdated fs-repo, starting migration.")

err = migrate.RunMigration(fsrepo.RepoVersion)
if err != nil {
fmt.Println("The migrations of fs-repo failed:")
fmt.Printf(" %s\n", err)
fmt.Println("If you think this is a bug, please file an issue and include this whole log output.")
fmt.Println(" https://github.com/ipfs/fs-repo-migrations")
return err
}

fmt.Println("Repo migrated successfully.")
return nil
},
}

0 comments on commit bf789d6

Please sign in to comment.