Skip to content

CLI commands

Run migrax help <command> for the same information in the terminal. Run every command from the service folder (the one with pom.xml or build.gradle), or pass --dir <path>.

Options for every command

Option Meaning
--dir <path> Project folder (default: current folder)
--no-build Do not run Maven/Gradle; use the classes and dependencies from the last build
--refresh Re-resolve dependencies even if cached
--json Machine-readable output (plan, status, check, generate, lint, drift, diff, verify)
--verbose, -v Show debug output, Hibernate's own log and stack traces
--no-input Never ask questions (the default when input is not a terminal)

Exit codes

Code Meaning
0 Success
1 Error, failed check, or failed migration
2 Differences found: check (entity changes without a migration), drift (database differs), diff (the two databases differ)

Getting started

init

migrax init [--json]

Creates the .migrax folder and the migration folder, then shows the entity package, database, dialect and naming Migrax detected. Safe to run more than once. A folder without a build file or migrax.properties belongs to the nearest folder above it that has one: init sets up that folder and says so.

Option Meaning
--json Machine-readable output
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--naming <strategy> spring, jpa, jpa-snake or micronaut (default: detected)
--dir <path> Project folder (default: current folder)

doctor

migrax doctor

Runs every check Migrax needs and explains how to fix anything that fails. Exits with code 1 when a check fails.

Option Meaning
--json Machine-readable output
--env <name> Environment for migrations marked '-- migrax:env'
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--extractor <mode> auto, hibernate, eclipselink, openjpa, spring-data-jdbc, micronaut-data or annotations (default: auto)
--schema-file <path> SQL file with the desired schema, instead of entities
--scratch-url <url> Empty database to read the schema file in (default: Docker)
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

mcp

migrax mcp [--allow-generate]

Runs a Model Context Protocol server on stdin/stdout, so AI assistants such as Claude Code can call status, check, plan, lint, drift, doctor, verify and show_migration as tools and read their JSON results. It never changes a database: migrate, rollback, repair and clean are not offered. --allow-generate also offers generate, which writes migration files for the person to review. Claude Code: claude mcp add migrax -- migrax mcp. See Using Migrax with AI assistants.

Option Meaning
--allow-generate Also offer the generate tool (writes migration files)
--dir <path> Project folder (default: current folder)

import

migrax import flyway|liquibase

flyway: records every migration in flyway_schema_history as applied, so Migrax continues where Flyway stopped; V*__ and R__ files keep working. liquibase: writes a baseline migration with the current schema and records it. Then it lists the dependencies, build plugins and settings of Flyway or Liquibase still in the project, each with its file and line, so you can remove them. Afterwards run migrax generate to start managing changes. See Switching from Flyway or Liquibase.

Option Meaning
--table <name> Flyway history table (default: flyway_schema_history)
--name <name> Migration file name (default: next number + description)
--schema <name> Database schema to read
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--dialect <name> postgresql, cockroachdb, yugabytedb, mysql, mariadb, tidb, sqlserver, oracle, h2, hsqldb, derby, sqlite
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

Everyday

baseline

migrax baseline <migration> [--dry-run] --yes

For a database whose tables already exist (created by hand, by a script or by another tool): records every versioned migration up to and including <migration> as applied without running it. migrax migrate then runs only the later ones. Refused when the database already has migration history. --yes confirms the change to migration history.

Option Meaning
--dry-run Show what would happen without doing it
--yes, -y Confirm without asking
--json Machine-readable output
--env <name> Environment for migrations marked '-- migrax:env'
--schemas <a,b> Run for each schema (multi-tenant)
--lock-timeout <time> Wait this long while another process migrates (e.g. 2m)
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--java-package <pkg> Package of Java migrations (default: db.migration; db.<name> with --database)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

generate

Alias: makemigrations

migrax generate [--name <name>] [--allow-destructive [--keep-data]] [--safe]
migrax generate --zero-downtime [--name <name>] [--allow-destructive]
migrax generate --contract
migrax generate --rebuild-snapshot

