Migrations for Java

JavaRuby on-RailsMigration

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

Liquibase is another project in this domain worth checking out.

Solution 3 - Java

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.

Solution 4 - Java

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.

Solution 5 - Java

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.

Solution 6 - Java

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.

Solution 7 - Java

Migrate4j seems like a candidate, but the project doesn't look mature enough for production usage.

Solution 8 - Java

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).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJosh MooreView Question on Stackoverflow
Solution 1 - JavaAxel FontaineView Answer on Stackoverflow
Solution 2 - JavaAdam MonsenView Answer on Stackoverflow
Solution 3 - JavaKyle BurtonView Answer on Stackoverflow
Solution 4 - JavaBrian DeterlingView Answer on Stackoverflow
Solution 5 - JavaWinkyView Answer on Stackoverflow
Solution 6 - JavaKiefView Answer on Stackoverflow
Solution 7 - JavareacunaView Answer on Stackoverflow
Solution 8 - JavaPascal ThiventView Answer on Stackoverflow