Skip to content

Commit ffe37f8

Browse files
GAtom22hieuvubk
authored andcommitted
feat(confix): allow customization of migration plan (#21202)
Co-authored-by: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> (cherry picked from commit 1d7f891)
1 parent 7373998 commit ffe37f8

2 files changed

Lines changed: 19 additions & 7 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+
### Features
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: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ const (
2121
// MigrationMap defines a mapping from a version to a transformation plan.
2222
type MigrationMap map[string]func(from *tomledit.Document, to, planType string) (transform.Plan, *tomledit.Document)
2323

24+
// loadDestConfigFile is the function signature to load the destination version
25+
// configuration toml file.
26+
type loadDestConfigFile func(to, planType string) (*tomledit.Document, error)
27+
2428
var Migrations = MigrationMap{
2529
"v0.45": NoPlan, // Confix supports only the current supported SDK version. So we do not support v0.44 -> v0.45.
26-
"v0.46": PlanBuilder,
27-
"v0.47": PlanBuilder,
28-
"v0.50": PlanBuilder,
29-
"v0.52": PlanBuilder,
30+
"v0.46": defaultPlanBuilder,
31+
"v0.47": defaultPlanBuilder,
32+
"v0.50": defaultPlanBuilder,
33+
"v0.52": defaultPlanBuilder,
3034
"v2": V2PlanBuilder,
31-
// "v0.xx.x": PlanBuilder, // add specific migration in case of configuration changes in minor versions
35+
// "v0.xx.x": defaultPlanBuilder, // add specific migration in case of configuration changes in minor versions
3236
}
3337

3438
type v2KeyChangesMap map[string][]string
@@ -53,12 +57,16 @@ var v2KeyChanges = v2KeyChangesMap{
5357
// Add other key mappings as needed
5458
}
5559

60+
func defaultPlanBuilder(from *tomledit.Document, to, planType string) (transform.Plan, *tomledit.Document) {
61+
return PlanBuilder(from, to, planType, LoadLocalConfig)
62+
}
63+
5664
// PlanBuilder is a function that returns a transformation plan for a given diff between two files.
57-
func PlanBuilder(from *tomledit.Document, to, planType string) (transform.Plan, *tomledit.Document) {
65+
func PlanBuilder(from *tomledit.Document, to, planType string, loadFn loadDestConfigFile) (transform.Plan, *tomledit.Document) {
5866
plan := transform.Plan{}
5967
deletedSections := map[string]bool{}
6068

61-
target, err := LoadLocalConfig(to, planType)
69+
target, err := loadFn(to, planType)
6270
if err != nil {
6371
panic(fmt.Errorf("failed to parse file: %w. This file should have been valid", err))
6472
}

0 commit comments

Comments
 (0)