Compiles the project if needed, compares the entities with .migrax/snapshot.json and writes a numbered SQL file plus a rollback script (rollback/<file>). On the first run, with no snapshot, the current database schema is the baseline: its tables are written to 0001_baseline.sql, which that database records as applied without running it. When a column or table seems renamed, Migrax asks (or pass --rename / --rename-table) so the data is kept. Drops need --allow-destructive; with --keep-data, dropped tables and columns go to migrax_backup_* tables and the rollback script restores them (migrax backups lists and drops those tables). Without --keep-data, Migrax asks whether to keep that data (Enter keeps it), or warns when it can't ask. --safe (PostgreSQL, CockroachDB) builds indexes and constraints on existing tables without blocking writes, in a second migration. --zero-downtime splits the change so the old and new application versions can run at the same time: an expand migration now (new columns and tables, a renamed column kept equal to its old name by a trigger, a renamed table's old name as a view) and a contract migration for the next release (drops, NOT NULL, narrower types, new constraints). The contract migration waits in .migrax/pending/; generate --contract adds it to the migration folder. When a generated migration file was deleted, generate stops (MXE119): restore the file, or run generate --rebuild-snapshot to move the snapshot back to the history snapshot of the newest generated migration before the deleted ones, then generate again; with no migration file left at all it asks for --yes first. Always review the generated SQL; Migrax lints it for you.

Option Meaning
--name <name> Migration file name (default: next number + description)
--allow-destructive Allow drops and narrowing type changes
--keep-data Keep dropped data in backup tables the rollback restores
--safe Non-blocking indexes and constraints (PostgreSQL, CockroachDB)
--zero-downtime Split into an expand migration now and a contract one later
--contract Add the waiting contract migrations to the migration folder
--rebuild-snapshot Move the snapshot back after a migration file was deleted
--yes, -y Confirm without asking
--rename t.old=new Treat a column change as a rename (comma-separated)
--rename-table old=new Treat a table change as a rename
--no-input Never ask questions
--json Machine-readable output
--lock-timeout <time> Wait this long while another process migrates (e.g. 2m)
--dialect <name> postgresql, cockroachdb, yugabytedb, mysql, mariadb, tidb, sqlserver, oracle, h2, hsqldb, derby, sqlite
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--naming <strategy> spring, jpa, jpa-snake or micronaut (default: detected)
--extractor <mode> auto, hibernate, eclipselink, openjpa, spring-data-jdbc, micronaut-data or annotations (default: auto)
--schema-file <path> SQL file with the desired schema, instead of entities
--scratch-url <url> Empty database to read the schema file in (default: Docker)
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--schema <name> Database schema to read
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--refresh Re-resolve dependencies even if cached
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

migrate

migrax migrate [--to <migration>] [--sql | --dry-run] [--resume] [--schemas a,b]

Applies pending SQL and Java migrations in order, then new or changed repeatable R__*.sql migrations, with beforeMigrate/afterMigrate callbacks and ${placeholders}. --to applies versioned migrations only up to and including the given one; repeatable migrations then wait for the next migrate without --to. --sql prints the SQL script of what migrate would do, for a DBA to review and run with the database's own tool; nothing changes. --dry-run lists and lints pending migrations without changing the database. --schemas runs the migrations once per schema (multi-tenant). --resume re-runs a failed migration only if it is marked -- migrax:resume-safe. On PostgreSQL a migration waits at most 5 seconds for a lock that another session holds (--table-lock-timeout), so queries on that table don't queue behind it; a migration that ran in a transaction and stopped this way changed nothing and runs again with the next migrate (details, and what differs for -- migrax:no-transaction and Java migrations, in Configuration).

Option Meaning
--to <migration> Last migration to apply, keep or squash up to
--env <name> Environment for migrations marked '-- migrax:env'
--sql Print the SQL script without running it (for a DBA)
--dry-run Show what would happen without doing it
--json Machine-readable output
--resume Re-run a failed resume-safe migration
--lock-timeout <time> Wait this long while another process migrates (e.g. 2m)
--table-lock-timeout <time> Stop when a table stays locked this long (default 5s)
--schemas <a,b> Run for each schema (multi-tenant)
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--java-package <pkg> Package of Java migrations (default: db.migration; db.<name> with --database)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

status

Alias: showmigrations

migrax status [--json] [--check]

Lists migrations as applied [X], pending [ ] or a problem [!], without changing the database. Exits with code 1 when a migration failed, changed or is missing. --check also does what migrax check does, in the same run: exits with code 2 when the entities changed without a migration. With --json the output is then {"status": <the status JSON>, "check": <the check JSON>}.

