cardinal

Install

Set up the migrator's checkout, its state database and its web UI.

The migrator runs from a checkout of its repository. Erlang and Elixir versions are pinned in its .tool-versions. It needs a Postgres database of its own for state: migrations, runs, failed rows, conflicts and checks. Cardinal never reads that database.

Set up

Write the operator's settings to .env in the checkout, one KEY=value per line with no quotes. bin/frappe-migrator reads it on every start. A variable already set in the shell wins.

cat > .env <<EOF
MIGRATOR_KEY=$(openssl rand -base64 32)
MIGRATOR_PASSWORD=$(openssl rand -base64 18)
MIGRATOR_DATABASE_URL=ecto://user:pass@localhost:5432/frappe_migrator
EOF
chmod 600 .env

Keep a copy of MIGRATOR_KEY somewhere else. It decrypts the stored credentials and keys.

Fetch dependencies and create the state database once. Its migrations run on every start.

mix deps.get
(set -a; . ./.env; MIX_ENV=prod mix ecto.create)

Start the web UI and open http://127.0.0.1:4100. Sign in with MIGRATOR_PASSWORD.

bin/frappe-migrator server

To keep it running after the terminal closes, run nohup bin/frappe-migrator server > server.log 2>&1 &.

bin/frappe-migrator runs mix migrator with MIX_ENV=prod unless MIX_ENV is set, and builds the static assets the first time.

Settings

VariableDefaultWhat it does
MIGRATOR_DATABASE_URLrequired in prodThe state database
MIGRATOR_ENV_FILE.envThe file bin/frappe-migrator reads the other variables from
MIGRATOR_KEYrequired32 bytes in base64. Encrypts source and target credentials and keys at rest (AES-256-GCM) and derives the cookie secret
MIGRATOR_PASSWORDunsetThe operator password for the web UI. Unset means no login, allowed only on a loopback bind
MIGRATOR_BIND127.0.0.1The address the UI listens on. Any other address needs MIGRATOR_PASSWORD, or the server refuses to start
MIGRATOR_PORT4100The UI's port
MIGRATOR_HOSTlocalhostThe host name in generated URLs

Perch also defaults to port 4100. If you run both on one machine, set MIGRATOR_PORT or PERCH_PORT to another port.

Command line

Every action in the UI has a command. Both read and write the same state database and take the same lock per migration.

bin/frappe-migrator server                       serve the web UI
bin/frappe-migrator migration add NAME [options] add a migration
bin/frappe-migrator migration list               migrations and their last run
bin/frappe-migrator migration test NAME          connect to the source and target, say what was found
bin/frappe-migrator sync NAME [--resume]         run a sync, or resume the last stopped or failed one
bin/frappe-migrator check NAME                   run the checks alone, printing the log
bin/frappe-migrator stop NAME                    stop the running sync after its current batch
bin/frappe-migrator report NAME                  counts, failures by kind, conflicts, every check

bin/frappe-migrator help lists the options of migration add. Connect the sites lists them too.

Try it with demo data

MIX_ENV=dev mix run priv/repo/demo_seeds.exs     # with MIGRATOR_KEY and MIGRATOR_DATABASE_URL set

The seeds create three made-up migrations: acme-erpnext (finished syncs, failures, conflicts, checks), globex-hr (never synced) and initech (ready for cutover). Their runs report progress without touching any site, so you can try Start, Stop and Resume. Run the server with MIX_ENV=dev too.

On this page