Skip to content

Implement a storage migration framework with versioned schema keys #350

Description

@Kingsman-99

Overview

As the contract evolves, storage key schemas change. Build a migration framework that allows the contract to detect the current storage schema version, execute migrations in order, and update the version — all without wiping existing data.

Requirements

  • Store a schema_version: u32 in instance storage
  • migrate(env, admin) admin-only entry point that runs pending migrations in sequence
  • Each migration is a Rust function fn migration_vN(env: &Env) — transforms old storage entries to new format
  • Guard all entry points: if schema_version < CURRENT_VERSION, panic with MigrationRequired (except migrate itself)
  • Write at least two concrete migrations as examples (e.g. v1→v2 adds a new field to InvoiceOptions, v2→v3 renames a storage key)
  • Write integration tests that simulate upgrading from v1 data through to current

Acceptance Criteria

  • migrate entry point implemented
  • MigrationRequired guard on all other entry points when schema is stale
  • At least 2 migration functions implemented and tested
  • Storage snapshot test accounts for versioned keys
  • All existing tests pass
  • cargo test --workspace passes with zero failures
  • cargo clippy --all-targets -- -D warnings produces zero warnings

Definition of Done

All CI checks must pass before the PR is reviewed.

Metadata

Metadata

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignOfficial Campaign | FWC26Campaign: Official Campaign | FWC26complexity: highComplex feature requiring deep knowledge - 200 ptsgrantfoxIssue for GrantFox programstorageStorage layout and TTL optimisation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions