The CLI
migrant manages migrations that live under <project-dir>/migrations/, where
project-dir is the closest parent directory containing a Migrant.toml.
Applied migrations are tracked in a __migrant_migrations table. Commands are
run from anywhere inside the project; migrant searches upward for the config.
Project setup
migrant init [--type <sqlite|postgres|mysql>] [--location <dir>] [--default-from-env] [--no-confirm]- Create a
Migrant.toml. Run interactively (without--no-confirm) it also runssetup.--default-from-envseeds every value as anenv:VARreference instead of a literal (see Configuration). migrant setup- Verify database credentials and create the
__migrant_migrationstable if it is missing. migrant which-config- Print the path of the active
Migrant.toml. migrant connect-string- Print the connection string (server databases) or the database file path (SQLite).
Migrations
migrant new <tag>- Generate a timestamped
<stamp>_<tag>/directory with emptyup.sqlanddown.sql. Tags may contain[a-z0-9-]. migrant edit <tag> [--down]- Open the
up.sql(ordown.sqlwith--down) for a migration matching<tag>in$EDITOR. migrant list- List available migrations and mark those applied.
migrant status [--format <text|json>]- Report every managed migration with its applied/pending state and summary
counts.
--format text(the default) prints a summary line plus a[✓]/[ ]row per migration;--format jsonprints the same data as JSON ({ total, applied, pending, migrations: [{ tag, applied }] }) for scripting. migrant apply [--down] [--all] [--force[=<mode>]] [--fake] [--no-sync]- Apply the next migration.
--downreverts instead of applying.--allruns every remaining migration in the chosen direction.--forcecontinues past a failed migration: bare--force(or--force=accept-failures) records the failed migration as applied anyway, so it is not retried on later runs;--force=skip-failuresleaves it unrecorded and retries it on the next run.--fakerecords the migration as (un)applied without running its SQL.--no-syncdisables the cross-process advisory lock that is otherwise on by default for PostgreSQL/MySQL; use it when migrations are already serialized by an external mechanism. migrant redo [--all] [--force[=<mode>]] [--no-sync]- Shortcut for the latest
downthenup. Useful while iterating on a migration you are still writing.--no-syncdisables the advisory lock for both the down and up runs.
Inspect and connect
migrant shell- Open a database repl. Requires the matching client on your
PATH:sqlite3for SQLite,psqlfor PostgreSQL, and for MySQLmysqlshwhen installed, falling back to the classicmysqlclient. The password is passed out of band (PGPASSWORD/MYSQL_PWD), never on the command line. migrant tui- Interactive terminal UI for viewing and applying migrations. Keys:
j/k(or Down/Up) move the selection,uapplies the next migration anddreverts the last,aapplies all andDreverts all,rrefreshes from the database, andq(or Esc / Ctrl-C) quits.
Maintenance
migrant self update [--no-confirm] [--quiet]- Replace the running binary with the latest GitHub release. Only works when the
binary was built with the
updatefeature (release binaries are; a plaincargo installis not). migrant self bash-completions [install [--path <path>]]- Generate a bash completion script. Without
installit is written to stdout, so you can redirect it yourself. Withinstallit is written to a file (default/etc/bash_completion.d/migrant) and the success message goes to stderr.
Behavior worth knowing
- Each migration and its bookkeeping row are applied in one transaction by
default. See Transactions and the
-- migrant:no-transactiondirective for DDL that cannot run in a transaction. - Runs against PostgreSQL/MySQL take an advisory lock so concurrent
migrantprocesses serialize. See Concurrency and locking.