Unfortunately, my attempt (see below) fails to decode the keys when iterating over the in-memory created MyMapOld
, at least when testing with the try-runtime
feature.
mod migration {
use crate::MyMap as MyMapNew;
#[storage_alias]
type MyMap = StorageMap<_, Blake2_128Concat, KeyTypeOld, V>;
#[storage_alias]
type MyMapTmp = StorageMap<_, Blake2_128Concat, KeyTypeOldMyEnum<KeyTypeOld, KeyTypeAddition>, V>;
pub struct MyMigration(PhantomData<P>);
impl<P: crate::pallet::Config> OnRuntimeUpgrade for MyMigration<P>{
fn on_runtime_upgrade() -> frame_support::weights::Weight {
// Should not write to same storage item during drain
// Thus, write to temporary storage and move at the end
MyMap::<P>::drain().for_each(|(key_old, value)| {
let key_new = MyEnum::<KeyTypeOld, KeyTypeAddition>::Old(key_old);
MyMapTmp::<R>::insert(key_new, value);
});
// Move items from MyMapTmp to MyMapNew similar to
// frame_support::storage::migration::move_storage_from_pallet
...
}
}