Migrations #
A migration is a numbered step with an up and a down, each a schema-transaction body. Schema
transactions can also read and write data, so a step can change the schema and backfill data
atomically.
Driver.migrate applies, in version order, every step newer than the database's latest applied
one. Each step runs in its own schema transaction together with the insertion of its history
record, so a failed step leaves no trace and the steps before it stay applied. The history lives
in the database itself, as typedb-lean-migration entities.
Every step has a checksum of its name and fingerprint. Migrating fails before running anything
if an applied step's checksum no longer matches the list, which catches edits to steps that have
already run. Lean functions cannot be hashed, so steps written as code must say what identifies
them in fingerprint; steps built from TypeQL text (Migration.tql, Migration.define) use the
text itself.
Driver.rollback runs down steps in reverse version order, each with the removal of its
history record. A step whose down is .irreversible stops the rollback.
How a migration is undone.
- step (body : Tx TxMode.schema Unit) : Down
- irreversible : Down
The step cannot be undone, e.g. because it drops data.
Instances For
A step that defines the mapped types; down undefines nothing and is irreversible unless
given.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A step from a TypeQL file, read now so that its checksum covers the file's content.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- m.checksum = TypeDB.Str.padLeft (String.ofList (Nat.toDigits 16 (hash (m.name ++ "\n" ++ m.fingerprint)).toNat)) 16 '0'
Instances For
A row of the migration history.
- version : Nat
- name : String
- checksum : String
- appliedAt : Std.Time.PlainDateTime
Instances For
Equations
- TypeDB.instFromRowAppliedMigration = { decoder := TypeDB.AppliedMigration.mk <$> TypeDB.col "v" <*> TypeDB.col "n" <*> TypeDB.col "c" <*> TypeDB.col "t" }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Equations
- TypeDB.Migrations.historyType = "typedb-lean-migration"
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Checks that versions are unique and strictly increasing.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The applied history, oldest first.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Applies every step newer than the latest applied one, each in its own schema transaction.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- d.migrate db ms = TypeDB.blocking (d.migrateSync db ms)
Instances For
Equations
- d.rollback db ms to = TypeDB.blocking (d.rollbackSync db ms to)