Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
ef62acfb
Unverified
Commit
ef62acfb
authored
1 year ago
by
Bastian Köcher
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
pallet-uniques: Move migration over to `VersionedMigration` (#2687)
parent
2aaa9af3
Branches
gh-readonly-queue/master/pr-2944-9543d31474195b5f384e298299a483d460f37fe7
Branches containing commit
No related merge requests found
Pipeline
#425113
passed with stages
in 1 hour, 26 minutes, and 18 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
prdoc/pr_2687.prdoc
+18
-0
18 additions, 0 deletions
prdoc/pr_2687.prdoc
substrate/frame/uniques/src/migration.rs
+33
-32
33 additions, 32 deletions
substrate/frame/uniques/src/migration.rs
with
51 additions
and
32 deletions
prdoc/pr_2687.prdoc
0 → 100644
+
18
−
0
View file @
ef62acfb
title: "pallet-uniques: Move migration over to `VersionedMigration`"
doc:
- audience: Runtime Dev
description: |
Moves the migration over to `VersionedMigration`. Thus, if you had
used `migrate_to_v1` before in a custom `OnRuntimeUpgrade` implementation
you can now directly use the `MigrateV0ToV1`.
migrations:
runtime:
- reference: MigrateV0ToV1
description: |
Migrate the pallet storage from `0` to `1` by initializing
the `CollectionAccount` storage entry from all collections.
crates:
- name: "pallet-uniques"
This diff is collapsed.
Click to expand it.
substrate/frame/uniques/src/migration.rs
+
33
−
32
View file @
ef62acfb
...
...
@@ -17,38 +17,39 @@
//! Various pieces of common functionality.
use
super
::
*
;
use
frame_support
::
traits
::{
Get
,
GetStorageVersion
,
PalletInfoAccess
,
StorageVersion
};
/// Migrate the pallet storage to v1.
pub
fn
migrate_to_v1
<
T
:
Config
<
I
>
,
I
:
'static
,
P
:
GetStorageVersion
+
PalletInfoAccess
>
(
)
->
frame_support
::
weights
::
Weight
{
let
on_chain_storage_version
=
<
P
as
GetStorageVersion
>
::
on_chain_storage_version
();
log
::
info!
(
target
:
LOG_TARGET
,
"Running migration storage v1 for uniques with storage version {:?}"
,
on_chain_storage_version
,
);
if
on_chain_storage_version
<
1
{
let
mut
count
=
0
;
for
(
collection
,
detail
)
in
Collection
::
<
T
,
I
>
::
iter
()
{
CollectionAccount
::
<
T
,
I
>
::
insert
(
&
detail
.owner
,
&
collection
,
());
count
+=
1
;
use
frame_support
::
traits
::{
Get
,
OnRuntimeUpgrade
};
use
sp_std
::
marker
::
PhantomData
;
mod
v1
{
use
super
::
*
;
/// Actual implementation of the storage migration.
pub
struct
MigrateToV1Impl
<
T
,
I
>
(
PhantomData
<
(
T
,
I
)
>
);
impl
<
T
:
Config
<
I
>
,
I
:
'static
>
OnRuntimeUpgrade
for
MigrateToV1Impl
<
T
,
I
>
{
fn
on_runtime_upgrade
()
->
frame_support
::
weights
::
Weight
{
let
mut
count
=
0
;
for
(
collection
,
detail
)
in
Collection
::
<
T
,
I
>
::
iter
()
{
CollectionAccount
::
<
T
,
I
>
::
insert
(
&
detail
.owner
,
&
collection
,
());
count
+=
1
;
}
log
::
info!
(
target
:
LOG_TARGET
,
"Storage migration v1 for uniques finished."
,
);
// calculate and return migration weights
T
::
DbWeight
::
get
()
.reads_writes
(
count
as
u64
+
1
,
count
as
u64
+
1
)
}
StorageVersion
::
new
(
1
)
.put
::
<
P
>
();
log
::
info!
(
target
:
LOG_TARGET
,
"Running migration storage v1 for uniques with storage version {:?} was complete"
,
on_chain_storage_version
,
);
// calculate and return migration weights
T
::
DbWeight
::
get
()
.reads_writes
(
count
as
u64
+
1
,
count
as
u64
+
1
)
}
else
{
log
::
warn!
(
target
:
LOG_TARGET
,
"Attempted to apply migration to v1 but failed because storage version is {:?}"
,
on_chain_storage_version
,
);
T
::
DbWeight
::
get
()
.reads
(
1
)
}
}
/// Migrate the pallet storage from `0` to `1`.
pub
type
MigrateV0ToV1
<
T
,
I
>
=
frame_support
::
migrations
::
VersionedMigration
<
0
,
1
,
v1
::
MigrateToV1Impl
<
T
,
I
>
,
Pallet
<
T
,
I
>
,
<
T
as
frame_system
::
Config
>
::
DbWeight
,
>
;
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment