@@ -21,14 +21,18 @@ const (
2121// MigrationMap defines a mapping from a version to a transformation plan.
2222type 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+
2428var 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
3438type 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