Skip to content

Commit c74a4e2

Browse files
authored
Merge pull request #480 from jshufro/jms/v2/fixMigration
Fix a few bugs with the migration
2 parents a37e59f + 31f87ae commit c74a4e2

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

src/shared/config/migration/migration-manager.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ type ConfigUpgrader struct {
2020
UpgradeFunc func(serializedConfig map[string]any) (map[string]any, error)
2121
}
2222

23-
func UpdateConfig(serializedConfig map[string]any) error {
23+
func UpdateConfig(serializedConfig map[string]any) (map[string]any, error) {
2424

2525
// Get the config's version
2626
configVersion, err := getVersionFromConfig(serializedConfig)
2727
if err != nil {
28-
return err
28+
return nil, err
2929
}
3030

3131
// Create versions
3232
v1, err := parseVersion(v1LegacyVersionMax)
3333
if err != nil {
34-
return err
34+
return nil, err
3535
}
3636

3737
// Create the collection of upgraders
@@ -52,19 +52,19 @@ func UpdateConfig(serializedConfig map[string]any) error {
5252

5353
// If there are no upgrades to apply, return
5454
if targetIndex == -1 {
55-
return nil
55+
return serializedConfig, nil
5656
}
5757

5858
// If there are upgrades, start at the first applicable index and apply them all in series
5959
for i := targetIndex; i < len(upgraders); i++ {
6060
upgrader := upgraders[i]
6161
serializedConfig, err = upgrader.UpgradeFunc(serializedConfig)
6262
if err != nil {
63-
return fmt.Errorf("error applying upgrade for config version %s: %w", upgrader.Version.String(), err)
63+
return nil, fmt.Errorf("error applying upgrade for config version %s: %w", upgrader.Version.String(), err)
6464
}
6565
}
6666

67-
return nil
67+
return serializedConfig, nil
6868

6969
}
7070

@@ -94,12 +94,12 @@ func getVersionFromConfig(serializedConfig map[string]any) (*version.Version, er
9494
if !ok {
9595
return nil, fmt.Errorf("detected a Smart Node v1 config; it has an entry named [%s.%s] but it is not a string, it's a %s", legacyRootConfigName, legacyVersionKey, reflect.TypeOf(configVersionEntry))
9696
}
97-
}
98-
99-
var ok bool
100-
configVersionString, ok = configVersionEntry.(string)
101-
if !ok {
102-
return nil, fmt.Errorf("config has an entry named [%s] but it is not a string, it's a %s", ids.VersionID, reflect.TypeOf(configVersionEntry))
97+
} else {
98+
var ok bool
99+
configVersionString, ok = configVersionEntry.(string)
100+
if !ok {
101+
return nil, fmt.Errorf("config has an entry named [%s] but it is not a string, it's a %s", ids.VersionID, reflect.TypeOf(configVersionEntry))
102+
}
103103
}
104104

105105
configVersion, err := version.NewVersion(strings.TrimPrefix(configVersionString, "v"))

src/shared/config/smartnode-config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,9 @@ func (cfg *SmartNodeConfig) Serialize() map[string]any {
516516

517517
// Deserializes a settings file into this config
518518
func (cfg *SmartNodeConfig) Deserialize(masterMap map[string]any) error {
519+
var err error
519520
// Upgrade the config to the latest version
520-
err := migration.UpdateConfig(masterMap)
521+
masterMap, err = migration.UpdateConfig(masterMap)
521522
if err != nil {
522523
return fmt.Errorf("error upgrading configuration to v%s: %w", shared.RocketPoolVersion, err)
523524
}

0 commit comments

Comments
 (0)