Expand description

Migrate pattern implements methods to change the storage representation of a struct.

The migration controller takes the old and new schema and deserializes the contract state from the old schema. The on_migrate method takes this state and replaces it with the new schema. MigrateExternal exposes this functionality publicly.

The crate exports a derive macro that derives a default implementation for migration.

Note: MigrateHook must be implemented by the user and is not derived by default. It must convert data in the old schema to the new schema without failing. For a complete example checkout upgrade_new.rs in workspace-tests.

Safety

The contract state must conform to the old schema otherwise deserializing it will fail and throw an error.

Modules

Traits

Conversion between two storage schemas
Migrate-able contracts expose this trait publicly
Called on migration. Must be implemented by the user. (The derive macro does not implement this for you.)