Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Creating Ruby Style Migrations In Java

Creating Ruby Style Migrations In Java

Database migrations are a critical piece of any project upgrade. The most common Java database migration tool is writing scripts and executing them by hand. Most projects that have a tool end up rolling their own but there are several open-source tools out there which tackle the problem in different ways. Available tools include Migrator (a set of Ant tasks for doing database migration in the style of ActiveRecord, a part of the Ruby on Rails platform), Scriptella (mainly an ETL tool but schema migrations are possible), and DdlUtils (database independent migrations).

Migrator is currently out in beta, and has no documentation, but Obie Fernandez just wrote an overview. Migrator is easy-to-use, but is undocumented and relies on SQL and therefore your migrations are not portable to other databases. It is an attempt to bring the functionality of ActiveRecord migrations to Java.

Scriptella, which has gone from a 0.1 release to version 0.4 in the last two months, is primarily a Extract-Transform-Load (ETL) tool. However, it does provide the capability to do schema migrations. In their examples, they provide a demonstration of how to do migrations, with documentation. Scriptella is primarily used from Ant and uses straight SQL in the query and script sections of its XML configuration file, thus it is not cross-database (although it nicely supports moving data from one database to another, you have to write both sets of SQL yourself).

DdlUtils is an Apache project that first and foremost handles straight DDL changes to your database in a cross-platform way. Guy Davis blogged how to use DdlUtils in a cross-database way including dumping and loading data. One limitation of DdlUtils is that it currently does not have the ability to capture or create triggers, constraints, or stored procedures.

Of the above projects, DdlUtils has been around the longest, although Sciptella was developed in-house and then open-sourced so it is also fairly stable. Migrator shows good promise, but it is too soon to say how it will develop.

InfoQ covered some similar ideas back in August when talking about the broader idea of project updates.

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Scriptella does support cross database scripts.

    by Fyodor Kupolov,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Hello Rob,

    First I'd like to thank you for mentioning Scriptella. But I have several important notes.

    Scriptella supports cross database scripts via dialect elements. Example:

    INSERT INTO Table VALUES(...);
    <dialect name=".*hsql.*">

    So you can write most of your code in ANSI SQL and only add small vendor specific code snippets if necessary. See Best Practices for additional tips on how to write cross database scripts.

    Scriptella is mainly an ETL and scripts execution tool, so schema evolution is just one of possible usages. With Scriptella you can work with databases, LDAP directories, Velocity etc. simultaneously and this feature is very important in complex deployment scenarious. I'd like to note that SQL is not the only supported language, our phylosophy is to use a suitable language for the datasource, e.g. LDIF for inserting data into directories.

    Originally Scriptella was created to migrate our customer production Sybase DB to HSQLDB with additional schema changes. Then we used it to synchronize Oracle DB with LDAP directory. And finally we've tried Scriptella as a schema evolution tool.

    We also use Scriptella for test data generation, benchmarking and preparing an in-memory database for testing. Besides Ant and command line launchers Scriptella can be easily integrated with Java code, Spring Framework and Java EE environment.

    Fyodor Kupolov

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p