This project is a library used to have pallet-contracts
-like migration schema for Substrate pallets.
-
Add the following statements:
#[migratable::pallet]
in the pallet's module.#[migratable::config]
in the pallet's configuration.#[migratable::hooks]
in the pallet's hooks.
-
Declare the pallet's hooks impl block. There's no need to implement any function.
-
Make sure you add the corresponding storage version with the
#[pallet::storage_version()]
statement.
#[migratable::pallet]
#[frame_support::pallet]
pub mod pallet {
// -- snip --
#[migratable::config]
#[pallet::config]
pub trait Config: frame_system::Config {
// -- snip --
}
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);
#[migratable::hooks]
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
}
- When instantiating the pallet, make sure to add the migrations that apply. Some examples here.
impl my_pallet::Config for Runtime {
// -- snip --
type Migrations = (
my_pallet::migration::v2::Migration<Self>,
my_pallet::migration::v3::Migration<Self>,
my_pallet::migration::v4::Migration<Self>,
// add as many as needed
);
}
- Add the pallet's
Migration
struct toExecutive
:
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
// make sure to add here the migration
(
my_pallet::pallet::Migration<Runtime>,
),
>;