Documentation

TypeDB.Migrate

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.

inductive TypeDB.Down :

How a migration is undone.

Instances For

    One versioned migration step.

    • version : Nat
    • name : String
    • down : Down
    • fingerprint : String

      What identifies the step's content for the checksum: its TypeQL, or a description that changes whenever the step's code does.

    Instances For
      def TypeDB.Migration.tql (version : Nat) (name up : String) (down : Option String := none) :

      A step from TypeQL text, with an optional TypeQL down.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def TypeDB.Migration.define (version : Nat) (name : String) (specs : List TypeSpec) (down : Down := Down.irreversible) :

        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
          def TypeDB.Migration.ofFile (version : Nat) (name : String) (path : System.FilePath) (down : Down := Down.irreversible) :

          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

            A row of the migration history.

            Instances For

              What migrate or rollback did: the steps run, in order.

              Instances For
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  Equations
                  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

                              Runs the down steps of every applied step newer than to, newest first.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For