From 8365b32199560f10a70c544c1688a742a257a9b9 Mon Sep 17 00:00:00 2001 From: Harish Marri Date: Thu, 1 Feb 2024 10:26:52 +0530 Subject: [PATCH] add v2.1 upgrade handler --- app/app.go | 3 ++- app/upgrades/v2.1/constants.go | 16 ++++++++++++++++ app/upgrades/v2.1/upgrades.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 app/upgrades/v2.1/constants.go create mode 100644 app/upgrades/v2.1/upgrades.go diff --git a/app/app.go b/app/app.go index f7e379be..6d91081f 100644 --- a/app/app.go +++ b/app/app.go @@ -51,6 +51,7 @@ import ( "github.com/OmniFlix/omniflixhub/v2/app/upgrades" v012 "github.com/OmniFlix/omniflixhub/v2/app/upgrades/v012" v2 "github.com/OmniFlix/omniflixhub/v2/app/upgrades/v2" + v2_1 "github.com/OmniFlix/omniflixhub/v2/app/upgrades/v2.1" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -72,7 +73,7 @@ func getGovProposalHandlers() []govclient.ProposalHandler { var ( // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string - Upgrades = []upgrades.Upgrade{v012.Upgrade, v2.Upgrade} + Upgrades = []upgrades.Upgrade{v012.Upgrade, v2.Upgrade, v2_1.Upgrade} Forks []upgrades.Fork ) diff --git a/app/upgrades/v2.1/constants.go b/app/upgrades/v2.1/constants.go new file mode 100644 index 00000000..5241edc8 --- /dev/null +++ b/app/upgrades/v2.1/constants.go @@ -0,0 +1,16 @@ +package v2_1 + +import ( + "github.com/OmniFlix/omniflixhub/v2/app/upgrades" + store "github.com/cosmos/cosmos-sdk/store/types" +) + +const UpgradeName = "v2.1" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateV2UpgradeHandler, + StoreUpgrades: store.StoreUpgrades{ + Added: []string{}, + }, +} diff --git a/app/upgrades/v2.1/upgrades.go b/app/upgrades/v2.1/upgrades.go new file mode 100644 index 00000000..0edf738f --- /dev/null +++ b/app/upgrades/v2.1/upgrades.go @@ -0,0 +1,28 @@ +package v2_1 + +import ( + "github.com/OmniFlix/omniflixhub/v2/app/keepers" + "github.com/OmniFlix/omniflixhub/v2/app/upgrades" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +func CreateV2UpgradeHandler( + mm *module.Manager, + cfg module.Configurator, + _ upgrades.BaseAppParamManager, + _ *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info("running migrations ...") + // Run migrations before applying any other state changes. + // NOTE: DO NOT PUT ANY STATE CHANGES BEFORE RunMigrations(). + versionMap, err := mm.RunMigrations(ctx, cfg, fromVM) + if err != nil { + return nil, err + } + ctx.Logger().Info("Upgrade complete") + return versionMap, nil + } +}