Option Meaning
--json Machine-readable output
--check Also check the entities against the snapshot, as check does
--env <name> Environment for migrations marked '-- migrax:env'
--schemas <a,b> Run for each schema (multi-tenant)
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--java-package <pkg> Package of Java migrations (default: db.migration; db.<name> with --database)
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--naming <strategy> spring, jpa, jpa-snake or micronaut (default: detected)
--extractor <mode> auto, hibernate, eclipselink, openjpa, spring-data-jdbc, micronaut-data or annotations (default: auto)
--schema-file <path> SQL file with the desired schema, instead of entities
--scratch-url <url> Empty database to read the schema file in (default: Docker)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--refresh Re-resolve dependencies even if cached
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

plan

Alias: sqlmigrate

migrax plan [--impact] [--json]

Shows the operations and SQL for current entity changes without writing files. --impact adds the estimated size of each affected table from the database.

Option Meaning
--impact Show affected table sizes (needs the database)
--json Machine-readable output
--dialect <name> postgresql, cockroachdb, yugabytedb, mysql, mariadb, tidb, sqlserver, oracle, h2, hsqldb, derby, sqlite
--rename t.old=new Treat a column change as a rename (comma-separated)
--rename-table old=new Treat a table change as a rename
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--naming <strategy> spring, jpa, jpa-snake or micronaut (default: detected)
--extractor <mode> auto, hibernate, eclipselink, openjpa, spring-data-jdbc, micronaut-data or annotations (default: auto)
--schema-file <path> SQL file with the desired schema, instead of entities
--scratch-url <url> Empty database to read the schema file in (default: Docker)
--url <jdbc-url> Database URL (default: application config)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--refresh Re-resolve dependencies even if cached
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

rollback

migrax rollback [--steps n | --to <migration>] [--dry-run] --yes

Runs the rollback script of the newest applied migration (or several) and removes it from the history. generate writes rollback scripts to rollback/<file>; Java migrations roll back with JavaMigration.rollback. Restores structure, not deleted data.

Option Meaning
--json Machine-readable output
--steps <n> Number of migrations to roll back
--to <migration> Last migration to apply, keep or squash up to
--dry-run Show what would happen without doing it
--yes, -y Confirm without asking
--schemas <a,b> Run for each schema (multi-tenant)
--lock-timeout <time> Wait this long while another process migrates (e.g. 2m)
--table-lock-timeout <time> Stop when a table stays locked this long (default 5s)
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

new

migrax new <name> [--java]

Creates the next numbered SQL file for hand-written changes such as data migrations, with an empty rollback script. --java creates a JavaMigration class instead.

Option Meaning
--json Machine-readable output
--java Create a Java migration
--java-package <pkg> Package of Java migrations (default: db.migration; db.<name> with --database)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

Safety and CI

check

migrax check [--json]

Exits with code 2 when the entities differ from .migrax/snapshot.json, and with 1 when two migrations share a number (run migrax merge).

Option Meaning
--json Machine-readable output
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--naming <strategy> spring, jpa, jpa-snake or micronaut (default: detected)
--extractor <mode> auto, hibernate, eclipselink, openjpa, spring-data-jdbc, micronaut-data or annotations (default: auto)
--schema-file <path> SQL file with the desired schema, instead of entities
--scratch-url <url> Empty database to read the schema file in (default: Docker)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--refresh Re-resolve dependencies even if cached
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

lint

migrax lint [files...] [--all] [--strict] [--json] [--sarif <file>]

Checks pending migrations (or the given files, or --all) for statements that block tables, fail on existing data, or break running application instances, and suggests safe alternatives. Exits with 1 on errors, or on warnings with --strict. Silence a finding with -- migrax:lint-ignore MX001 before the statement. --sarif also writes the findings as SARIF 2.1.0, which GitHub code scanning, GitLab and Azure DevOps show on the SQL line in a pull request; its paths are relative to the current folder, so run lint from the repository's root.

Option Meaning
--all Lint every migration, not only pending ones
--strict Fail on warnings too
--json Machine-readable output
--sarif <file> Also write the findings as SARIF 2.1.0 for code scanning
--dialect <name> postgresql, cockroachdb, yugabytedb, mysql, mariadb, tidb, sqlserver, oracle, h2, hsqldb, derby, sqlite
--url <jdbc-url> Database URL (default: application config)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

verify

migrax verify [--url <scratch-db>] [--skip-rollbacks]

