You are here

function uuid_update_1 in Universally Unique IDentifier 5

Remove duplicated user UUIDs and change uuid field to index instead of a primary key.

File

./uuid.install, line 20

Code

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

  // Move the non duplicates into a temporary table.
  $ret[] = update_sql('CREATE TABLE {uuid_users_temp} AS SELECT * FROM {uuid_users} GROUP BY uid');

  // Delete the old table.
  $ret[] = update_sql('DROP TABLE {uuid_users}');

  // Rename the new_table to the name of the old_table.
  $ret[] = update_sql('RENAME TABLE {uuid_users_temp} TO {uuid_users}');

  // Add key and index to new table.
  $ret[] = update_sql('ALTER TABLE {uuid_users} ADD PRIMARY KEY(uid), ADD INDEX {uuid_users}_uuid_idx(uuid)');

  // Recreate primary key and add index to uuid_node table.
  $ret[] = update_sql('ALTER TABLE {uuid_node} DROP PRIMARY KEY, ADD PRIMARY KEY(nid), ADD INDEX {uuid_node}_uuid_idx(uuid)');
  return $ret;
}