morley-0.5.0: Developer tools for the Michelson Language

Safe HaskellNone
LanguageHaskell2010

Lorentz.UStore.Migration.Base

Contents

Description

Basic migration primitives.

All primitives in one scheme:

MigrationBlocks (batched migrations writing) /| || muBlock // || mkUStoreBatchedMigration // || // || MUStore || UStore template value (simple migration writing) || (storage initialization) \ || // \ || // mkUStoreMigration \ || // fillUStore | / |/ UStoreMigration (whole migration) || \ || \ migrationToScript || \ compileMigration || \ MigrationBatching || \ (way to slice migration) || \ // || \ // || | |/ || UStoreMigrationCompiled || (sliced migration) || // \ || migrationToScripts \ buildMigrationPlan || // \ migrationStagesNum || // \ ... / |/ | MigrationScript Information about migration (part of migration which (migration plan, stages number...) fits into Tezos transaction)

Synopsis

UStore utilities

type InitUStore = UStore () Source #

Absolutely empty storage.

data SomeUTemplate Source #

Dummy template for UStore, use this when you want to forget exact template and make type of store homomorphic.

type UStore_ = UStore SomeUTemplate Source #

UStore with hidden template.

Basic migration primitives

newtype MigrationScript Source #

Code of migration for UStore.

Invariant: preferably should fit into op size / gas limits (quite obvious). Often this stands for exactly one stage of migration (one Tezos transaction).

Instances
Show MigrationScript Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

Generic MigrationScript Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

Associated Types

type Rep MigrationScript :: Type -> Type #

Wrapped MigrationScript Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

Associated Types

type Unwrapped MigrationScript :: Type #

IsoValue MigrationScript Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

Associated Types

type ToT MigrationScript :: T Source #

TypeHasDoc MigrationScript Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

type Rep MigrationScript Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

type Rep MigrationScript = D1 (MetaData "MigrationScript" "Lorentz.UStore.Migration.Base" "morley-0.5.0-GrlgowF8t30F9AnUlsv4ov" True) (C1 (MetaCons "MigrationScript" PrefixI True) (S1 (MetaSel (Just "unMigrationScript") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Lambda UStore_ UStore_))))
type Unwrapped MigrationScript Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

type ToT MigrationScript Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

data MigrationAtom Source #

Minimal possible piece of migration script.

Different atoms can be arbitrarily reordered and separated across migration stages, but each single atom is treated as a whole.

Splitting migration into atoms is responsibility of migration writer.

data UStoreMigration (oldStore :: Type) (newStore :: Type) where Source #

Keeps information about migration between UStores with two given templates. Note that it is polymorphic over whole storage types, not their templates, for convenience (so that there is no need to export the template).

Constructors

UStoreMigration :: (oldStore ~ UStore oldTemplate, newStore ~ UStore newTemplate) => [MigrationAtom] -> UStoreMigration oldStore newStore 

type UStoreMigrationT ot nt = UStoreMigration (UStore ot) (UStore nt) Source #

Alias for UStoreMigration which accepts UStore templates as type arguments.

newtype MigrationBlocks (oldTemplate :: Type) (newTemplate :: Type) (preRemDiff :: [DiffItem]) (preTouched :: [Symbol]) (postRemDiff :: [DiffItem]) (postTouched :: [Symbol]) Source #

A bunch of migration atoms produced by migration writer.

Instances
(RequireEmptyDiff d1, t1 ~ t2) => MigrationFinishCheckPosition (MigrationBlocks o n d1 t1 ([] :: [DiffItem]) t2) Source #

This version can be used in mkUStoreMultiMigration as the last migration block.

Instance details

Defined in Lorentz.UStore.Migration.Blocks

Methods

migrationFinish :: MigrationBlocks o n d1 t1 [] t2 Source #

newtype MUStore (oldTemplate :: Type) (newTemplate :: Type) (remDiff :: [DiffItem]) (touched :: [Symbol]) Source #

Wrapper over UStore which is currently being migrated.

In type-level arguments it keeps

  • Old and new UStore templates - mostly for convenience of the implementation.
  • Remaining diff which yet should be covered. Here we track migration progress. Once remaining diff is empty, migration is finished.
  • Names of fields which have already been touched by migration. Required to make getters safe.

Constructors

MUStoreUnsafe (UStore oldTemplate) 
Instances
Generic (MUStore oldTemplate newTemplate remDiff touched) Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

Associated Types

type Rep (MUStore oldTemplate newTemplate remDiff touched) :: Type -> Type #

Methods

from :: MUStore oldTemplate newTemplate remDiff touched -> Rep (MUStore oldTemplate newTemplate remDiff touched) x #

to :: Rep (MUStore oldTemplate newTemplate remDiff touched) x -> MUStore oldTemplate newTemplate remDiff touched #

IsoValue (MUStore oldTemplate newTemplate remDiff touched) Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

Associated Types

type ToT (MUStore oldTemplate newTemplate remDiff touched) :: T Source #

Methods

toVal :: MUStore oldTemplate newTemplate remDiff touched -> Value (ToT (MUStore oldTemplate newTemplate remDiff touched)) Source #

fromVal :: Value (ToT (MUStore oldTemplate newTemplate remDiff touched)) -> MUStore oldTemplate newTemplate remDiff touched Source #

type Rep (MUStore oldTemplate newTemplate remDiff touched) Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

type Rep (MUStore oldTemplate newTemplate remDiff touched) = D1 (MetaData "MUStore" "Lorentz.UStore.Migration.Base" "morley-0.5.0-GrlgowF8t30F9AnUlsv4ov" True) (C1 (MetaCons "MUStoreUnsafe" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (UStore oldTemplate))))
type ToT (MUStore oldTemplate newTemplate remDiff touched) Source # 
Instance details

