Flyway: “Hello database migrations”


Flyway is a open source database migration tool that allows you to manage database changes using migrations. Last week the version 4.0.1 has been released and I decided to write my first post about Flyway.

I started to use Flyway command-line almost 3 years ago (version 2.2.1) and the main reason that took me to use and keep using nowadays is: it’s simplicity, “database migrations made easy”. This key factor is translated into the following:

  • Zero dependencies (you need java and your jdbc driver)
    • You can download the version that already includes both: java and the driver;
    • This is a key factor for the easy setup process;
  • Easy to setup, no need to install
    • You just have to configure Flyway: target server, migrations location, etc;
    • This makes the deploy process extremely easy;
  • The scripts are written in SQL
    • You, or your team, do not have to learn or use a different language to create migrations.

Flyway commands

Flyway provides 6 basic commands:

  • migrate
    • Apply all migrations until the latest version, or until a specific target version;
    • If the metadata table doesn’t exist this command will create it automatically;
    • This is they key command of the Flyway workflow;
  • clean
    • Drops all database objects in the configured schemas;
    • This command should be used with caution, especially in system databases or in production environment;
    • Its useful in development and test environments enabling a fresh start  cleaning completely your database;
  • info
    • Gives the current status information about all the migrations;
    • This is done by checking the migrations scripts against the metadata table;
    •  Allows you to know if a migration was applied with success, or still pending or was ignored;
  • validate
    • Validates applied migrations against the available migration scripts on your folder;
    • Allows to validate if all migrations were applied, i.e. do not exist pending migrations;
    • Allows to validate if a migration script was change after being successfully applied;
      • This validation is made trough checksum validation;
      • Allows to reliably recreate the database schema;
  • baseline
    • Allows to set the baseline of an existing database;
    • All migrations upto and including the baseline version will me ignored;
    • If the metadata table doesn’t exist this command will create it automatically;
  • repair
    • This command repairs the metadata table;
    • Remove migrations from the table marked as failed;
    • Realign the checksums of the applied migrations to the ones of the available migrations


Flyway configuration

The Flyway configuration can be specified in two ways:

  1. In the configuration file: flyway.conf
  2. In the command-line using the format “-key=value” (this way overrides the previous one)

The following picture shows all available configuration options for Flyway version 3.2.1:


Flyway metadata table

The metadata table is used to track the state of the database. Allows to know which migrations have already been applied, when were applied and by whom. Additionally also tracks migration checksums.


The default name of the metadata table is “schema_version”. If the database is empty and the metadata table do not exist, Flyway will create it automatically.

Flyway scans the migrations directory and check migrations against the metadata table. Migrations are sorted based on their version number and applied in order.

Flyway command-line structure

When you download and extract Flyway command-line you will find the following structure:


  • conf
    • In the folder you will find the configuration file “flyway.conf”
  • drivers
    • This folder contains the jdbc drivers
  • jars
    • In this folder you can add java migrations
  • lib
    • This folder contains Flyway jar files
  • sql
    • In this folder you can add SQL migrations
  • flyway.cmd
    • File responsible for executing Flyway (Windows command script)


Arduino Christmas Lights

One of my first projects using Arduino happened during the Christmas season, so seemed a good idea to create Christmas lights to illuminate and brighten the house.

The first step is to gather the necessary hardware:

  • 1 x Arduino, I used the Arduino 2009;
  • 2 x breadboard, should be enough to perform the tests;
  • 1 x switch button, it will be used to switch between the diferrent lightning effects;
  • 8 x red LEDs
  • 8 x green LEDs
  • 8 x yellow LEDs
  • 4 x 56Ω resistor
  • 4 x 33Ω resistor
  • 4 x 47Ω resistor
  • 1 x 10kΩ resistor
  • wiring

The second step is to connect LEDs so that there are no excessive current circulating in the circuit since a small change in voltage may cause large current variations (the current through an LED varies exponentially according to the voltage that crosses).

The solution is to use resistors, which have the purpose of limiting the amount of current to a safe value. To define the resistors values and the appropriate way to connect the LEDs I resorted to the following website: LED center.

Relevant information:

  • DC source voltage: 5V (Arduino output)
  • Forward voltage:
    • Red LED: 2.0V
    • Yellow LED: 2.1V
    • Green LED: 2.2V
  • Forward current: 20mA for 3mm and 5 mm LEDs
  • Number of LEDs: 4 x LEDs for each Arduino output (it were used 6 outputs)
Red LEDs
Yellow LEDs
Green LEDs

The represent the whole circuit I used Fritzing. This tool, which is an open-source project, allows documenting prototypes, share those same prototypes and even design the layout of a printed circuit board (PCB).

Circuit using breadboards

To download the Fritzing file (.fz extension) click here.And so it concludes the part referring to the hardware.

The third step is the lighting effects program creation for Arduino. The program was written using the Arduino IDE and is defined by a set of lighting effects and the ability of switch between them. The following lighting effects were defined:

  1. blinkAllLights:  the lights turn on and off periodically;
  2. runningLights 0: the lights starts as off and then light up and down successively;
  3. fadingLights: the LEDs intensity is increased and decreased step by step;
  4. runningLights 255:  the lights starts as on and then light down and up successively;
  5. Adds the above affects,1 to 4, in a sequential manner within a loop.

The switch button lets you toggle between the different lighting effects. It should be mentioned that the fading effect implies using the PWM Arduino outputs.

The code can be downloaded from this link.

Merry Christmas and Happy New Year!