Blogbody Rotating Header Image

The beauty of an upgrade framework

Today we upgraded HostedQA, which required the schema to be changed a bit. It is a time like this that the value of an automated upgrade framework really pays off.

INFO: Looking up upgrade class com.hostedqa.upgrade.UpgradeToBuild1
INFO: Upgrading to build 1…
INFO: Upgrade to build 1 SUCCESS
INFO: Looking up upgrade class com.hostedqa.upgrade.UpgradeToBuild2
INFO: Upgrading to build 2…
INFO: Upgrade to build 2 SUCCESS
INFO: Looking up upgrade class com.hostedqa.upgrade.UpgradeToBuild3
INFO: Upgrading to build 3…
INFO: Upgrade to build 3 SUCCESS

Simply using something like Hibernate’s schema update utilities isn’t good enough. It takes you from step A to Z without giving you an opportunity to make iterative changes to the data, as I had to do today. To really make software easy to deploy, you need to streamline the upgrade process to be trivial while also automating upgrades from any arbitrary version to any other arbitrary version.

Part of doing that is building an upgrade framework that will handle changing your data using a combination of Java code and SQL. The reason you need both is because sometimes there is complex logic that is required to shuffle data around. Again, today we had that very need so simple SQL scripts wouldn’t suffice.

Word is that Jive Software has a pretty sweet upgrade framework in their latest version of Jive Forums. I think more software needs to take the approach that HostedQA, JIRA, Confluence, and Jive Forums do: make upgrades painless by investing in a upgrade framework.

Not just for enterprise software

Because HostedQA is, well, hosted, it doesn’t really need an upgrade framework as much as the other enterprise software listed do. Atlassian has been doing this for years (though I don’t think theirs is advanced as it could or should be). However, we invested in the framework anyway because we believe that not only is it nice for customers, it makes development easier.

How many times has an engineer in your team sent out an email along these lines:

Gang,
I recently made some pretty big changes to the whiz_bang table. You’ll need to add these 3 columns to your local database before you can use the latest code checked in to SVN. Sorry about the trouble!

Bob

I’ve seen this all the time. It’s a problem because it puts a larger burden on good communication when a simple automatic solution is readily available with very limited development. If your team had an upgrade framework, “Bob” wouldn’t have to send out an email and depend on each team member reading the email and correctly executing his recommended steps. In short: it eliminates room for human error during development.

So I recommend making an upgrade framework core to any application. Enterprise software? Definitely. Hosted applications, like HostedQA? Absolutely. Internal applications? Why not! It is a big win all around and requires very little effort to get a basic framework in place.

Restrictions on your framework

One word of advice if you decide to add an upgrade framework to your application, do not depend on your OR framework (ie: Hibernate) to update the schema. As mentioned previously, it doesn’t give you the opportunity to take the iterative steps needed when upgrading from very old builds/versions. It also doesn’t give you the opportunity to execute Java code to populate data as the schema changes, which often is required.

On top of that, don’t make your upgrade scripts (such as the class UpgradeToBuild2, as seen in the HostedQA logs) depend on much of your application. If you can, avoid calling any of your APIs and stick to straight JDBC. Even better, make your upgrade framework a standalone project so you can’t get caught doing something like that.

The reason? Simple: your code will change over time. Suppose in Whizbang Version 1.0 your FooService understood that the foo table had three columns and mapped it to Foo objects appropriately. Then in Version 2.0, you write an upgrade task that uses FooService to do some data manipulation. Then in Version 3.0, you change the foo table to have two additional columns.

Now imagine someone upgrades from Version 1.0 to Version 3.0 by dropping in whizbang.war to their webapps directory. When the Version 2.0 upgrade task runs, it will run the FooService that was built for Version 3.0 (the one that assumes there are five columns instead of three). Of course, the Version 3.0 schema changes haven’t been executed yet, and so the FooService will fail with SQL query errors.

So by avoiding your APIs and OR mapping frameworks and sticking to straight JDBC, you can make a truly robust upgrade framework that benefits customers, developers, sales, and support. It’s truly a win-win for everyone!

Advanced upgrade framework features

HostedQA’s upgrade framework, like Atlassian’s, is pretty simplistic: it runs and if there is an error it stops. There are opportunities to make the end user experience better if you’re willing to invest a little extra time.

Jive went ahead and made their upgrade framework prompt the user that an upgrade needs to take place (asking the user for the admin password before proceeding). Then, when any error happens, the individual task that failed is reported to the user and manual upgrade steps are presented. The user can stop the upgrade at that point and call support or do the manual steps and continue the upgrade.

This type of stuff is great for users of your software, but typically isn’t required for software like HostedQA or internal-only applications. But if you’re writing enterprise software, you might want to take your upgrade framework one step further and implement something like what Jive has. Your users and your support team will thank you!

Update 8/4/2006:

A few follow up blog entries

5 Comments on “The beauty of an upgrade framework”

  1. #1 Don Brown
    on Aug 4th, 2006 at 8:14 am

    Great post, now if only it had implementation details… :) Anyways, I’ve played with implementing this with Spring 2.0 and have documented my finds on my blog (silly trackback in Roller is throwing an NPE).

  2. #2 loge
    on Aug 4th, 2006 at 10:20 am

    How about starting something as stated on Dons blog? Spring based would be perfect but i am open to other alternatives. This should be an overseeable thingy to work on. Most of the time will be spent to spec out the notation of SQL scripts and java helper programs for pushing new data into new fields…

    We could get a project place and discuss the architecture there.

    Marc

  3. #3 Patrick Lightbody
    on Aug 4th, 2006 at 10:44 am

    Marc,
    I do think there is room for a standalone project to help with this, though I think it would be even better if it was integrated as part of a larger stack (a la Rails). Would you be open to getting involved in something like that? I have a start on it, which is where my upgrade framework came from in the first place.

  4. #4 Sam SF
    on Sep 9th, 2007 at 5:08 pm

    I started a project to do this and have open sourced it. Here is a link to the blog entry where I describe it:

    http://www.javarants.com/2007/09/09/agile-database-schema-migration-tool-for-java/

  5. #5 Adam
    on Nov 5th, 2008 at 12:59 pm

    Great article, thanks!

    LiquiBase is one hopeful take at a standardized upgrade/migration tool.

Leave a Comment