Skip to content

Commit

Permalink
migrate config to v5 (#1560)
Browse files Browse the repository at this point in the history
* migrate config to v5

* change default version
  • Loading branch information
LexLuthr committed Jul 11, 2023
1 parent 5d903fa commit 540b41b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion node/config/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var log = logging.Logger("cfg")

// CurrentVersion is the config version expected by Boost.
// We need to migrate the config file to this version.
const CurrentVersion = 4
const CurrentVersion = 5

type migrateUpFn = func(cfgPath string) (string, error)

Expand All @@ -24,6 +24,7 @@ var migrations = []migrateUpFn{
v1Tov2, // index 1 => version 2
v2Tov3, // index 2 => version 3
v3Tov4, // index 3 => version 4
v4Tov5, // index 4 => version 5
}

// This struct is used to get the config file version
Expand Down
28 changes: 28 additions & 0 deletions node/config/v4_to_v5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package config

import (
"fmt"
)

// Migrate from config version 4 to version 5
func v4Tov5(cfgPath string) (string, error) {
cfg, err := FromFile(cfgPath, DefaultBoost())
if err != nil {
return "", fmt.Errorf("parsing config file %s: %w", cfgPath, err)
}

boostCfg, ok := cfg.(*Boost)
if !ok {
return "", fmt.Errorf("unexpected config type %T: expected *config.Boost", cfg)
}

// Update the Boost config version
boostCfg.ConfigVersion = 5

bz, err := ConfigUpdate(boostCfg, DefaultBoost(), true, false)
if err != nil {
return "", fmt.Errorf("applying configuration: %w", err)
}

return string(bz), nil
}

0 comments on commit 540b41b

Please sign in to comment.