Starts a throwaway database (H2, HSQLDB and Derby in memory, Docker for other engines), applies every migration, then checks the result: Hibernate's schema validation when Hibernate is in the project, otherwise a structural comparison with the entities. It also tests every rollback script on its own: it rolls the migration back, applies it again and checks that the schema is the same, so a broken script is named.

Option Meaning
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--image <image> Docker image for the throwaway database
--skip-rollbacks Do not test rollback scripts
--json Machine-readable output
--env <name> Environment for migrations marked '-- migrax:env'
--dialect <name> postgresql, cockroachdb, yugabytedb, mysql, mariadb, tidb, sqlserver, oracle, h2, hsqldb, derby, sqlite
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--naming <strategy> spring, jpa, jpa-snake or micronaut (default: detected)
--extractor <mode> auto, hibernate, eclipselink, openjpa, spring-data-jdbc, micronaut-data or annotations (default: auto)
--schema-file <path> SQL file with the desired schema, instead of entities
--scratch-url <url> Empty database to read the schema file in (default: Docker)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

drift

migrax drift [--entities] [--json]

Reads the database schema and reports manual changes: missing or extra tables, columns, keys and unique constraints, nullability and type differences. Compares with the snapshot (what migrations produce) or, with --entities, the entities. Exits with code 2 when drift is found.

Option Meaning
--entities Compare with the entities instead of the snapshot
--json Machine-readable output
--env <name> Environment for migrations marked '-- migrax:env'
--schema <name> Database schema to read
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--naming <strategy> spring, jpa, jpa-snake or micronaut (default: detected)
--extractor <mode> auto, hibernate, eclipselink, openjpa, spring-data-jdbc, micronaut-data or annotations (default: auto)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

diff

migrax diff <source-url> [--sql] [--json]

Compares the schema of the source database (for example staging) with the project's database (for example production; set it with --url) and lists the changes that would make the project's database match: tables, columns, types, keys, indexes, checks and comments. --sql prints them as one SQL script to review. Both must be the same kind of database. Exits with code 2 when they differ. The source's user and password come from --source-user and --source-password-file, MIGRAX_SOURCE_USER and MIGRAX_SOURCE_PASSWORD, or the URL itself.

Option Meaning
--sql Print the SQL script without running it (for a DBA)
--json Machine-readable output
--source-user <name> User of the source database
--source-password-file <path> Read the source database's password from a file
--schema <name> Database schema to read
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

environments

migrax environments [--environments <a,b>] [--no-drift] [--timeout <duration>] [--json]

Asks each environment's database (migrax.environments.<name>.url) which migrations it has applied, lists what is pending there and whether its schema drifted from the snapshot, without changing anything. Migrations marked -- migrax:env count only in the environments they name. Exits with code 1 when an environment can't be reached or a migration failed, changed or is missing there, and 2 when drift is found; pending migrations alone exit with 0.

Option Meaning
--environments <a,b> Environments to show, in this order (default: all configured)
--no-drift Don't compare the schemas with the snapshot
--timeout <duration> How long to wait for each database (default: 30s)
--json Machine-readable output
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--java-package <pkg> Package of Java migrations (default: db.migration; db.<name> with --database)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

report

migrax report [--html <file>] [--json]

Writes one HTML page (default migrax-report.html) for reviews and CI artifacts: the schema with a diagram, entity changes that have no migration yet, every migration with its status and lint findings, and drift between the database and the snapshot. Parts that need the database are skipped when it can't be reached.

Option Meaning
--html <file> Where to write the page (default: migrax-report.html)
--json Machine-readable output
--env <name> Environment for migrations marked '-- migrax:env'
--schemas <a,b> Run for each schema (multi-tenant)
--dialect <name> postgresql, cockroachdb, yugabytedb, mysql, mariadb, tidb, sqlserver, oracle, h2, hsqldb, derby, sqlite
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--naming <strategy> spring, jpa, jpa-snake or micronaut (default: detected)
--extractor <mode> auto, hibernate, eclipselink, openjpa, spring-data-jdbc, micronaut-data or annotations (default: auto)
--schema-file <path> SQL file with the desired schema, instead of entities
--scratch-url <url> Empty database to read the schema file in (default: Docker)
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

Maintenance

squash

Alias: squashmigrations

migrax squash --to <migration> [--optimize]

Writes one migration that replaces all migrations up to --to. Databases that already applied them record it without running it; new databases run just the squashed file. --optimize writes only the resulting schema (data statements are dropped). Delete the old files once every environment has run migrate.

