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 #21202

Merged
merged 5 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]

### Features

* (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
22 changes: 15 additions & 7 deletions tools/confix/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ const (
// MigrationMap defines a mapping from a version to a transformation plan.
type MigrationMap map[string]func(from *tomledit.Document, to, planType string) (transform.Plan, *tomledit.Document)

// loadDestConfigFile is the function signature to load the destination version
// configuration toml file.
type loadDestConfigFile func(to, planType 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.52": PlanBuilder,
"v0.46": defaultPlanBuilder,
"v0.47": defaultPlanBuilder,
"v0.50": defaultPlanBuilder,
"v0.52": defaultPlanBuilder,
"v2": V2PlanBuilder,
// "v0.xx.x": PlanBuilder, // add specific migration in case of configuration changes in minor versions
// "v0.xx.x": defaultPlanBuilder, // add specific migration in case of configuration changes in minor versions
}

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

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

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

target, err := LoadLocalConfig(to, planType)
target, err := loadFn(to, planType)
GAtom22 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
panic(fmt.Errorf("failed to parse file: %w. This file should have been valid", err))
}
Expand Down
Loading