| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Lorentz.UStore.Migration
Description
Type-safe migrations of UStore.
This implements imperative approach to migration when we make user write a code of migration and track whether all new fields were indeed added and all unnecessary fields were removed.
You can find migration examples in tests.
How to write your simple migration
Start with migration template:
migration ::
UStoreMigrationV1.Storage V2.Storage migration =mkUStoreMigration$ do -- migration code to be put heremigrationFinishYou will be prompted with a list of fields which should be added or removed.
- Add/remove necessary fields using
migrateAddField,migrateExtractFieldand other instructions. They allow you to operate withMUStore— it is similar toUStorebut used withinmkUStoreMigrationto track migration progress. - Use
migrationToScriptormigrationToTestScriptto turnUStoreMigrationinto something useful.
Note that here you will get a solid MigrationScript, thus migration has
to fit into single Tezos transaction. If that's an issue, see the next section.
How to write batched migration
Insert migration template.
It looks like:
migration ::
UStoreMigrationV1.Storage V2.Storage migration =mkUStoreBatchedMigration$ -- place for migration blocksmigrationFinish
Fill migration code with blocks like
mkUStoreBatchedMigration$muBlock$:do -- code for block 1<-->muBlock$:do -- code for block 2<-->migrationFinishMigration blocks have to be the smallest actions which can safely be mixed and splitted across migration stages.
Compile migration with
compileBatchedMigration.Here you have to supply batching implementation. Alternatives include
mbNoBatching;mbBatchesAsIs;- Functions from
Batchingmodule.
Get the required information about migration.
migrationToScriptspicks the migration scripts, each has to be put in a separate Tezos transaction.buildMigrationPlan- dump description of each migration stage.
Manual migrations
If for some reasons you need to define migration manually, you can use
functions from Manual migrations section of Lorentz.UStore.Migration.Base.