Defined in Lorentz.UStore.Migration.Base

type ToT (MUStore oldTemplate newTemplate remDiff touched) = GValueType (Rep (MUStore oldTemplate newTemplate remDiff touched))

migrationToLambda :: UStoreMigrationT oldTemplate newTemplate -> Lambda (UStore oldTemplate) (UStore newTemplate) Source #

Turn Migration into a whole piece of code for transforming storage.

This is not want you'd want to use for contract deployment because of gas and operation size limits that Tezos applies to transactions.

mapMigrationCode :: (forall i o. (i :-> o) -> i :-> o) -> UStoreMigration os ns -> UStoreMigration os ns Source #

Modify all code in migration.

Simple migrations

mkUStoreMigration :: Lambda (MUStore oldTempl newTempl (BuildDiff oldTempl newTempl) '[]) (MUStore oldTempl newTempl '[] _1) -> UStoreMigrationT oldTempl newTempl Source #

Safe way to create migration scripts for UStore.

You have to supply a code which would transform MUStore, coverring required diff step-by-step. All basic instructions work, also use migrate* functions from this module to operate with MUStore.

This method produces a whole migration, it cannot be splitted in batches. In case if your migration is too big to be applied within a single transaction, use mkUStoreBatchedMigration.

migrationToScript :: UStoreMigration ot nt -> MigrationScript Source #

Get migration script in case of simple (non-batched) migration.

Batched migrations

data MigrationBatching (structure :: Type -> Type) (batchInfo :: Type) Source #

Way of distributing migration atoms among batches.

This also participates in describing migration plan and should contain information which would clarify to a user why migration is splitted such a way. Objects of type batchInfo stand for information corresponding to a batch and may include e.g. names of taken actions and gas consumption.

Type argument structure stands for container where batches will be put to and is usually a list ('[]').

When writing an instance of this datatype, you should tend to produce as few batches as possible because Tezos transaction execution overhead is quite high; though these batches should still preferably fit into gas limit.

Note that we never fail here because reaching perfect consistency with Tezos gas model is beyond dreams for now, even if our model predicts that some migration atom cannot be fit into gas limit, Tezos node can think differently and accept the migration. If your batching function can make predictions about fitting into gas limit, consider including this information in batchInfo type.

See batching implementations in Lorentz.UStore.Migration.Batching module.

Constructors

MigrationBatching ([MigrationAtom] -> structure (batchInfo, MigrationScript)) 

mbBatchesAsIs :: MigrationBatching [] Text Source #

Put each migration atom to a separate batch.

In most cases this is not what you want, but may be useful if e.g. you write your migration manually.

mbNoBatching :: MigrationBatching Identity Text Source #

Put the whole migration into one batch.

compileMigration :: MigrationBatching t batchInfo -> UStoreMigration ot nt -> UStoreMigrationCompiled t batchInfo Source #

Compile migration for use in production.

newtype UStoreMigrationCompiled (structure :: Type -> Type) (batchInfo :: Type) Source #

Migration script splitted in batches.

This is an intermediate form of migration content and needed because compiling UStoreMigration is a potentially heavyweight operation, and after compilation is performed you may need to get various information like number of migration steps, migration script, migration plan and other.

Constructors

UStoreMigrationCompiled 

Fields

mkUStoreBatchedMigration :: MigrationBlocks oldTempl newTempl (BuildDiff oldTempl newTempl) '[] '[] _1 -> UStoreMigrationT oldTempl newTempl Source #

Version of mkUStoreMigration which allows splitting migration in batches.

Here you supply a sequence of migration blocks which then are automatically distributed among migration stages.

migrationToScripts :: Traversable t => UStoreMigrationCompiled t batchInfo -> t MigrationScript Source #

Get migration scripts, each to be executed in separate Tezos transaction.

migrationToScriptsList :: Traversable t => UStoreMigrationCompiled t batchInfo -> [MigrationScript] Source #

Get migration scripts as list.

migrationToInfo :: Traversable t => UStoreMigrationCompiled t batchInfo -> t batchInfo Source #

Get information about each batch.

migrationStagesNum :: Traversable t => UStoreMigrationCompiled t batchInfo -> Int Source #

Number of stages in migration.

buildMigrationPlan :: (Traversable t, Buildable batchInfo) => UStoreMigrationCompiled t batchInfo -> Builder Source #

Render migration plan.

Manual migrations

manualWithUStore :: forall ustore template. ustore ~ UStore template => ('[ustore] :-> '[ustore]) -> MigrationScript Source #

Manually perform a piece of migration.

manualConcatMigrationScripts :: [MigrationScript] -> MigrationScript Source #

Merge several migration scripts. Used in manual migrations.

This function is generally unsafe because resulting migration script can fail to fit into operation size limit.

Extras

data DMigrationActionType Source #

An action on storage entry.

Constructors

DAddAction Text

Some sort of addition: "init", "set", "overwrite", e.t.c.

DDelAction

Removal.

data DMigrationActionDesc Source #

Describes single migration action.

In most cases it is possible to derive reasonable description for migration atom automatically, this datatype exactly carries this information.

Constructors

DMigrationActionDesc 

Fields

attachMigrationActionName :: (KnownSymbol fieldName, SingI (ToT fieldTy)) => DMigrationActionType -> Label fieldName -> Proxy fieldTy -> s :-> s Source #

Add description of action, it will be used in rendering migration plan and some batching implementations.

Internals

formMigrationAtom :: Maybe Text -> Lambda UStore_ UStore_ -> MigrationAtom Source #

Create migration atom from code.

This is an internal function, should not be used for writing migrations.