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.

resolves ipfs#7471
  • Loading branch information
zaibon authored and gammazero committed Sep 3, 2021
1 parent 65d570c commit 1e1c5e8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func TestCommands(t *testing.T) {
"/repo/stat",
"/repo/verify",
"/repo/version",
"/repo/migrate",
"/resolve",
"/shutdown",
"/stats",
Expand Down
43 changes: 40 additions & 3 deletions core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"sync"
"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"

humanize "github.com/dustin/go-humanize"
cid "github.com/ipfs/go-cid"
bstore "github.com/ipfs/go-ipfs-blockstore"
cmds "github.com/ipfs/go-ipfs-cmds"
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 @@ -375,3 +379,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 1e1c5e8

Please sign in to comment.