Trait frame_support::migrations::SteppedMigration
source · pub trait SteppedMigration {
type Cursor: FullCodec + MaxEncodedLen;
type Identifier: FullCodec + MaxEncodedLen;
// Required methods
fn id() -> Self::Identifier;
fn step(
cursor: Option<Self::Cursor>,
meter: &mut WeightMeter,
) -> Result<Option<Self::Cursor>, SteppedMigrationError>;
// Provided methods
fn max_steps() -> Option<u32> { ... }
fn transactional_step(
cursor: Option<Self::Cursor>,
meter: &mut WeightMeter,
) -> Result<Option<Self::Cursor>, SteppedMigrationError> { ... }
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> { ... }
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> { ... }
}
Expand description
A migration that can proceed in multiple steps.
Required Associated Types§
sourcetype Cursor: FullCodec + MaxEncodedLen
type Cursor: FullCodec + MaxEncodedLen
The cursor type that stores the progress (aka. state) of this migration.
sourcetype Identifier: FullCodec + MaxEncodedLen
type Identifier: FullCodec + MaxEncodedLen
The unique identifier type of this migration.
Required Methods§
sourcefn id() -> Self::Identifier
fn id() -> Self::Identifier
The unique identifier of this migration.
If two migrations have the same identifier, then they are assumed to be identical.
sourcefn step(
cursor: Option<Self::Cursor>,
meter: &mut WeightMeter,
) -> Result<Option<Self::Cursor>, SteppedMigrationError>
fn step( cursor: Option<Self::Cursor>, meter: &mut WeightMeter, ) -> Result<Option<Self::Cursor>, SteppedMigrationError>
Try to migrate as much as possible with the given weight.
ANY STORAGE CHANGES MUST BE ROLLED-BACK BY THE CALLER UPON ERROR. This is necessary
since the caller cannot return a cursor in the error case. Self::transactional_step
is
provided as convenience for a caller. A cursor of None
implies that the migration is at
its end. A migration that once returned Nonce
is guaranteed to never be called again.
Provided Methods§
sourcefn max_steps() -> Option<u32>
fn max_steps() -> Option<u32>
The maximum number of steps that this migration can take.
This can be used to enforce progress and prevent migrations becoming stuck forever. A
migration that exceeds its max steps is treated as failed. None
means that there is no
limit.
sourcefn transactional_step(
cursor: Option<Self::Cursor>,
meter: &mut WeightMeter,
) -> Result<Option<Self::Cursor>, SteppedMigrationError>
fn transactional_step( cursor: Option<Self::Cursor>, meter: &mut WeightMeter, ) -> Result<Option<Self::Cursor>, SteppedMigrationError>
Same as Self::step
, but rolls back pending changes in the error case.
sourcefn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError>
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError>
Hook for testing that is run before the migration is started.
Returns some bytes which are passed into post_upgrade
after the migration is completed.
This is not run for the real migration, so panicking is not an issue here.
sourcefn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError>
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError>
Hook for testing that is run after the migration is completed.
Should be used to verify the state of the chain after the migration. The state
parameter
is the return value from pre_upgrade
. This is not run for the real migration, so panicking
is not an issue here.