You are here

function image_attach_update_6100 in Image 6

Add primary key and index on 'iid' to {image_attach} table.

File

contrib/image_attach/image_attach.install, line 94

Code

function image_attach_update_6100() {
  $ret = array();
  db_change_field($ret, 'image_attach', 'nid', 'nid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  db_change_field($ret, 'image_attach', 'iid', 'iid', 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_attach');
  db_add_primary_key($ret, 'image_attach', array(
    'nid',
  ));
  @db_drop_index($ret, 'image_attach', 'iid');
  db_add_index($ret, 'image_attach', 'iid', array(
    'iid',
  ));

  // 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_attach} DROP PRIMARY KEY" or "DROP INDEX iid" here it is harmless.'),
  );
  return $ret;
}