You are here

function image_update_6100 in Image 7

Same name and namespace in other branches
  1. 6 image.install \image_update_6100()

Add primary key and index on 'fid' to {image} table.

File

./image.install, line 304

Code

function image_update_6100() {
  $ret = array();
  db_change_field($ret, 'image', 'nid', 'nid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  db_change_field($ret, 'image', 'fid', 'fid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));

  /**
   * We remove and re-add primary keys and indexes because the column types
   * are changed.
   * Sometimes however these don't exist in the first place (@see
   * <http://drupal.org/node/562810>; the @ takes care of suppressing the
   * error message this causes.
   */
  @db_drop_primary_key($ret, 'image');
  db_add_primary_key($ret, 'image', array(
    'nid',
    'image_size',
  ));
  @db_drop_index($ret, 'image', 'image_fid');
  db_add_index($ret, 'image', 'fid', array(
    'fid',
  ));

  // Notify the user that they may get harmless fail messages here.
  $ret[] = array(
    'success' => TRUE,
    'query' => t('If you see a message of the form "Failed: ALTER TABLE {image} DROP PRIMARY KEY" or "DROP INDEX image_fid" here it is harmless.'),
  );
  return $ret;
}