Simple Database Migration in Java

As I started with Rails development I discovered the very neat feature of database migrations. For me this was the main advantage of using Rails compared to a pure Java solution.

In our Rails application this works without any problems: you can change the database schema as well as migrating the data itself via ruby.

I needed a similar feature at that time in Java and discovered Liquibase, which was relative easy to use and stable. But it has (in my opinion) one major drawback that you have to use xml and for your data migration you even have to use pure SQL. Then you’ll run fast into some issues (e.g. this). But okay, there is also one advantage over the Rails-mechanism: you don’t need to specify the rollback statement (if it is not pure SQL) – liquibase knows from the migration command which revert command it should use.

If you use Hibernate one could stick with SchemaUpdate, but several things don’t work properly with that approach.

Another idea would be to export objects from version 1 and import them into version 2 directly within your application logic e.g. with Groovy … or should I give DMT I try?

Now I thought that Grails could solve this issue better for Java, but to my knowledge (‘Automatic Database Migration’) there is not such a mature migration concept within Grails like in Rails. The Liquibase plugin (grails install-plugin liquibase) or the outdated (?) dbmigrate plugin (grails install-plugin dbmigrate) can solve this as well as autobase, which is based on liquibase too. Does somebody has experiences with that? Here is a mini comparison.

Today I discovered migrate4j, which seems to be the best tool I found so far for pure Java. Another option would be to use JRuby with Rails or simply rails, but this would be a bit of an architecture overkill for the most people, I fear.

Other choices might be:

Do you know other (better?) solutions? How do you do db migrations?


10 thoughts on “Simple Database Migration in Java

  1. If you like liquibase besides the XML format, version 2.0 has been refactored to support multiple changelog file formats. XML is the only version currently supported out of the box, but you would be able to create your own ChangeLogParser to allow you to create changelogs in any format you like

  2. Pingback: Liquibase + Hibernate (annotations). Easy and solid Database Migration. « Find Time for the Karussell

  3. Thanks for your feedback ! (sorry about the late reply, didn’t see it before today)

    I’ve integrated it in the feature matrix. The license is really important, and you were absolutely right to point it out.

    I’ve added DB2 to the list as well. I don’t know which other DBs liquibase supports have a >1% market share for productive deployments. If some of them do, I’ll gladly add them to the list.

Comments are closed.