View source
<?php
function uuid_install() {
$tables = array(
'node' => 'nid',
'users' => 'uid',
'node_revisions' => 'vid',
);
foreach ($tables as $table => $key) {
db_query(uuid_table_schema($table, $key));
db_query('INSERT INTO {uuid_' . $table . '} SELECT ' . $key . ', UUID() FROM {' . $table . '}');
}
}
function uuid_update_1() {
$ret = array();
$ret[] = update_sql('CREATE TABLE {uuid_users_temp} AS SELECT * FROM {uuid_users} GROUP BY uid');
$ret[] = update_sql('DROP TABLE {uuid_users}');
$ret[] = update_sql('RENAME TABLE {uuid_users_temp} TO {uuid_users}');
$ret[] = update_sql('ALTER TABLE {uuid_users} ADD PRIMARY KEY(uid), ADD INDEX {uuid_users}_uuid_idx(uuid)');
$ret[] = update_sql('ALTER TABLE {uuid_node} DROP PRIMARY KEY, ADD PRIMARY KEY(nid), ADD INDEX {uuid_node}_uuid_idx(uuid)');
return $ret;
}
function uuid_update_2() {
db_query(uuid_table_schema('node_revisions', 'vid'));
db_query('INSERT INTO {uuid_node_revisions} SELECT vid, UUID() FROM {node_revisions}');
return array();
}
function uuid_table_schema($table, $key = 'key') {
return "CREATE TABLE {uuid_" . $table . "} (\n " . $key . " int(10) unsigned NOT NULL default '0',\n uuid char(36) NOT NULL default '',\n PRIMARY KEY (" . $key . "),\n KEY {uuid_" . $table . "}_uuid_idx(uuid)\n ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;";
}
function uuid_uninstall() {
foreach (array(
'node',
'users',
'node_revisions',
) as $table) {
db_query('DROP TABLE {uuid_' . $table . '}');
}
}