Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(confix): allow customization of migration plan (backport #21202) #21268

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/confix/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

## [v0.1.2](https://github.com/cosmos/cosmos-sdk/releases/tag/tools/confix/v0.1.2) - 2024-08-13

* (confix) [#21202](https://github.com/cosmos/cosmos-sdk/pull/21202) Allow customization of migration `PlanBuilder`.

## [v0.1.1](https://github.com/cosmos/cosmos-sdk/releases/tag/tools/confix/v0.1.1) - 2023-12-11

* [#18496](https://github.com/cosmos/cosmos-sdk/pull/18496) Remove invalid non SDK config from app.toml migration templates.
Expand Down
18 changes: 13 additions & 5 deletions tools/confix/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,28 @@ const (
// MigrationMap defines a mapping from a version to a transformation plan.
type MigrationMap map[string]func(from *tomledit.Document, to string) transform.Plan

// loadDestConfigFile is the function signature to load the destination version
// configuration toml file.
type loadDestConfigFile func(to string) (*tomledit.Document, error)

var Migrations = MigrationMap{
"v0.45": NoPlan, // Confix supports only the current supported SDK version. So we do not support v0.44 -> v0.45.
"v0.46": PlanBuilder,
"v0.47": PlanBuilder,
"v0.50": PlanBuilder,
"v0.46": defaultPlanBuilder,
"v0.47": defaultPlanBuilder,
"v0.50": defaultPlanBuilder,
// "v0.xx.x": PlanBuilder, // add specific migration in case of configuration changes in minor versions
}

func defaultPlanBuilder(from *tomledit.Document, to string) transform.Plan {
return PlanBuilder(from, to, LoadLocalConfig)
}

// PlanBuilder is a function that returns a transformation plan for a given diff between two files.
func PlanBuilder(from *tomledit.Document, to string) transform.Plan {
func PlanBuilder(from *tomledit.Document, to string, loadFn loadDestConfigFile) transform.Plan {
plan := transform.Plan{}
deletedSections := map[string]bool{}

target, err := LoadLocalConfig(to)
target, err := loadFn(to)
if err != nil {
panic(fmt.Errorf("failed to parse file: %w. This file should have been valid", err))
}
Expand Down
Loading