Basics
Illustrates how to modify the storage for a specific pallet and prepare to migrate to the new storage layout.
Add the Nicks pallet locally
Create a storage struct and update storage item
/// The lookup table for names.
#[pallet::storage]
pub(super) type NameOf<T: Config> =
StorageMap<_, Twox64Concat, T::AccountId, (BoundedVec<u8, T::MaxLength>, BalanceOf<T>)>; #[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen, PartialEqNoBound, RuntimeDebug)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound())]
pub struct Nickname<T: Config> {
pub first: BoundedVec<u8, T::MaxLength>,
pub last: Option<BoundedVec<u8, T::MaxLength>>,
}Update functions
Add the storage version
Declare a migration module
Write migrate_to_v2
migrate_to_v2Check the storage version
Transform storage values
Update the storage version
Return the consumed weight
7. Use migrate_to_v2 in on_runtime_upgrade
migrate_to_v2 in on_runtime_upgradeUpdate unit tests
Examples
Resources
Last updated