function system_update_146 in Drupal 5
Same name and namespace in other branches
- 4 database/updates.inc \system_update_146()
File
- modules/
system/ system.install, line 1816
Code
function system_update_146() {
$ret = array();
if ($GLOBALS['db_type'] == 'mysql') {
$ret[] = update_sql("CREATE TABLE {node_revisions}\n SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format\n FROM {node}");
$ret[] = update_sql("ALTER TABLE {node_revisions} CHANGE nid nid int unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {node_revisions} ADD log longtext");
$ret[] = update_sql("ALTER TABLE {node} ADD vid int unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {files} ADD vid int unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {book} ADD vid int unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {forum} ADD vid int unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {book} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {forum} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {files} DROP PRIMARY KEY");
$ret[] = update_sql("UPDATE {node} SET vid = nid");
$ret[] = update_sql("UPDATE {forum} SET vid = nid");
$ret[] = update_sql("UPDATE {book} SET vid = nid");
$ret[] = update_sql("UPDATE {files} SET vid = nid");
$ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY vid (vid)");
$ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY vid (vid)");
$ret[] = update_sql("ALTER TABLE {node_revisions} ADD PRIMARY KEY vid (vid)");
$ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY nid (nid)");
$ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY uid (uid)");
$ret[] = update_sql("CREATE TABLE {old_revisions} SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
$ret[] = update_sql("ALTER TABLE {book} ADD KEY nid (nid)");
$ret[] = update_sql("ALTER TABLE {forum} ADD KEY nid (nid)");
$ret[] = update_sql("ALTER TABLE {files} ADD KEY fid (fid)");
$ret[] = update_sql("ALTER TABLE {files} ADD KEY vid (vid)");
$vid = db_next_id('{node}_nid');
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{node_revisions}_vid', {$vid})");
}
else {
// pgsql
$ret[] = update_sql("CREATE TABLE {node_revisions} (\n nid integer NOT NULL default '0',\n vid integer NOT NULL default '0',\n uid integer NOT NULL default '0',\n title varchar(128) NOT NULL default '',\n body text NOT NULL default '',\n teaser text NOT NULL default '',\n log text NOT NULL default '',\n timestamp integer NOT NULL default '0',\n format int NOT NULL default '0',\n PRIMARY KEY (vid))");
$ret[] = update_sql("INSERT INTO {node_revisions} (nid, vid, uid, title, body, teaser, timestamp, format)\n SELECT nid, nid AS vid, uid, title, body, teaser, changed AS timestamp, format\n FROM {node}");
$ret[] = update_sql('CREATE INDEX {node_revisions}_nid_idx ON {node_revisions}(nid)');
$ret[] = update_sql('CREATE INDEX {node_revisions}_uid_idx ON {node_revisions}(uid)');
$vid = db_next_id('{node}_nid');
$ret[] = update_sql("CREATE SEQUENCE {node_revisions}_vid_seq INCREMENT 1 START {$vid}");
db_add_column($ret, 'node', 'vid', 'int', array(
'not null' => TRUE,
'default' => 0,
));
db_add_column($ret, 'files', 'vid', 'int', array(
'not null' => TRUE,
'default' => 0,
));
db_add_column($ret, 'book', 'vid', 'int', array(
'not null' => TRUE,
'default' => 0,
));
db_add_column($ret, 'forum', 'vid', 'int', array(
'not null' => TRUE,
'default' => 0,
));
$ret[] = update_sql("ALTER TABLE {book} DROP CONSTRAINT {book}_pkey");
$ret[] = update_sql("ALTER TABLE {forum} DROP CONSTRAINT {forum}_pkey");
$ret[] = update_sql("ALTER TABLE {files} DROP CONSTRAINT {files}_pkey");
$ret[] = update_sql("UPDATE {node} SET vid = nid");
$ret[] = update_sql("UPDATE {forum} SET vid = nid");
$ret[] = update_sql("UPDATE {book} SET vid = nid");
$ret[] = update_sql("UPDATE {files} SET vid = nid");
$ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY (vid)");
$ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY (vid)");
$ret[] = update_sql("CREATE TABLE {old_revisions} AS SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
$ret[] = update_sql('CREATE INDEX {node}_vid_idx ON {node}(vid)');
$ret[] = update_sql('CREATE INDEX {forum}_nid_idx ON {forum}(nid)');
$ret[] = update_sql('CREATE INDEX {files}_fid_idx ON {files}(fid)');
$ret[] = update_sql('CREATE INDEX {files}_vid_idx ON {files}(vid)');
}
// Move logs too.
$result = db_query("SELECT nid, log FROM {book} WHERE log != ''");
while ($row = db_fetch_object($result)) {
db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $row->log, $row->nid);
}
$ret[] = update_sql("ALTER TABLE {book} DROP log");
$ret[] = update_sql("ALTER TABLE {node} DROP teaser");
$ret[] = update_sql("ALTER TABLE {node} DROP body");
$ret[] = update_sql("ALTER TABLE {node} DROP format");
$ret[] = update_sql("ALTER TABLE {node} DROP revisions");
return $ret;
}