The first step to knowledge…

Menu

Flyway command-line easy setup

One of the reasons for adopting Flyway command-line was the easy setup process (no need to install). First, I will show how to setup Flyway for a single database, i.e., as if have only one database in your server, and than the setup for multiple databases in a server.

Single database

After download and extract you have the following folders/files structure:

In this case it’s only necessary to work the “flyway.conf” file (you can find it in conf folder):

Set url to target server/database

Set user and password to target server/database

Alternatively you don´t need to set user and password on the configuration file, it can be provided as argument.

Shell

1

flyway.cmd-user=eduardo.piairo-password=eduardo.piairoinfo

Multiple databases

Because numbers matter! If you have two or more databases in your server, a option is to apply the single database setup for every database. This approach will lead to an unnecessary files multiplication. As alternative we can create a centralized folder dedicated to the Flyway application.

Extract Flyway for a folder and change the name of the folder for flyway;

Create a folder each one of your databases (MyDatabase1, MyDatabase2, …);

Create the folder flyway_conf and copy the file flyway.conf inside;

For flyway.conf file set url, user and password for the target database;

Uncomment the locations configuration and set his value with “filesystem:.” (flyway.locations=filesystem:.). This means that Flyway will scan recursively for migrations the folder that contains the flyway.cmd (MyDatabase1 for example);

Create the file flyway.cmd with the following code inside:

Shell

1

..\flyway\flyway.cmd-configFile=./flyway_conf/flyway.conf%*

After this you can execute the flyway command from each database.

And that’s it! You are ready for manage the changes of multiple databases.

Multiple servers

If you have multiple servers like: dev, test, staging, … the solution is to create a flyway.cmd and flyway.conf for each server/environment.

Inside flyway/flyway_conf folder create a flyway_servername.conf file for each server (flyway_dev.conf, flyway_test.conf) and set the url, user and password for the target server and database;

Create a flyway_servername.cmd file for each server (flyway_dev.cmd, flyway_test.cmd). Muke sure that you are using the correct configuration file;

You just have to execute the flyway command for the intended server/environment.

User and Password

Because we want to source control all migrations and Flyway related files, saving the user name and the password in plain text in the configuration file it’s not such a good idea. So, where’s a solution: