The Flyway command-line tool is a standalone Flyway distribution. It runs on Windows, macOS and Linux and it is primarily meant for users who wish to migrate their database from the command-line without having to integrate Flyway into their applications nor having to install a build tool.
Select the platform that you need. Each download contains all editions (community, pro, enterprise) of Flyway.
Extract the archive and simply add the new flyway-7.5.0
directory to the PATH
to make the flyway
command available from anywhere on your system.
Download, extract and install by adding to PATH
(requires sudo
permissions):
$ wget -qO- https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/7.5.0/flyway-commandline-7.5.0-linux-x64.tar.gz | tar xvz && sudo ln -s `pwd`/flyway-7.5.0/flyway /usr/local/bin
Or simply download the archive:
(Linux only) Download, extract and install by adding to PATH
(requires sudo
permissions):
$ sudo sh -c 'echo "docker run --rm flyway/flyway:7.5.0 $*" > /usr/local/bin/flyway && chmod +x /usr/local/bin/flyway'
(All platforms) Or simply download the image:
> docker pull flyway/flyway:7.5.0
Go to Docker Hub for detailed usage instructions.
Older versions, packages without JRE and sources are available from Maven Central
Older Docker images are available from boxfuse/flyway
The Flyway download, once extracted, now becomes a directory with the following structure:
flyway-7.5.0 conf flyway.conf configuration file drivers JDBC drivers jars Java-based migrations (as jars) jre lib licenses sql SQL migrations flyway macOS/Linux executable flyway.cmd Windows executable
> flyway [options] command
The Flyway Command-line tool distribution ships with all editions of Flyway. It defaults to Flyway Community Edition. It can however easily be configured to run the Flyway Pro or Enterprise Edition instead.
One way to switch between the various Flyway editions is to set the FLYWAY_EDITION
environment variable prior to
executing Flyway to any of the following values:
community | Select the Flyway Community Edition (default) |
pro | Select the Flyway Pro Edition |
enterprise | Select the Flyway Enterprise Edition |
Alternatively Flyway also comes with edition-selecting flags. By default the flyway
command will launch whatever
edition has been selected with the FLYWAY_EDITION
environment variable (defaulting to community
).
You can however also use edition-selecting flags to force the selection of the edition of your choice and avoid the need
to set any environment variable at all:
-community | Select the Flyway Community Edition |
-pro | Select the Flyway Pro Edition |
-enterprise | Select the Flyway Enterprise Edition |
Name | Description |
---|---|
migrate | Migrates the database |
clean | Drops all objects in the configured schemas |
info | Prints the details and status information about all the migrations |
validate | Validates the applied migrations against the ones available on the classpath |
undo Flyway Pro | Undoes the most recently applied versioned migrations |
baseline | Baselines an existing database, excluding all migrations up to and including baselineVersion |
repair | Repairs the schema history table |
In order to connect with your database, Flyway needs the appropriate JDBC driver to be available in its drivers
directory.
To see if Flyway ships with the JDBC driver for your database, visit the Driver section of the documentation page for your database. For example, here is the Oracle Drivers section.
If Flyway does not ship with the JDBC driver, you will need to download the driver and place it in the drivers
directory yourself. Instructions on where to download drivers from are also in the Driver section of the documentation page for each database, under Maven Central coordinates
.
The Flyway Command-line tool can be configured in a wide variety of ways. You can use config files, environment
variables and command-line parameters (except for FLYWAY_EDITION
, which is not available in config files and
should be used as specified above). These different means of configuration can be combined at will.
Config files are supported by the Flyway command-line tool. If you are not familiar with them, check out the Flyway config file structure and settings reference first.
Flyway will search for and automatically load the following config files if present:
<install-dir>/conf/flyway.conf
<user-home>/flyway.conf
<current-dir>/flyway.conf
It is also possible to point Flyway at one or more additional config files. This is achieved by
supplying the command line parameter -configFiles=
as follows:
> flyway -configFiles=path/to/myAlternativeConfig.conf migrate
To pass in multiple files, separate their names with commas:
> flyway -configFiles=path/to/myAlternativeConfig.conf,other.conf migrate
Relative paths are relative to the current working directory.
Alternatively you can also use the FLYWAY_CONFIG_FILES
environment variable for this.
When set it will take preference over the command-line parameter.
> export FLYWAY_CONFIG_FILES=path/to/myAlternativeConfig.conf,other.conf > flyway migrate
By default Flyway loads configuration files using UTF-8. To use an alternative encoding, use the command line parameter -configFileEncoding=
as follows:
> flyway -configFileEncoding=ISO-8859-1 migrate
Alternatively you can also use the FLYWAY_CONFIG_FILE_ENCODING
environment variable for this.
When set it will take preference over the command-line parameter.
> export FLYWAY_CONFIG_FILE_ENCODING=ISO-8859-1
To make it easier to work with cloud and containerized environments, Flyway also supports configuration via environment variables. Check out the Flyway environment variable reference for details.
Finally, Flyway can also be configured by passing arguments directly from the command-line:
> flyway -user=myuser -schemas=schema1,schema2 -placeholders.keyABC=valueXYZ migrate
Some command-line arguments will need care as specific characters may be interpreted differently depending on the
shell you are working in. The url
parameter is particularly affected when it contains extra parameters with
equals =
and ampersands &
. For example:
bash, macOS terminal and Windows cmd: use double-quotes:
> flyway info -url="jdbc:snowflake://ab12345.snowflakecomputing.com/?db=demo_db&user=foo"
Powershell: use double-quotes inside single-quotes:
> ./flyway info -url='"jdbc:snowflake://ab12345.snowflakecomputing.com/?db=demo_db&user=foo"'
You can provide configuration options to the standard input of the Flyway command line. Flyway will expect such configuration to be in the same format as a configuration file.
This allows you to compose Flyway with other operations. For instance, you can decrypt a config file containing login credentials and pipe it straight into Flyway.
Read a single option from echo
:
> echo $'flyway.url=jdbc:h2:mem:mydb' | flyway info
Read multiple options from echo
, delimited by newlines:
> echo $'flyway.url=jdbc:h2:mem:mydb\nflyway.user=sa' | flyway info
Use cat
to read a config file and pipe it directly into Flyway:
> cat flyway.conf | flyway migrate
Use gpg
to encrypt a config file, then pipe it into Flyway.
Encrypt the config file:
> gpg -e -r "Your Name" flyway.conf
Decrypt the file and pipe it to Flyway:
> gpg -d -q flyway.conf.gpg | flyway info
The Flyway command-line tool has been carefully designed to load and override configuration in a sensible order.
Settings are loaded in the following order (higher items in the list take precedence over lower ones):
<current-dir>/flyway.conf
<user-home>/flyway.conf
<install-dir>/conf/flyway.conf
The means that if for example flyway.url
is both present in a config file and passed as -url=
from the command-line,
the command-line argument will take precedence and be used.
If you do not supply a database user
or password
via any of the means above, you will be
prompted to enter them:
Database user: myuser Database password:
If you want Flyway to connect to your database without a user or password, you can suppress prompting by adding
the -n
flag.
There are exceptions, where the credentials are passed in the JDBC URL or where a password-less method of authentication is being used.
If you need to to pass custom arguments to Flyway’s JVM, you can do so by setting the JAVA_ARGS
environment variable.
They will then automatically be taken into account when launching Flyway. This is particularly useful when needing to set JVM system properties.
By default, all debug, info and warning output is sent to stdout
. All errors are sent to stderr
.
Flyway will automatically detect and use any logger class that it finds on its classpath that derives from any of the following:
org.apache.commons.logging.Log
org.slf4j.Logger
android.util.Log
The simplest pattern to achieve this is to put all the necessary jar files in Flyway’s lib
folder and any
configuration in the FLyway root folder.
For example, if you wished to use log4j with the Flyway command line, you would achieve this by placing the
log4j jar file log4j-<version>.jar
and the corresponding
configuration file log4j.xml
like this:
flyway-7.5.0 conf drivers jars jre lib log4j-2.13.1.jar log4j jar licenses sql log4j.xml log4j configuration
Similarly, to use Logback add the relevant files like this:
flyway-7.5.0 conf drivers jars jre lib logback-classic.1.1.7.jar Logback jar logback-core-1.1.7.jar Logback jar slf4j-api-1.7.21.jar Logback dependency licenses sql logback.xml Logback configuration
If you are building Flyway into a larger application, this means you do not need to explicitly wire up any logging if you use one of these frameworks.
By default the output is automatically colorized if stdout
is associated with a terminal.
You can override this behavior with the -color
option. Possible values:
auto
(default) : Colorize output, unless stdout
is not associated with a terminalalways
: Always colorize outputnever
: Never colorize outputAdd -X
to the argument list to also print debug output. If this gives you too much information, you can filter it
with normal command-line tools, for example:
bash, macOS terminal
> flyway migrate -X | grep -v 'term-to-filter-out'
Powershell
> flyway migrate -X | sls -Pattern 'term-to-filter-out' -NoMatch
Windows cmd
> flyway migrate -X | findstr /v /c:"term-to-filter-out"
Add -q
to the argument list to suppress all output, except for errors and warnings.
Add -json
to the argument list to print JSON instead of human-readable output. Errors are included in the JSON payload instead of being sent to stderr
.
Add -outputFile=/my/output.txt
to the argument list to also write output to the specified file.