I use both ruby on rails and Java. I really enjoy using migrations when I am working on a rails project. so I am wondering is there a migrations like tool for Java? If there is no such tool is it a good idea to use migrations as a tool to control a database used by a Java project?
8 Answers
For a feature comparison between
- Flyway
- Liquibase
- c5-db-migration
- dbdeploy
- mybatis
- MIGRATEdb
- migrate4j
- dbmaintain
- AutoPatch
have a look at http://flywaydb.org
This should be a good start for you and anyone else to select the right tool for the job

- 34,542
- 16
- 106
- 137
-
2Hey, I wasn't aware of Flyway. It looks pretty interesting and I'll have a closer look at it. Thanks for mentioning Flyway! – Pascal Thivent Oct 13 '10 at 13:42
-
@Pascal Thivent Thanks for your comment! If you do evaluate it, I'd be glad to hear your opinion/criticism/suggestions about it, either here or in Flyway's issue tracker :-) I'll also look into adding DbMaintain to the comparison matrix as it looks like a great competitor... – Axel Fontaine Oct 14 '10 at 09:30
-
Sure, I will. And thanks for adding DbMaintain to the comparison, it's very nice to have such a matrix. – Pascal Thivent Oct 14 '10 at 10:42
-
@Pascal Thivent It took a while, but I finally got around to it. dbmaintain and AutoPatch are now included. – Axel Fontaine Dec 23 '10 at 20:35
-
3Thanks for posting this. I just started using Flyway today. I've previously used liquibase and in one project they rolled their own solution. Flyway is what I was expecting liquibase to be. Simple, no xml, and I can write more complex migrations in java. Perfect. Looking forward to ant support. – nogridbag Aug 10 '11 at 20:28
-
1The current version of the website appears to only compare Flyway, Liquibase and MyBatis. Is the full comparison still available elsewhere? – Zero3 Mar 30 '16 at 14:07
-
@AxelFontaine I think it would be suitable if you added a note to your answer about the comparison being biased since you are the creator of Flyway. – Zero3 Mar 30 '16 at 14:14
-
@Zero3 The other tools haven't seen an update in years. Which one do you feel should be readded? Also which part do you feel is not objective/accurate? – Axel Fontaine Mar 30 '16 at 17:03
-
@AxelFontaine That's very nice information to have! I think it would be a good addition to your answer if you would not mind updating it. I know none of the tools already, so I have no idea whether or not the comparison is accurate. For all I know, your comparison is perfectly objective and accurate. I just think it would be nice with the disclosure when you have a strong personal connection with one of the products in the comparison. – Zero3 Mar 31 '16 at 12:00
-
I think it may be a good idea to group the ones that are no longer active. It's a waste of time to even look at some of those tools. – Jamel Toms Dec 18 '17 at 03:14
-
As of 2021 http://flywaydb.org no longer has the mentioned feature comparison. – salomvary Apr 14 '21 at 23:16
Grails has a dbmigrate utility that is patterned after the one from Rails. Since it's implemented in Groovy, you should be able to use it from any of your Java projects.

- 26,788
- 9
- 50
- 60
I've used Hibernate's SchemaUpdate to perform the same function as migrations. It's actually easier than migrations because every time you start up your app, it examines the database structure and syncs it up with your mappings so there's no extra rake:db:migrate step and your app can never be out of sync with the database it's running against. Hibernate mapping files are no more complex than Rails migrations so even if you didn't use Hibernate in the app, you could take advantage of it. The downside is that it's not as flexible as far as rolling back, migrating down, running DML statements. As pointed out in the comments, it also doesn't drop tables or columns. I run a separate method to do those manually as part of the Hibernate initialization process.
I don't see why you couldn't use Rails migrations though - as long as you don't mind installing the stack (Ruby, Rake, Rails), you wouldn't have to touch your app.

- 13,556
- 4
- 55
- 59
-
22It doesn't sync it 100%. It doesn't alter columns, delete columns or tables, remove FKs etc. – cherouvim Aug 26 '09 at 20:06
I ran across this post while researching the same question. I haven't come to any conclusions about the best tool or approach yet, but one tool that I've come across which hasn't been mentioned in other answers so far is dbdeploy. I'd be interested to read any comparisons of these tools.
Some other relevant resources: Martin Fowler and Pramod Sadalage's somewhat aged post on Evolutionary Database Design, and the book Refactoring Databases: Evolutionary Database Design by Sadalage and Scot Ambler.

- 4,383
- 4
- 26
- 21
There are also two independent implementations of rails-like migrations for Java:
1) Maven-based migrations from Carbon Five
2) Ant-based tasks from Hashrocket (my personal favorite)
Although these packages were written for Maven and Ant specifically, with some work you can adapt them to just about anything.
-
5Hashrocket hasn't been touched since 2007. Carbon Five's c5-db-migration product hasn't been updated since 2010. – Green Jul 15 '14 at 20:46
There is also DbMaintain which has been initially developed inside Unitils but is now a dedicated project. We are currently using it and are very satisfied (which doesn't mean there aren't any good alternatives). I list more of them in my database+migration bookmarks (with a focus on tools supporting Maven).

- 562,542
- 136
- 1,062
- 1,124
-
1
-
@Arthur Yes, it's very a good thing we got some tools like that too. Cascading schema updates from one environment to the other is now a pleasure for us :) – Pascal Thivent Oct 14 '10 at 06:59