github.com/Finschia/finschia-sdk@v0.48.1/x/collection/keeper/migrations.go (about)

     1  package keeper
     2  
     3  import (
     4  	sdk "github.com/Finschia/finschia-sdk/types"
     5  	"github.com/Finschia/finschia-sdk/types/module"
     6  	"github.com/Finschia/finschia-sdk/x/collection"
     7  	v2 "github.com/Finschia/finschia-sdk/x/collection/keeper/migrations/v2"
     8  )
     9  
    10  // Migrator is a struct for handling in-place store migrations.
    11  type Migrator struct {
    12  	keeper Keeper
    13  }
    14  
    15  // NewMigrator returns a new Migrator.
    16  func NewMigrator(keeper Keeper) Migrator {
    17  	return Migrator{keeper: keeper}
    18  }
    19  
    20  func (m Migrator) Register(register func(moduleName string, fromVersion uint64, handler module.MigrationHandler) error) error {
    21  	for fromVersion, handler := range map[uint64]module.MigrationHandler{
    22  		1: func(ctx sdk.Context) error {
    23  			return v2.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
    24  		},
    25  	} {
    26  		if err := register(collection.ModuleName, fromVersion, handler); err != nil {
    27  			return err
    28  		}
    29  	}
    30  
    31  	return nil
    32  }