Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- type InitUStore = UStore ()
- data SomeUTemplate
- type UStore_ = UStore SomeUTemplate
- toUStore_ :: UStore template -> UStore_
- fromUStore_ :: UStore_ -> UStore template
- newtype MigrationScript = MigrationScript {}
- maNameL :: Lens' MigrationAtom Text
- maScriptL :: Lens' MigrationAtom MigrationScript
- maActionsDescL :: Lens' MigrationAtom [DMigrationActionDesc]
- data MigrationAtom = MigrationAtom {}
- data UStoreMigration (oldStore :: Type) (newStore :: Type) where
- UStoreMigration :: (oldStore ~ UStore oldTemplate, newStore ~ UStore newTemplate) => [MigrationAtom] -> UStoreMigration oldStore newStore
- type UStoreMigrationT ot nt = UStoreMigration (UStore ot) (UStore nt)
- newtype MigrationBlocks (oldTemplate :: Type) (newTemplate :: Type) (preRemDiff :: [DiffItem]) (preTouched :: [Symbol]) (postRemDiff :: [DiffItem]) (postTouched :: [Symbol]) = MigrationBlocks [MigrationAtom]
- newtype MUStore (oldTemplate :: Type) (newTemplate :: Type) (remDiff :: [DiffItem]) (touched :: [Symbol]) = MUStoreUnsafe (UStore oldTemplate)
- migrationToLambda :: UStoreMigrationT oldTemplate newTemplate -> Lambda (UStore oldTemplate) (UStore newTemplate)
- mapMigrationCode :: (forall i o. (i :-> o) -> i :-> o) -> UStoreMigration os ns -> UStoreMigration os ns
- mkUStoreMigration :: Lambda (MUStore oldTempl newTempl (BuildDiff oldTempl newTempl) '[]) (MUStore oldTempl newTempl '[] _1) -> UStoreMigrationT oldTempl newTempl
- migrationToScript :: UStoreMigration ot nt -> MigrationScript
- data MigrationBatching (structure :: Type -> Type) (batchInfo :: Type) = MigrationBatching ([MigrationAtom] -> structure (batchInfo, MigrationScript))
- mbBatchesAsIs :: MigrationBatching [] Text
- mbNoBatching :: MigrationBatching Identity Text
- compileMigration :: MigrationBatching t batchInfo -> UStoreMigration ot nt -> UStoreMigrationCompiled t batchInfo
- newtype UStoreMigrationCompiled (structure :: Type -> Type) (batchInfo :: Type) = UStoreMigrationCompiled {
- compiledMigrationContent :: structure (batchInfo, MigrationScript)
- mkUStoreBatchedMigration :: MigrationBlocks oldTempl newTempl (BuildDiff oldTempl newTempl) '[] '[] _1 -> UStoreMigrationT oldTempl newTempl
- migrationToScripts :: Traversable t => UStoreMigrationCompiled t batchInfo -> t MigrationScript
- migrationToScriptsList :: Traversable t => UStoreMigrationCompiled t batchInfo -> [MigrationScript]
- migrationToInfo :: Traversable t => UStoreMigrationCompiled t batchInfo -> t batchInfo
- migrationStagesNum :: Traversable t => UStoreMigrationCompiled t batchInfo -> Int
- buildMigrationPlan :: (Traversable t, Buildable batchInfo) => UStoreMigrationCompiled t batchInfo -> Builder
- manualWithUStore :: forall ustore template. ustore ~ UStore template => ('[ustore] :-> '[ustore]) -> MigrationScript
- manualConcatMigrationScripts :: [MigrationScript] -> MigrationScript
- data DMigrationActionType
- data DMigrationActionDesc = DMigrationActionDesc {}
- attachMigrationActionName :: (KnownSymbol fieldName, SingI (ToT fieldTy)) => DMigrationActionType -> Label fieldName -> Proxy fieldTy -> s :-> s
- formMigrationAtom :: Maybe Text -> Lambda UStore_ UStore_ -> MigrationAtom
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.
fromUStore_ :: UStore_ -> UStore template Source #
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
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.
Instances
Show MigrationAtom Source # | |
Defined in Lorentz.UStore.Migration.Base showsPrec :: Int -> MigrationAtom -> ShowS # show :: MigrationAtom -> String # showList :: [MigrationAtom] -> ShowS # |
data UStoreMigration (oldStore :: Type) (newStore :: Type) where Source #
Keeps information about migration between UStore
s 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).
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 |
Defined in Lorentz.UStore.Migration.Blocks 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.
MUStoreUnsafe (UStore oldTemplate) |
Instances
Generic (MUStore oldTemplate newTemplate remDiff touched) Source # | |
Defined in Lorentz.UStore.Migration.Base | |
IsoValue (MUStore oldTemplate newTemplate remDiff touched) Source # | |
Defined in Lorentz.UStore.Migration.Base | |
type Rep (MUStore oldTemplate newTemplate remDiff touched) Source # | |
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 # | |
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.
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.
UStoreMigrationCompiled | |
|
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.
DAddAction Text | Some sort of addition: "init", "set", "overwrite", e.t.c. |
DDelAction | Removal. |
Instances
Show DMigrationActionType Source # | |
Defined in Lorentz.UStore.Migration.Base showsPrec :: Int -> DMigrationActionType -> ShowS # show :: DMigrationActionType -> String # showList :: [DMigrationActionType] -> ShowS # | |
Buildable DMigrationActionType Source # | |
Defined in Lorentz.UStore.Migration.Base build :: DMigrationActionType -> Builder # |
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.
DMigrationActionDesc | |
|
Instances
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.