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
Definition of Done
All CI checks must pass before the PR is reviewed.
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
schema_version: u32in instance storagemigrate(env, admin)admin-only entry point that runs pending migrations in sequencefn migration_vN(env: &Env)— transforms old storage entries to new formatschema_version < CURRENT_VERSION, panic withMigrationRequired(exceptmigrateitself)InvoiceOptions, v2→v3 renames a storage key)Acceptance Criteria
migrateentry point implementedcargo test --workspacepasses with zero failurescargo clippy --all-targets -- -D warningsproduces zero warningsDefinition of Done
All CI checks must pass before the PR is reviewed.