Skip to content

Commit

Permalink
Count migrated items
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriqueNogara committed Aug 12, 2024
1 parent 44d5e0b commit 699fc20
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 2 deletions.
34 changes: 32 additions & 2 deletions pallets/asset/src/checkpoint/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,83 +62,113 @@ pub(crate) fn migrate_to_v2<T: Config>() {

// Removes all elements in the old storage and inserts it in the new storage

let mut count = 0;
log::info!("Updating types for the TotalSupply storage");
v1::TotalSupply::drain().for_each(|(ticker, checkpoint_id, balance)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
TotalSupply::insert(asset_id, checkpoint_id, balance);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the Balance storage");
v1::Balance::drain().for_each(|((ticker, checkpoint_id), did, balance)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
Balance::insert((asset_id, checkpoint_id), did, balance);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the CheckpointIdSequence storage");
v1::CheckpointIdSequence::drain().for_each(|(ticker, checkpoint_id)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
CheckpointIdSequence::insert(asset_id, checkpoint_id);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the BalanceUpdates storage");
v1::BalanceUpdates::drain().for_each(|(ticker, did, checkpoint_id)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
BalanceUpdates::insert(asset_id, did, checkpoint_id);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the Timestamps storage");
v1::Timestamps::drain().for_each(|(ticker, checkpoint_id, when)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
Timestamps::insert(asset_id, checkpoint_id, when);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the ScheduleIdSequence storage");
v1::ScheduleIdSequence::drain().for_each(|(ticker, schedule_id)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
ScheduleIdSequence::insert(asset_id, schedule_id);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the CachedNextCheckpoints storage");
v1::CachedNextCheckpoints::drain().for_each(|(ticker, next_checkpoint)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
CachedNextCheckpoints::insert(asset_id, next_checkpoint);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the ScheduledCheckpoints storage");
v1::ScheduledCheckpoints::drain().for_each(|(ticker, schedule_id, next_checkpoint)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
ScheduledCheckpoints::insert(asset_id, schedule_id, next_checkpoint);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the ScheduleRefCount storage");
v1::ScheduleRefCount::drain().for_each(|(ticker, schedule_id, count)| {
v1::ScheduleRefCount::drain().for_each(|(ticker, schedule_id, ref_count)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
ScheduleRefCount::insert(asset_id, schedule_id, count);
ScheduleRefCount::insert(asset_id, schedule_id, ref_count);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the SchedulePoints storage");
v1::SchedulePoints::drain().for_each(|(ticker, schedule_id, checkpoint_id)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
SchedulePoints::insert(asset_id, schedule_id, checkpoint_id);
});
log::info!("{:?} items migrated", count);
}
66 changes: 66 additions & 0 deletions pallets/asset/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,71 +103,97 @@ pub(crate) fn migrate_to_v5<T: Config>() {

// Removes all elements in the old storage and inserts it in the new storage

let mut count = 0;
log::info!("Moving items from Tickers to UniqueTickerRegistration");
v4::Tickers::<T>::drain().for_each(|(ticker, ticker_registration)| {
count += 1;
let asset_id = AssetID::from(ticker);
ticker_to_asset_id.insert(ticker, asset_id);
UniqueTickerRegistration::<T>::insert(ticker, ticker_registration);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Moving items from Tokens to SecurityTokens");
v4::Tokens::drain().for_each(|(ticker, security_token)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
SecurityTokens::insert(asset_id, security_token);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the AssetNames storage");
v4::AssetNames::drain().for_each(|(ticker, asset_name)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
AssetNames::insert(asset_id, asset_name);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the BalanceOf storage");
v4::BalanceOf::drain().for_each(|(ticker, identity, balance)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
BalanceOf::insert(asset_id, identity, balance);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Moving items from Identifiers to AssetIdentifiers");
v4::Identifiers::drain().for_each(|(ticker, identifiers)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
AssetIdentifiers::insert(asset_id, identifiers);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the FundingRound storage");
v4::FundingRound::drain().for_each(|(ticker, name)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
FundingRound::insert(asset_id, name);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the IssuedInFundingRound storage");
v4::IssuedInFundingRound::drain().for_each(|((ticker, name), balance)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
IssuedInFundingRound::insert((asset_id, name), balance);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the Frozen storage");
v4::Frozen::drain().for_each(|(ticker, frozen)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
Frozen::insert(asset_id, frozen);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Moving items from AssetOwnershipRelations to TickersOwnedByUser and SecurityTokensOwnedByUser");
v4::AssetOwnershipRelations::drain().for_each(|(owner_did, ticker, ownership_detail)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
Expand All @@ -183,118 +209,158 @@ pub(crate) fn migrate_to_v5<T: Config>() {
AssetOwnershipRelation::NotOwned => {}
}
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the AssetDocuments storage");
v4::AssetDocuments::drain().for_each(|(ticker, doc_id, doc)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

AssetDocuments::insert(asset_id, doc_id, doc);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the AssetDocumentsIdSequence storage");
v4::AssetDocumentsIdSequence::drain().for_each(|(ticker, seq)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

AssetDocumentsIdSequence::insert(asset_id, seq);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the AssetMetadataValues storage");
v4::AssetMetadataValues::drain().for_each(|(ticker, key, value)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

AssetMetadataValues::insert(asset_id, key, value);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the AssetMetadataValueDetails storage");
v4::AssetMetadataValueDetails::<T>::drain().for_each(|(ticker, key, value)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

AssetMetadataValueDetails::<T>::insert(asset_id, key, value);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the AssetMetadataLocalNameToKey storage");
v4::AssetMetadataLocalNameToKey::drain().for_each(|(ticker, name, local_key)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

AssetMetadataLocalNameToKey::insert(asset_id, name, local_key);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the AssetMetadataLocalKeyToName storage");
v4::AssetMetadataLocalKeyToName::drain().for_each(|(ticker, local_key, name)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

AssetMetadataLocalKeyToName::insert(asset_id, local_key, name);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the AssetMetadataLocalSpecs storage");
v4::AssetMetadataLocalSpecs::drain().for_each(|(ticker, local_key, spec)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

AssetMetadataLocalSpecs::insert(asset_id, local_key, spec);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the AssetMetadataNextLocalKey storage");
v4::AssetMetadataNextLocalKey::drain().for_each(|(ticker, next)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

AssetMetadataNextLocalKey::insert(asset_id, next);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Moving items from TickersExemptFromAffirmation to AssetsExemptFromAffirmation");
v4::TickersExemptFromAffirmation::drain().for_each(|(ticker, exempt)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

AssetsExemptFromAffirmation::insert(asset_id, exempt);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Moving items from PreApprovedTicker to PreApprovedAsset");
v4::PreApprovedTicker::drain().for_each(|(did, ticker, approved)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

PreApprovedAsset::insert(did, asset_id, approved);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the MandatoryMediators storage");
v4::MandatoryMediators::<T>::drain().for_each(|(ticker, mediators)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

MandatoryMediators::<T>::insert(asset_id, mediators);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the CurrentAssetMetadataLocalKey storage");
v4::CurrentAssetMetadataLocalKey::drain().for_each(|(ticker, current_key)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));

CurrentAssetMetadataLocalKey::insert(asset_id, current_key);
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Adding link from legacy tickers to an asset_id");
for (ticker, asset_id) in ticker_to_asset_id.into_iter() {
count += 1;
AssetIDTicker::insert(asset_id, ticker);
TickerAssetID::insert(ticker, asset_id);
}
log::info!("{:?} items migrated", count);
}
6 changes: 6 additions & 0 deletions pallets/compliance-manager/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,25 @@ pub(crate) fn migrate_to_v1<T: Config>() {
RuntimeLogger::init();
let mut ticker_to_asset_id = BTreeMap::new();

let mut count = 0;
log::info!("Updating types for the AssetCompliances storage");
v0::AssetCompliances::drain().for_each(|(ticker, compliance)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
AssetCompliances::insert(asset_id, AssetCompliance::from(compliance));
});
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Updating types for the TrustedClaimIssuer storage");
v0::TrustedClaimIssuer::drain().for_each(|(ticker, trusted_issuers)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
TrustedClaimIssuer::insert(asset_id, trusted_issuers);
});
log::info!("{:?} items migrated", count);
}
Loading

0 comments on commit 699fc20

Please sign in to comment.