Thursday, February 19, 2015

Database Migrations for Java Application

One of the tools that I've used in the recent days that merits a blogpost is Flyway.
Flyway is a database migration tool that provides database state migration in applications that do not have a built in migration.
Rails and (some) rails based frameworks already have this, but it is pain to implement this in say, a java application. Flyway alieviates the need to create this as it has native support for many popular databases(including cloud based Dbs and counting?) as well as a Java based api with support for build tools like ant, maven and gradle.
It has only 6 basic functions: Migrate, Clean, Info, Validate, Baseline and Repair.
Unlike rails, you are not restricted with timestamp values (and they are a pain if you have renamed a file and left out a digit - which makes ordering difficult to trace). Here, you can specify a file as V__.sql

While a rails developer is bound to miss the up and down in a migration file (as the rails like backward migration is missing in the current version), the rest of the application works as desired and is indeed handy.

Having some significant traction, this project is in use by different teams and does not require huge overhead/configuration to work easily with hibernate/spring based applications as well. The project is located at github so you can easily head over there to check out its source as well.