From 0911832c0d09d739e4faeb78d59c64b8151894a3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 23 Jan 2024 21:53:58 +0100 Subject: [PATCH] feat(templates): scaffold module migrations --- .../base/x/{{moduleName}}/keeper/migrate.go.plush | 15 +++++++++++++++ .../base/x/{{moduleName}}/module/module.go.plush | 4 ++++ .../migrations/{{num}}/migrate.go.plush | 14 ++++++++++++++ ignite/templates/module/placeholders.go | 4 ++++ 4 files changed, 37 insertions(+) create mode 100644 ignite/templates/module/create/files/base/x/{{moduleName}}/keeper/migrate.go.plush create mode 100644 ignite/templates/module/create/files/migrations/x/{{moduleName}}/migrations/{{num}}/migrate.go.plush diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/keeper/migrate.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/keeper/migrate.go.plush new file mode 100644 index 0000000000..adcae50a24 --- /dev/null +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/keeper/migrate.go.plush @@ -0,0 +1,15 @@ +package keeper + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper *Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper *Keeper) Migrator { + return Migrator{ + keeper: keeper, + } +} + +// this line is used by starport scaffolding # migrations/migrator \ No newline at end of file diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush index 3cb2ced633..524ea6efe6 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush @@ -132,6 +132,10 @@ func NewAppModule( func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + + m := keeper.NewMigrator(am.keeper) + _ = m + // this line is used by starport scaffolding # migrations/register } // RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) diff --git a/ignite/templates/module/create/files/migrations/x/{{moduleName}}/migrations/{{num}}/migrate.go.plush b/ignite/templates/module/create/files/migrations/x/{{moduleName}}/migrations/{{num}}/migrate.go.plush new file mode 100644 index 0000000000..8fc37ac1da --- /dev/null +++ b/ignite/templates/module/create/files/migrations/x/{{moduleName}}/migrations/{{num}}/migrate.go.plush @@ -0,0 +1,14 @@ +package {{ num }} + +import ( + "context" + + corestoretypes "cosmossdk.io/core/store" + + "github.com/cosmos/cosmos-sdk/codec" +) + +// MigrateStore migrates the module to consensus version {{ num }}. +func MigrateStore(ctx context.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec) { + // Insert {{ num }} migration here. +} \ No newline at end of file diff --git a/ignite/templates/module/placeholders.go b/ignite/templates/module/placeholders.go index d8cf25041a..3c0406175a 100644 --- a/ignite/templates/module/placeholders.go +++ b/ignite/templates/module/placeholders.go @@ -27,4 +27,8 @@ const ( PlaceholderTypesGenesisValidField = "// this line is used by starport scaffolding # types/genesis/validField" PlaceholderGenesisTestState = "// this line is used by starport scaffolding # genesis/test/state" PlaceholderGenesisTestAssert = "// this line is used by starport scaffolding # genesis/test/assert" + + // Migrations + PlaceholderMigrationsRegister = "// this line is used by starport scaffolding # migrations/register" + PlaceholderMigrationsMigrator = "// this line is used by starport scaffolding # migrations/migrator" )