Todd has posted 1 posts at DZone. View Full User Profile

Migrate4j - Database Migration Tool for Java

  • submit to reddit

Migrate4j is a migration tool for java, similar to Ruby's db:migrate task. Unlike other Java based migration tools, database schema changes are defined in Java, not SQL. This means your migrations can be applied to different database engines without worrying about whether your DDL statements will still work.

Schema changes are defined in Migration classes, which define "up" and "down" methods - "up" is called when a Migration is being applied, while "down" is called when it is being rolled back. A simple Migration, which simply adds a table to a database, is written as:

package db.migrations;
import static com.eroi.migrate.Define.*;
import static com.eroi.migrate.Define.DataTypes.*;
import static com.eroi.migrate.Execute.*;
import com.eroi.migrate.Migration;
public class Migration_1 implements Migration
public void up()
column("id", INTEGER, primaryKey(), notnull()),
column("desc", VARCHAR, length(50), defaultValue("NA"))));

public void down()

This Migration can be applied at application startup, from an Ant task (included in migrate4j) or from the command line. Migrate4j will only apply the migration if it has not yet been applied. LIkewise, migrate4j will roll back the migration when instructed, only if the migration has been previously applied.

The migrate4j team is happy to announce a new release which adds improved usability (simplified syntax), additional schema changes and support for more database products. While migrate4j does not yet have support for all database products, we are actively seeking developers interested in helping fix this situation.

Visit for more information on how migrate4j can simplify synchronizing your databases. To obtain migrate4j, go to and download the latest release. For questions or to help with future development of migrate4j, email us at migrate4j-users AT (replacing the AT with the "at symbol").

Published at DZone with permission of its author, Todd Runstein.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Jon Chase replied on Mon, 2008/04/28 - 1:17pm

Looks nice, but does this offer anything over and above what Liquibase ( does (other than sql defined in Java instead of XML)?

I've been using Liquibase for automatic database upgrades during app deployments and it's been great - it's so nice not to have to run those scripts manually anymore!

I'm glad to see another serious project in this market - it shows that there is definitely interest, and this is something that the agile Java community has needed for a long time.


Jon Chase - Securely email large files to anyone

Todd Runstein replied on Mon, 2008/04/28 - 1:47pm


From a feature standpoint, migrate4j is intended to be very similar to Liquibase. However, our main focus is to provide a tool that uses Java to define schema changes.

If you're already using Liquibase, db:migrate, or some other migration tool, you'll probably want to stick with that. However, for Java projects that are not using a migration tool, migrate4j is an option to consider.


Jon Chase replied on Mon, 2008/04/28 - 1:53pm


Thanks for the clarification - I think Migrage4j is a good option for teams that want to stick to Java and stay out of XML.


Stefan Reuter replied on Mon, 2008/04/28 - 11:22pm

The sourceforge project page indicates that migrate4j is licenced under GPL. This means many open source projects that are using a more liberal license (e.g. Apache) as well as closed source projects won't be able to use it.

Is that by intention?

Todd Runstein replied on Tue, 2008/04/29 - 9:14am in response to: Stefan Reuter


The reason for going GPL right now is to make sure improvements get shared. As much as we'd love migrate4j to be adopted by other projects, we want all work being done to be donated back. Once our codebase is more complete, offering other licensing options is certainly a possibility.


Stefan Reuter replied on Tue, 2008/04/29 - 10:18am in response to: Todd Runstein

Thanks for your answer,

I guess you could also achieve this with LGPL which would still make sure enhancements to the library are passed back while allowing more liberal usage of the library in other projects.

LGPL is also used by LiquidBase - probably your strongest "competitor" ;)


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.