Migration files
V<n>__<desc>.sql
Versioned migration (runs once)
Two underscores between version and description, e.g.
V2__add_users.sql
R__<desc>.sql
Repeatable migration
U<n>__<desc>.sql
Undo migration for a version
Undo needs a paid edition
B<n>__<desc>.sql
Baseline migration
flyway add -description=<text>
Create next versioned script
flyway add -type=undo
Create undo script
flyway add -version=<v>
-description=<text>
Create script with explicit version
flyway add -timestamp -description=<text>
Add timestamp to version
flyway add -location=<path>
Choose target directory
flyway add -add.nameOnly=true -q
Print the file name only
${<name>}
Placeholder inside SQL
-locations=filesystem:<dir>
Where to scan for scripts
Project and setup
flyway init -projectName=<name>
-databaseType=<type>
Generate project and flyway.toml
flyway init -from=flyway.conf -fromType=Conf
Upgrade an old .conf file
flyway list engines
List supported databases
flyway -environment=<env>
Pick the target environment
flyway -configFiles=<file>
Use a specific config file
flyway -url="<jdbc-url>" -user=<u>
-password=<p> migrate
Connect without a config file
-schemas=<a>,<b>
Schemas Flyway manages
-workingDirectory=<dir>
Run as if in another directory
Migrate and inspect
flyway migrate
Apply all pending migrations
flyway info
Show applied and pending
flyway validate
Compare files with history
flyway migrate -target=<version>
Stop at a version
flyway migrate -outOfOrder=true
Allow lower versions after higher
flyway migrate -baselineOnMigrate=true
Baseline a non-empty DB on first run
flyway migrate -validateOnMigrate=false
Skip validation (avoid)
flyway migrate -mixed=true
Mix transactional and non-transactional
flyway info -infoOfState=pending
Filter by state
flyway info -infoSinceVersion=<v>
From a version onwards
flyway info -infoSinceDate="dd/MM/yyyy HH:mm"
Applied after a date
flyway info -migrationIds=true
Print only the ids
flyway undo
Undo the last versioned migration
Repair and recover
flyway repair
Remove failed rows, realign checksums
Use the same locations as migrate; clean up objects a failed
script left behind by hand
flyway baseline
Mark existing DB as migrated
flyway baseline -baselineVersion=<v>
Baseline at a version
flyway clean -cleanDisabled=false
Drop all objects in schemas
Never against production
flyway check -code
Review migrations with code analysis
flyway check -dryrun
Preview a deployment script
flyway check -drift
Detect out-of-band changes
flyway check -changes
Report pending changes
Configuration
flyway.toml
Project config file
[environments.<name>] url, user, password
Define an environment
[flyway] locations = ["filesystem:sql"]
Flyway settings in TOML
FLYWAY_URL / FLYWAY_USER / FLYWAY_PASSWORD
Env var overrides
locations
Folders scanned recursively
table
Name of the history table
defaultSchema
Schema holding the history table
baselineVersion
Version used by baseline
sqlMigrationPrefix / sqlMigrationSeparator
Change naming defaults
connectRetries
Retry connecting to the DB
[flyway.placeholders] name = "value"
Define placeholders
beforeMigrate.sql / afterMigrate.sql
Callback scripts in locations
-outputType=json
Machine-readable output
-outputFile=<file>
Also write output to a file