You are here

function hosting_server_update_6200 in Hosting 7.3

Same name and namespace in other branches
  1. 6.2 server/hosting_server.install \hosting_server_update_6200()
  2. 7.4 server/hosting_server.install \hosting_server_update_6200()

Implements hook_update_N().

Add primary key for IPs, drop versionning

File

server/hosting_server.install, line 237
Define the database schema and update functions for the hosting_server module.

Code

function hosting_server_update_6200() {
  $ret = array();
  db_drop_index($ret, 'hosting_ip_addresses', 'vid');
  db_drop_field($ret, "hosting_ip_addresses", "vid");
  db_add_field($ret, "hosting_ip_addresses", "id", array(
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'id',
    ),
  ));
  $r = db_query("SELECT nid, ip_address FROM {hosting_ip_addresses}");
  for ($i = 0; $row = db_fetch_object($r); $i++) {
    $ret[] = update_sql("UPDATE {hosting_ip_addresses} SET id={$i} WHERE nid={$row->nid} AND ip_address='{$row->ip_address}'");
  }
  db_add_index($ret, 'hosting_ip_addresses', 'nid', array(
    'nid',
  ));
  return $ret;
}