Skip to content

Conversation

@RomarQ
Copy link
Contributor

@RomarQ RomarQ commented Nov 26, 2025

Overview

This PR introduces a new generic migration utility ClearStorageByPrefix that enables safe removal of storage items by prefix using the multi-block migration frame.

Motivation

Previously, clearing specific storage items required writing custom migrations for each use case. This generic implementation provides a reusable solution that can clear any storage prefix without being tied to a specific pallet, making storage cleanup operations more maintainable and less error-prone.

Changes

New Migration Utility

  • ClearStorageByPrefix<T, StoragePrefix>: A generic struct that implements SteppedMigration to safely clear storage items matching a given prefix
    • Uses the multi-block migration pallet to safely handle large storage removals
    • Processes keys in batches based on available block weight
    • Generates unique migration identifiers based on the storage prefix

Usage Example

use frame_support::parameter_types;

// Define the storage prefix to clear
parameter_types! {
    pub StoragePrefixToClear: [u8; 32] = frame_support::storage::storage_prefix(
        b"PalletName",
        b"StorageName",
    );
}

// Configure the migration
pub type MultiBlockMigrations =
    pallet_migrations::ClearStorageByPrefix<Runtime, StoragePrefixToClear>;

impl pallet_migrations::Config for Runtime {
    type Migrations = MultiBlockMigrations;
    // ... other configuration
}

Breaking Changes

None. This is a new utility that does not affect existing functionality.

@RomarQ RomarQ marked this pull request as ready for review November 26, 2025 12:48
@RomarQ RomarQ requested a review from a team as a code owner November 26, 2025 12:48
@RomarQ RomarQ marked this pull request as draft November 26, 2025 15:58
@RomarQ RomarQ marked this pull request as ready for review November 26, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant