Safe Haskell | None |
---|---|
Language | Haskell2010 |
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 ::
UStoreMigration
V1.Storage V2.Storage migration =mkUStoreMigration
$ do -- migration code to be put heremigrationFinish
You will be prompted with a list of fields which should be added or removed.
- Add/remove necessary fields using
migrateAddField
,migrateExtractField
and other instructions. They allow you to operate withMUStore
— it is similar toUStore
but used withinmkUStoreMigration
to track migration progress. - Use
migrationToScript
ormigrationToTestScript
to turnUStoreMigration
into 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 ::
UStoreMigration
V1.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<-->
migrationFinish
Migration 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
Batching
module.
Get the required information about migration.
migrationToScripts
picks 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.