Syndicate content

Topic “easy”

By zzolo
2010, February 14 - 7:01pm

Upgrade Love with Demo and Drush : An easy workflow to testing a module upgrade path with database schema changes.

My Valentines Day consisted of coding the beginnings of the upgrade path from 1.x to 2.x of the OpenLayers module; that's some true love for the OpenLayers 1.x users.

The OpenLayers has a fairly unique situation where we have 3 major versions for Drupal 6, but they are not sequential, and going form OpenLayers 1.x to 2.x is a fairly large change. We have just released 1.0-RC1 and 2.0-alpha1, so it was about time to create an upgrade path for those folks on 1.x. Though it still needs some serious work, it's getting there. But, the point is, I ran into this problem: testing a Drupal update function with major schema changes without help can be tedious.

The Problem

Basically, a Drupal update is a specific function that gets called from update.php (or equivalent Drush command) given that the state of the module's schema is less than the newest available one. This means I have to do the following to test:

  1. Set up site with test data.
  2. Code update.
  3. Run update.php.
  4. Make sure everything went as planned.
  5. Repeat as needed (even if you have a syntax error).

Imagine doing this over and over again for a very involved upgrade process! I knew right away that this was not for me.

The Solution

(Note, there may be some much better way to do this with the Drupal SimpleTest module but I am unaware of it)

It was pretty obvious that a database dumb was going to be the best way to go; I could set up the site and then restore when I needed to test. But exporting, importing, managing changes, and just laziness kept me trying to think of something better. Then the Demo module popped into mind! The Demo module basically takes a snapshot of your database and allows you to restore to it, either through the interface or on cron runs. This seemed like a good candidate to getting around installing a new site and setting it up or using database dumps.

So, first step is to setup your Drupal site as you want it before the upgrade process. Then use the Demo module to make a snapshot. Also, it is important to install the Demo Reset module (part of Demo package) and set a default snapshot to use as we will refer to this when resetting. And! if your process changes, Demo makes it really easy to make changes to your site and save another snapshot.

Next, we just need to write a simple little script to do the restore and update (keep in mind we are going for lazy and automated). Luckily Drush is wonderful and allows us an easy way to run some simple PHP after Drupal has bootstrapped itself, and then perform the update. Here is my basic script, which is really just two commands.

Recent Books

Haiku and a Portrait

The Uncertainty Principle

Floating on the air
everywhere and somewhere,
nowhere, only here.

The Tweet of Zzolo

  • @atsmath It's just that secret! :)
    2 hours 45 min ago
  • Awesome! RT @eaton: Matt Mullenweg turns WP trademark over to the Nonprofit WordPress Foundation. Big news. Kudos! http://bit.ly/bopWpw
    4 hours 23 min ago
  • OpenLayers 2.10 out! Great work OL development team! http://trac.openlayers.org/wiki/Release/2.10 (JS library not Drupal module)
    8 hours 24 min ago
  • cool (ish). ESRI "gives away" ArcGIS to non-profit (tax-exempt), and open source its GeoPortal Ext http://bit.ly/aojcHZ http://bit.ly/cFQaR7
    8 hours 47 min ago
  • Office emaiI xchange: "I have electrons, atoms, and millions of transistors backing me", "I've faeries, pixies, Quempel and Lady Cottington"
    9 hours 21 min ago

Twitter Icon Flickr Icon LinkedIn Icon Facebook Icon Drupal Association, Individual Member icon