Java equivalent for database schema changes like South for Django?
Question: I've been working on a Django project using South to track and manage database
schema changes. I'm starting a new Java project using Google Web Toolkit and
wonder if there is an equivalent tool. For those who don't know, here's what
South does:

  * Automatically recognize changes to my Python database models (add/delete columns, tables etc.)
  * Automatically create SQL statements to apply those changes to my database
  * Track the applied schema migrations and apply them in order
  * Allow data migrations using Python code. For example, splitting a name field into a first-name and last-name field using the Python split() function

I haven't decided on my Java ORM yet, but Hibernate looks like the most
popular. For me, the ability to easily make database schema changes will be an
important factor.


Answer: Wow, South sounds pretty awesome! I'm not sure of anything out-of-the-box that
will help you nearly as much as that does, however if you choose Hibernate as
your ORM solution you can build your own incremental data migration suite
without a lot of trouble.

Here was the approach that I used in my own project, it worked fairly well for
me for over a couple of years and several updates/schema changes:

  1. Maintain a schema_version table in the database that simply defines a number that represents the version of your database schema. This table can be handled outside of the scope of Hibernate if you wish.

  2. Maintain the "current" version number for your schema inside your code.

  3. When the version number in code is newer than what's the database, you can use Hibernate's SchemaUpdate utility which will detect any schema additions (NOTE, just additions) such as new tables, columns, and constraints. 

  4. Finally I maintained a "script" if you will of migration steps that were more than just schema changes that were identified by which schema version number they were required for. For instance new columns needed default values applied or something of that nature.

This may sounds like a lot of work, especially when coming from an environment
that took care of a lot of it for you, but you can get a setup like this
rolling pretty quickly with Hibernate and it is pretty easy to add onto as you
go on. I never ended up making any changes to my incremental update framework
over that time except to add new migration tasks.

Hopefully someone will come along with a good answer for a more "hands-off"
approach, but I thought I'd share an approach that worked pretty well for me.

Good luck to you!

