feat(core): add migrations registering (#19370)
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
This commit is contained in:
co-authored by
Facundo Medica
parent
ac48269f98
commit
e15a0de251
@@ -1,6 +1,7 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/gogoproto/grpc"
|
||||
@@ -20,6 +21,8 @@ import (
|
||||
// their services in the RegisterServices method. It is designed to eventually
|
||||
// support module object capabilities isolation as described in
|
||||
// https://github.com/cosmos/cosmos-sdk/issues/7093
|
||||
// Deprecated: The Configurator is deprecated.
|
||||
// Preferably use core services for registering msg/query server and migrations.
|
||||
type Configurator interface {
|
||||
grpc.Server
|
||||
|
||||
@@ -45,6 +48,10 @@ type Configurator interface {
|
||||
// will panic. If the ConsensusVersion bump does not introduce any store
|
||||
// changes, then a no-op function must be registered here.
|
||||
RegisterMigration(moduleName string, fromVersion uint64, handler MigrationHandler) error
|
||||
|
||||
// Register registers an in-place store migration for a module.
|
||||
// It permits to register modules migrations that have migrated to serverv2 but still be compatible with baseapp.
|
||||
Register(moduleName string, fromVersion uint64, handler func(context.Context) error) error
|
||||
}
|
||||
|
||||
type configurator struct {
|
||||
@@ -119,6 +126,14 @@ func (c *configurator) RegisterMigration(moduleName string, fromVersion uint64,
|
||||
return nil
|
||||
}
|
||||
|
||||
// Register implements the Configurator.Register method
|
||||
// It allows to register modules migrations that have migrated to server/v2 but still be compatible with baseapp.
|
||||
func (c *configurator) Register(moduleName string, fromVersion uint64, handler func(context.Context) error) error {
|
||||
return c.RegisterMigration(moduleName, fromVersion, func(sdkCtx sdk.Context) error {
|
||||
return handler(sdkCtx)
|
||||
})
|
||||
}
|
||||
|
||||
// runModuleMigrations runs all in-place store migrations for one given module from a
|
||||
// version to another version.
|
||||
func (c *configurator) runModuleMigrations(ctx sdk.Context, moduleName string, fromVersion, toVersion uint64) error {
|
||||
|
||||
@@ -200,6 +200,13 @@ func (c coreAppModuleBasicAdaptor) RegisterServices(cfg Configurator) {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if module, ok := c.module.(appmodule.HasMigrations); ok {
|
||||
err := module.RegisterMigrations(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c coreAppModuleBasicAdaptor) IsOnePerModuleType() {}
|
||||
|
||||
@@ -467,6 +467,13 @@ func (m *Manager) RegisterServices(cfg Configurator) error {
|
||||
}
|
||||
}
|
||||
|
||||
if module, ok := module.(appmodule.HasMigrations); ok {
|
||||
err := module.RegisterMigrations(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Error() != nil {
|
||||
return cfg.Error()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user