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.
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:
- Set up site with test data.
- Code update.
- Run update.php.
- Make sure everything went as planned.
- 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.
(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.
So, now the new workflow is the following, and it’s easy to ensure upgrades are working well.
- Code changes.
- Run script