BT

Creating Ruby Style Migrations In Java

| by Rob Thornton Follow 0 Followers on Oct 16, 2006. Estimated reading time: 1 minute |
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

Adoption Stage
Style

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.

Tell us what you think

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

Email me replies to any of my messages in this thread

Scriptella does support cross database scripts. by Fyodor Kupolov

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.*">
COMMIT;
SHUTDOWN;
</dialect>

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.

Regards,
Fyodor Kupolov

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

Email me replies to any of my messages in this thread

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

Email me replies to any of my messages in this thread

1 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT