Skip to content
Latchkey

flyway migrate: Apply Migrations in CI

flyway migrate scans the configured locations and applies every pending versioned migration in order.

migrate is the command a pipeline runs to bring a database up to the latest schema. It records each applied migration in the schema history table so it only runs new ones.

What it does

flyway migrate compares the migrations on disk against the flyway_schema_history table and applies any that have not run yet, in version order. It is idempotent: running it twice applies nothing the second time.

Common usage

Terminal
flyway -url=jdbc:postgresql://localhost:5432/app \
  -user=ci -password="$DB_PASSWORD" \
  -locations=filesystem:./sql migrate

# from a config file instead of flags
flyway -configFiles=flyway.ci.conf migrate

Options

FlagWhat it does
-url=<jdbc>JDBC connection URL for the target database
-user / -passwordDatabase credentials (prefer env or config for secrets)
-locations=<list>Where migrations live, e.g. filesystem:./sql or classpath:db/migration
-baselineOnMigrate=trueBaseline a non-empty schema on first migrate
-outOfOrder=trueAllow a lower-version migration to run after a higher one
-schemas=<list>Schemas Flyway manages

In CI

Run migrate as its own step before the app deploys, so a failed migration blocks the release. Pass the password via -password="$DB_PASSWORD" from a secret, not a literal. Flyway takes a lock on the schema history table, so concurrent runners serialize rather than clobber each other.

Common errors in CI

"Validate failed: Migration checksum mismatch for migration version X" means a file that already ran was edited; restore it or run flyway repair. "Found non-empty schema(s) without schema history table" means Flyway is pointed at an existing database it did not create; set -baselineOnMigrate=true or run flyway baseline. "Migration V2__x.sql failed" prints the failing SQL and rolls back that migration on transactional databases.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →