In-Place Store Migrations allow your modules to upgrade to new versions that include breaking changes. This document outlines how to build modules to take advantage of this functionality.
Consensus Version
Successful upgrades of existing modules require eachAppModule
to implement the function ConsensusVersion() uint64
.
- The versions must be hard-coded by the module developer.
- The initial version must be set to 1.
Registering Migrations
To register the functionality that takes place during a module upgrade, you must register which migrations you want to take place. Migration registration takes place in theConfigurator
using the RegisterMigration
method. The AppModule
reference to the configurator is in the RegisterServices
method.
You can register one or more migrations. If you register more than one migration script, list the migrations in increasing order and ensure there are enough migrations that lead to the desired consensus version. For example, to migrate to version 3 of a module, register separate migrations for version 1 and version 2 as shown in the following example:
Migrator
as shown in this example:
x/bank/keeper/migrations.go
Writing Migration Scripts
To define the functionality that takes place during an upgrade, write a migration script and place the functions in amigrations/
directory. For example, to write migration scripts for the bank module, place the functions in x/bank/migrations/
. Use the recommended naming convention for these functions. For example, v2bank
is the script that migrates the package x/bank/migrations/v2
: