You are here

function votingapi_update_6100 in Voting API 6.2

File

./votingapi.install, line 252
Installation file for VotingAPI module.

Code

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

  // Convert vote_id and vote_cache_id columns to auto increment.
  db_drop_primary_key($ret, 'votingapi_cache');
  db_change_field($ret, 'votingapi_cache', 'vote_cache_id', 'vote_cache_id', array(
    'type' => 'serial',
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'vote_cache_id',
    ),
  ));
  db_drop_primary_key($ret, 'votingapi_vote');
  db_change_field($ret, 'votingapi_vote', 'vote_id', 'vote_id', array(
    'type' => 'serial',
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'vote_id',
    ),
  ));

  // Rename the 'hostname' field to 'vote_source' for more flexibility.
  db_change_field($ret, 'votingapi_vote', 'hostname', 'vote_source', array(
    'type' => 'varchar',
    'length' => 255,
  ));
  $indexes = array(
    'content_uid' => array(
      'content_type',
      'content_id',
      'uid',
    ),
    'content_source' => array(
      'content_type',
      'content_id',
      'vote_source',
    ),
    'content_vtype' => array(
      'content_type',
      'content_id',
      'value_type',
    ),
    'content_value_tag' => array(
      'content_type',
      'content_id',
      'value_type',
      'tag',
    ),
  );
  foreach ($indexes as $name => $fields) {
    db_add_index($ret, 'votingapi_vote', $name, $fields);
  }
  $indexes = array(
    'content_function' => array(
      'content_type',
      'content_id',
      'function',
    ),
    'content_tag_func' => array(
      'content_type',
      'content_id',
      'tag',
      'function',
    ),
    'content_vtype_tag' => array(
      'content_type',
      'content_id',
      'value_type',
      'tag',
    ),
    'content_vtype_tag_func' => array(
      'content_type',
      'content_id',
      'value_type',
      'tag',
      'function',
    ),
  );
  foreach ($indexes as $name => $fields) {
    db_add_index($ret, 'votingapi_cache', $name, $fields);
  }

  // Yes, we loves us the SchemaAPI.
  return $ret;
}