Upgrading to Drupal 6: the Image Module

Upgrading to Drupal 6 seems like a big step, even though I can't say that I'm using many modules, nor that I have a very complicated setup. Today, during a test upgrade, I've noticed the following problem: the image module, version 6.x-1.0-alpha2 failed to upgrade with the following SQL error: Unknown column 'f.nid' in 'field list' query.

The culprit is the following SQL statement:
INSERT INTO image SELECT DISTINCT f.nid, f.fid, f.filename FROM files f INNER JOIN node n ON f.nid = n.nid WHERE n.type='image' AND f.filename IN ('_original', 'thumbnail', 'preview')

After following a very helpful tip, I've came up with the following sequence for upgrading the image module, after switching to Drupal 6:

  1. Make a backup of the 'files' table.
    CREATE TABLE files_old SELECT * FROM files;
    Please note that the backup must be made before upgrading to Drupal 6; to be more specific, before running the update.php script for the upgrade. If you've already done this, you'll probably need to restore the old files table from a backup.
  2. Run the drupal update script
    http://yoursite/update.php
  3. Run the failed SQL statement, using the old files table:
    INSERT INTO image SELECT DISTINCT f.nid, f.fid, f.filename FROM files_old f INNER JOIN node n ON f.nid = n.nid WHERE n.type='image' AND f.filename IN ('_original', 'thumbnail', 'preview')
  4. Remove the temporary table files_old:
    DROP TABLE files_old;