Skip to content

Commit f705584

Browse files
GAtom22mergify[bot]
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) # Conflicts: # tools/confix/migrations.go
1 parent f7ee700 commit f705584

2 files changed

Lines changed: 51 additions & 0 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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ 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, planType 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.
28+
<<<<<<< HEAD
2429
"v0.46": PlanBuilder,
2530
"v0.47": PlanBuilder,
2631
"v0.50": PlanBuilder,
@@ -33,6 +38,48 @@ func PlanBuilder(from *tomledit.Document, to string) transform.Plan {
3338
deletedSections := map[string]bool{}
3439

3540
target, err := LoadLocalConfig(to)
41+
=======
42+
"v0.46": defaultPlanBuilder,
43+
"v0.47": defaultPlanBuilder,
44+
"v0.50": defaultPlanBuilder,
45+
"v0.52": defaultPlanBuilder,
46+
"v2": V2PlanBuilder,
47+
// "v0.xx.x": defaultPlanBuilder, // add specific migration in case of configuration changes in minor versions
48+
}
49+
50+
type v2KeyChangesMap map[string][]string
51+
52+
// list all the keys which are need to be modified in v2
53+
var v2KeyChanges = v2KeyChangesMap{
54+
"min-retain-blocks": []string{"comet.min-retain-blocks"},
55+
"index-events": []string{"comet.index-events"},
56+
"halt-height": []string{"comet.halt-height"},
57+
"halt-time": []string{"comet.halt-time"},
58+
"app-db-backend": []string{"store.app-db-backend"},
59+
"pruning-keep-recent": []string{
60+
"store.options.ss-pruning-option.keep-recent",
61+
"store.options.sc-pruning-option.keep-recent",
62+
},
63+
"pruning-interval": []string{
64+
"store.options.ss-pruning-option.interval",
65+
"store.options.sc-pruning-option.interval",
66+
},
67+
"iavl-cache-size": []string{"store.options.iavl-config.cache-size"},
68+
"iavl-disable-fastnode": []string{"store.options.iavl-config.skip-fast-storage-upgrade"},
69+
// Add other key mappings as needed
70+
}
71+
72+
func defaultPlanBuilder(from *tomledit.Document, to, planType string) (transform.Plan, *tomledit.Document) {
73+
return PlanBuilder(from, to, planType, LoadLocalConfig)
74+
}
75+
76+
// PlanBuilder is a function that returns a transformation plan for a given diff between two files.
77+
func PlanBuilder(from *tomledit.Document, to, planType string, loadFn loadDestConfigFile) (transform.Plan, *tomledit.Document) {
78+
plan := transform.Plan{}
79+
deletedSections := map[string]bool{}
80+
81+
target, err := loadFn(to, planType)
82+
>>>>>>> 1d7f891ea (feat(confix): allow customization of migration plan (#21202))
3683
if err != nil {
3784
panic(fmt.Errorf("failed to parse file: %w. This file should have been valid", err))
3885
}

0 commit comments

Comments
 (0)