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?
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
Thanks Nathan! This sounds good!
What about iBATIS 3 Schema Migrations System – http://ibatis.apache.org/java.cgi
Seems to achieve what you are trying to do
Thanks for the suggestion! I will take a look into this.
Thank you for the informative article! The persistent URL address for the DMT (Data Migration Toolkit) is http://www.purl.org/dmt The DMT has been recently released in its version 2.2 which includes updates and code revisions.
Pingback: Liquibase + Hibernate (annotations). Easy and solid Database Migration. « Find Time for the Karussell
I’ve put a comparison matrix (with Liquibase & migrate4j among others) up on the Flyway website: http://code.google.com/p/flyway/
I hope it’ll help you with your decision making.
Cheers
Axel
Axel, nice! Thanks a lot!
BTW: liquibase supports groovy as well as any other scriptin language: http://www.liquibase.org/generate-changelog-with-groovy
with liquibase is also possible to execute via maven target.
Another important thing is the license you should add.
You should also mention that there are a lot more databases liquibase supports http://www.liquibase.org/databases
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.