View Source migraterl_runner (migraterl v0.5.0)

The migration runner, modelled as a gen_statem.

A run is a short-lived, linear lifecycle where each phase is an explicit state and any failure routes to failed. The caller starts a runner and blocks on a single run call that is answered only once a terminal state is reached:

idle -> ensuring_journal -> locking -> reading_state
     -> scanning -> planning -> applying -> done
                                   |          |
                                (dry_run)  failed

The namespace advisory lock is acquired in locking and released before the caller is answered (with terminate/3 as a crash-path safety net), so it is held for the whole run regardless of the transaction mode. Transaction boundaries themselves are emitted from the applying loop, which lets one code path serve per_script, single and none modes.

Summary

Functions

Run a migration to completion and return its result. Blocks the caller until the runner reaches a terminal state.

Types

namespace()

-type namespace() :: binary().

ooo_policy()

-type ooo_policy() :: warn | error | ignore.

script_class()

-type script_class() :: once | on_change | always.

txn_mode()

-type txn_mode() :: per_script | single | none.

warning()

-type warning() :: {out_of_order, binary()} | {drift, binary()} | {missing, binary()}.

Functions

applying/3

callback_mode()

ensuring_journal/3

idle/3

init/1

locking/3

planning/3

reading_state/3

run(Conn, Opts, Timeout)

-spec run(epgsql:connection(),
          #opts{namespace :: namespace(),
                sources :: [{script_class(), file:filename_all()}],
                txn :: txn_mode(),
                on_out_of_order :: ooo_policy(),
                variables :: #{binary() => binary()},
                dry_run :: boolean(),
                notify :: boolean()},
          timeout()) ->
             {ok, #{applied := [binary()], skipped := [binary()], warnings := [warning()]}} |
             {error, term()}.

Run a migration to completion and return its result. Blocks the caller until the runner reaches a terminal state.

scanning/3

terminate/3