pallet_uniques/migration.rs
1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Various pieces of common functionality.
19use super::*;
20use core::marker::PhantomData;
21use frame_support::traits::{Get, UncheckedOnRuntimeUpgrade};
22
23mod v1 {
24 use super::*;
25
26 /// Actual implementation of the storage migration.
27 pub struct UncheckedMigrateToV1Impl<T, I>(PhantomData<(T, I)>);
28
29 impl<T: Config<I>, I: 'static> UncheckedOnRuntimeUpgrade for UncheckedMigrateToV1Impl<T, I> {
30 fn on_runtime_upgrade() -> frame_support::weights::Weight {
31 let mut count = 0;
32 for (collection, detail) in Collection::<T, I>::iter() {
33 CollectionAccount::<T, I>::insert(&detail.owner, &collection, ());
34 count += 1;
35 }
36
37 log::info!(
38 target: LOG_TARGET,
39 "Storage migration v1 for uniques finished.",
40 );
41
42 // calculate and return migration weights
43 T::DbWeight::get().reads_writes(count as u64 + 1, count as u64 + 1)
44 }
45 }
46}
47
48/// Migrate the pallet storage from `0` to `1`.
49pub type MigrateV0ToV1<T, I> = frame_support::migrations::VersionedMigration<
50 0,
51 1,
52 v1::UncheckedMigrateToV1Impl<T, I>,
53 Pallet<T, I>,
54 <T as frame_system::Config>::DbWeight,
55>;