Option Meaning
--json Machine-readable output
--to <migration> Last migration to apply, keep or squash up to
--name <name> Migration file name (default: next number + description)
--optimize Squash to the resulting schema only
--dialect <name> postgresql, cockroachdb, yugabytedb, mysql, mariadb, tidb, sqlserver, oracle, h2, hsqldb, derby, sqlite
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

merge

migrax merge

Renumbers migrations that share a number after a git merge (the one added later moves to the next free number) and rebuilds a snapshot that has merge conflicts.

Option Meaning
--json Machine-readable output
--dialect <name> postgresql, cockroachdb, yugabytedb, mysql, mariadb, tidb, sqlserver, oracle, h2, hsqldb, derby, sqlite
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--naming <strategy> spring, jpa, jpa-snake or micronaut (default: detected)
--extractor <mode> auto, hibernate, eclipselink, openjpa, spring-data-jdbc, micronaut-data or annotations (default: auto)
--schema-file <path> SQL file with the desired schema, instead of entities
--scratch-url <url> Empty database to read the schema file in (default: Docker)
--url <jdbc-url> Database URL (default: application config)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

repair

migrax repair <migration>... --action applied|retry|forget --yes

Use only after inspecting the database.

  • --action applied: every statement took effect, so record the migration as applied.
  • --action retry: you restored the database, so clear the failure and let it run again.
  • --action forget: you deleted applied migration files on purpose, so remove them from the history. The database keeps the changes they made. Accepts several migrations at once.

--yes confirms the change to the migration history.

Option Meaning
--json Machine-readable output
--action <action> applied, retry or forget
--yes, -y Confirm without asking
--lock-timeout <time> Wait this long while another process migrates (e.g. 2m)
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

clean

migrax clean [--dry-run] [--yes]

Empties the database so migrax migrate can rebuild it from the migrations: drops every table (the migration history too), view and sequence in the configured schema. Data is deleted and can't be restored. Migration files and the snapshot are not touched. Asks before dropping; --yes confirms without asking. --dry-run lists what would be dropped. Set MIGRAX_CLEAN_DISABLED=true on servers where clean must never run.

Option Meaning
--json Machine-readable output
--dry-run Show what would happen without doing it
--yes, -y Confirm without asking
--lock-timeout <time> Wait this long while another process migrates (e.g. 2m)
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--schema <name> Database schema to read
--schemas <a,b> Run for each schema (multi-tenant)
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

backups

migrax backups [--drop [<migration>] --yes]

Lists the migrax_backup_* tables that migrations generated with --keep-data keep dropped data in; their rollback scripts restore it from there. Once you are sure you won't roll a migration back, drop its backups: --drop removes them all, or only those of one migration (--drop 0005). Asks before dropping; --yes confirms without asking.

Option Meaning
--json Machine-readable output
--drop [<migration>] Drop the backup tables (all, or one migration's)
--yes, -y Confirm without asking
--url <jdbc-url> Database URL (default: application config)
--user <name> Database user
--password <secret> Database password (prefer env vars)
--password-file <path> Read the database password from a file (mounted secret)
--schema <name> Database schema to read
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

inspect

migrax inspect

Prints the schema model Migrax builds from the entities.

Option Meaning
--package <name> Entity package (default: MIGRAX_PACKAGE or pom groupId)
--naming <strategy> spring, jpa, jpa-snake or micronaut (default: detected)
--extractor <mode> auto, hibernate, eclipselink, openjpa, spring-data-jdbc, micronaut-data or annotations (default: auto)
--dialect <name> postgresql, cockroachdb, yugabytedb, mysql, mariadb, tidb, sqlserver, oracle, h2, hsqldb, derby, sqlite
--classpath <paths> Extra classpath; skips Maven/Gradle resolution
--no-build Do not run Maven/Gradle; use compiled classes
--refresh Re-resolve dependencies even if cached
--database <name> Work on migrax.databases.<name> instead of the default database
--dir <path> Project folder (default: current folder)

sql

migrax sql <migration>

Prints a migration file from the migration folder.

Option Meaning
--locations <paths> Migration folders, comma-separated (e.g. filesystem:db/sql)
--database <name> Work on migrax.databases.<name> instead of the default database
--migrations-only Only look in the migration folders
--dir <path> Project folder (default: current folder)

version

migrax version

Prints the Migrax version.

help

migrax help [command]

Shows general help, or help for one command.