-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove migrations for fields that have been since backrest 1.0.0 (…
- Loading branch information
1 parent
9205da1
commit 546482f
Showing
16 changed files
with
366 additions
and
723 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,45 @@ | ||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
|
||
v1 "github.com/garethgeorge/backrest/gen/go/v1" | ||
"go.uber.org/zap" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
var migrations = []func(*v1.Config){ | ||
migration001PrunePolicy, | ||
migration002Schedules, | ||
migration003RelativeScheduling, | ||
var migrations = []*func(*v1.Config){ | ||
&noop, // migration001PrunePolicy | ||
&noop, // migration002Schedules is deprecated | ||
&migration003RelativeScheduling, | ||
} | ||
|
||
var CurrentVersion = int32(len(migrations)) | ||
|
||
func ApplyMigrations(config *v1.Config) error { | ||
startMigration := int(config.Version - 1) | ||
if config.Version == 0 { | ||
if proto.Equal(config, &v1.Config{}) { | ||
config.Version = CurrentVersion | ||
return nil | ||
} | ||
return fmt.Errorf("config version 0 is invalid") | ||
} | ||
|
||
startMigration := int(config.Version) | ||
if startMigration < 0 { | ||
startMigration = 0 | ||
} | ||
|
||
for idx := startMigration; idx < len(migrations); idx += 1 { | ||
zap.S().Infof("applying config migration %d", idx+1) | ||
migrations[idx](config) | ||
m := migrations[idx] | ||
if m == &noop { | ||
return fmt.Errorf("config version %d is too old to migrate, please try first upgrading to backrest 1.4.0 which is the last version that may be compatible with your config", config.Version) | ||
} | ||
(*m)(config) | ||
} | ||
config.Version = CurrentVersion | ||
return nil | ||
} | ||
|
||
var noop = func(config *v1.Config) { | ||
// do nothing | ||
} |
Oops, something went wrong.