Skip to content

Commit

Permalink
Use Migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Feb 23, 2021
1 parent 30d9045 commit 828a41b
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 50 deletions.
19 changes: 10 additions & 9 deletions x/bank/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
v042 "github.com/cosmos/cosmos-sdk/x/bank/legacy/v042"
)

// MigrationKeeper is an interface that the keeper implements for handling
// in-place store migrations.
type MigrationKeeper interface {
// Migrate1 migrates the store from version 1 to 2.
Migrate1(ctx sdk.Context) error
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper BaseKeeper
}

var _ MigrationKeeper = (*BaseKeeper)(nil)
// NewMigrator returns a new Migrator.
func NewMigrator(keeper BaseKeeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate1 implements MigrationKeeper.Migrate1 method.
func (keeper BaseKeeper) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, keeper.storeKey)
// Migrate1 migrates from version 1 to 2.
func (m Migrator) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, m.keeper.storeKey)
}
4 changes: 3 additions & 1 deletion x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ type AppModule struct {
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.(keeper.BaseKeeper))
cfg.RegisterMigration(types.ModuleName, 1, func(ctx sdk.Context) error {
return am.keeper.(keeper.MigrationKeeper).Migrate1(ctx)
return m.Migrate1(ctx)
})
}

Expand Down
19 changes: 10 additions & 9 deletions x/distribution/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
v042 "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v042"
)

// MigrationKeeper is an interface that the keeper implements for handling
// in-place store migrations.
type MigrationKeeper interface {
// Migrate1 migrates the store from version 1 to 2.
Migrate1(ctx sdk.Context) error
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
}

var _ MigrationKeeper = (*Keeper)(nil)
// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate1 implements MigrationKeeper.Migrate1 method.
func (keeper Keeper) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, keeper.storeKey)
// Migrate1 migrates from version 1 to 2.
func (m Migrator) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, m.keeper.storeKey)
}
4 changes: 3 additions & 1 deletion x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
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)
cfg.RegisterMigration(types.ModuleName, 1, func(ctx sdk.Context) error {
return am.keeper.Migrate1(ctx)
return m.Migrate1(ctx)
})
}

Expand Down
19 changes: 10 additions & 9 deletions x/gov/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
v042 "github.com/cosmos/cosmos-sdk/x/gov/legacy/v042"
)

// MigrationKeeper is an interface that the keeper implements for handling
// in-place store migrations.
type MigrationKeeper interface {
// Migrate1 migrates the store from version 1 to 2.
Migrate1(ctx sdk.Context) error
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
}

var _ MigrationKeeper = (*Keeper)(nil)
// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate1 implements MigrationKeeper.Migrate1 method.
func (keeper Keeper) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, keeper.storeKey)
// Migrate1 migrates from version 1 to 2.
func (m Migrator) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, m.keeper.storeKey)
}
4 changes: 3 additions & 1 deletion x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)

m := keeper.Migrator{keeper: am.keeper}
cfg.RegisterMigration(types.ModuleName, 1, func(ctx sdk.Context) error {
return am.keeper.Migrate1(ctx)
return m.Migrate1(ctx)
})
}

Expand Down
19 changes: 10 additions & 9 deletions x/slashing/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
v042 "github.com/cosmos/cosmos-sdk/x/slashing/legacy/v042"
)

// MigrationKeeper is an interface that the keeper implements for handling
// in-place store migrations.
type MigrationKeeper interface {
// Migrate1 migrates the store from version 1 to 2.
Migrate1(ctx sdk.Context) error
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
}

var _ MigrationKeeper = (*Keeper)(nil)
// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate1 implements MigrationKeeper.Migrate1 method.
func (keeper Keeper) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, keeper.storeKey)
// Migrate1 migrates from version 1 to 2.
func (m Migrator) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, m.keeper.storeKey)
}
4 changes: 3 additions & 1 deletion x/slashing/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
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)
cfg.RegisterMigration(types.ModuleName, 1, func(ctx sdk.Context) error {
return am.keeper.Migrate1(ctx)
return m.Migrate1(ctx)
})
}

Expand Down
19 changes: 10 additions & 9 deletions x/staking/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
v042 "github.com/cosmos/cosmos-sdk/x/staking/legacy/v042"
)

// MigrationKeeper is an interface that the keeper implements for handling
// in-place store migrations.
type MigrationKeeper interface {
// Migrate1 migrates the store from version 1 to 2.
Migrate1(ctx sdk.Context) error
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
}

var _ MigrationKeeper = (*Keeper)(nil)
// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate1 implements MigrationKeeper.Migrate1 method.
func (keeper Keeper) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, keeper.storeKey)
// Migrate1 migrates from version 1 to 2.
func (m Migrator) Migrate1(ctx sdk.Context) error {
return v042.MigrateStore(ctx, m.keeper.storeKey)
}
4 changes: 3 additions & 1 deletion x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
querier := keeper.Querier{Keeper: am.keeper}
types.RegisterQueryServer(cfg.QueryServer(), querier)

m := keeper.NewMigrator(am.keeper)
cfg.RegisterMigration(types.ModuleName, 1, func(ctx sdk.Context) error {
return am.keeper.Migrate1(ctx)
return m.Migrate1(ctx)
})
}

Expand Down

0 comments on commit 828a41b

Please sign in to comment.