You are here

function imagecache_update_6000 in ImageCache 6.2

Upgrade from Drupal 5 => Drupal 6.

Use serial data type for primary keys. Add module field and presetid index.

File

./imagecache.install, line 258

Code

function imagecache_update_6000() {
  $ret = array();

  // Our additions to the schema.
  $schema['imagecache_preset'] = array(
    'fields' => array(
      'presetid' => array(
        'description' => t('The primary identifier for an imagecache_preset.'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'presetid',
    ),
  );
  $schema['imagecache_action'] = array(
    'fields' => array(
      'actionid' => array(
        'description' => t('The primary identifier for an imagecache_action.'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'module' => array(
        'description' => t('The module that defined the action.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'initial' => 'imagecache',
      ),
    ),
    'primary key' => array(
      'actionid',
    ),
  );

  // Update primary keys to serial type for Drupal 6
  foreach ($schema as $table => $info) {
    $field = $info['primary key'][0];
    if (db_table_exists('sequences')) {
      $ret[] = update_sql("DELETE FROM {sequences} WHERE name = '{{$table}}_{$field}'");
    }
    db_change_field($ret, $table, $field, $field, $info['fields'][$field]);
  }

  // Going to assume that if the table doesn't have a module column that
  // it needs the index as well.
  if (!db_column_exists('imagecache_action', 'module')) {

    // Add 'module' column to action table.
    db_add_field($ret, 'imagecache_action', 'module', $schema['imagecache_action']['fields']['module']);

    // Add 'presetid' index to action table
    db_add_index($ret, 'imagecache_action', 'presetid', array(
      'presetid',
    ));
  }
  return $ret;
}