Skip to content

Commit 7306552

Browse files
mergify[bot]GAtom22julienrbrt
authored
feat(confix): allow customization of migration plan (backport #21202) (#21268)
Co-authored-by: Tom <54514587+GAtom22@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
1 parent f7ee700 commit 7306552

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

tools/confix/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
3131

3232
## [Unreleased]
3333

34+
## [v0.1.2](https://github.com/cosmos/cosmos-sdk/releases/tag/tools/confix/v0.1.2) - 2024-08-13
35+
36+
* (confix) [#21202](https://github.com/cosmos/cosmos-sdk/pull/21202) Allow customization of migration `PlanBuilder`.
37+
3438
## [v0.1.1](https://github.com/cosmos/cosmos-sdk/releases/tag/tools/confix/v0.1.1) - 2023-12-11
3539

3640
* [#18496](https://github.com/cosmos/cosmos-sdk/pull/18496) Remove invalid non SDK config from app.toml migration templates.

tools/confix/migrations.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,28 @@ const (
1919
// MigrationMap defines a mapping from a version to a transformation plan.
2020
type MigrationMap map[string]func(from *tomledit.Document, to string) transform.Plan
2121

22+
// loadDestConfigFile is the function signature to load the destination version
23+
// configuration toml file.
24+
type loadDestConfigFile func(to string) (*tomledit.Document, error)
25+
2226
var Migrations = MigrationMap{
2327
"v0.45": NoPlan, // Confix supports only the current supported SDK version. So we do not support v0.44 -> v0.45.
24-
"v0.46": PlanBuilder,
25-
"v0.47": PlanBuilder,
26-
"v0.50": PlanBuilder,
28+
"v0.46": defaultPlanBuilder,
29+
"v0.47": defaultPlanBuilder,
30+
"v0.50": defaultPlanBuilder,
2731
// "v0.xx.x": PlanBuilder, // add specific migration in case of configuration changes in minor versions
2832
}
2933

34+
func defaultPlanBuilder(from *tomledit.Document, to string) transform.Plan {
35+
return PlanBuilder(from, to, LoadLocalConfig)
36+
}
37+
3038
// PlanBuilder is a function that returns a transformation plan for a given diff between two files.
31-
func PlanBuilder(from *tomledit.Document, to string) transform.Plan {
39+
func PlanBuilder(from *tomledit.Document, to string, loadFn loadDestConfigFile) transform.Plan {
3240
plan := transform.Plan{}
3341
deletedSections := map[string]bool{}
3442

35-
target, err := LoadLocalConfig(to)
43+
target, err := loadFn(to)
3644
if err != nil {
3745
panic(fmt.Errorf("failed to parse file: %w. This file should have been valid", err))
3846
}

0 commit comments

Comments
 (0)