function system_update_6019 in Drupal 6
Reconcile small differences in the previous, manually created mysql and pgsql schemas so they are the same and can be represented by a single schema structure.
Note that the mysql and pgsql cases make different changes. This is because each schema needs to be tweaked in different ways to conform to the new schema structure. Also, since they operate on tables defined by many optional core modules which may not ever have been installed, they must test each table for existence. If the modules are first installed after this update exists the tables will be created from the schema structure and will start out correct.
Related topics
File
- modules/
system/ system.install, line 1601
Code
function system_update_6019() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
// Remove default ''.
if (db_table_exists('aggregator_feed')) {
db_field_set_no_default($ret, 'aggregator_feed', 'description');
db_field_set_no_default($ret, 'aggregator_feed', 'image');
}
db_field_set_no_default($ret, 'blocks', 'pages');
if (db_table_exists('contact')) {
db_field_set_no_default($ret, 'contact', 'recipients');
db_field_set_no_default($ret, 'contact', 'reply');
}
db_field_set_no_default($ret, 'watchdog', 'location');
db_field_set_no_default($ret, 'node_revisions', 'body');
db_field_set_no_default($ret, 'node_revisions', 'teaser');
db_field_set_no_default($ret, 'node_revisions', 'log');
// Update from pgsql 'float' (which means 'double precision') to
// schema 'float' (which in pgsql means 'real').
if (db_table_exists('search_index')) {
db_change_field($ret, 'search_index', 'score', 'score', array(
'type' => 'float',
));
}
if (db_table_exists('search_total')) {
db_change_field($ret, 'search_total', 'count', 'count', array(
'type' => 'float',
));
}
// Replace unique index dst_language with a unique constraint. The
// result is the same but the unique key fits our current schema
// structure. Also, the postgres documentation implies that
// unique constraints are preferable to unique indexes. See
// http://www.postgresql.org/docs/8.2/interactive/indexes-unique.html.
if (db_table_exists('url_alias')) {
db_drop_index($ret, 'url_alias', 'dst_language');
db_add_unique_key($ret, 'url_alias', 'dst_language', array(
'dst',
'language',
));
}
// Fix term_node pkey: mysql and pgsql code had different orders.
if (db_table_exists('term_node')) {
db_drop_primary_key($ret, 'term_node');
db_add_primary_key($ret, 'term_node', array(
'vid',
'tid',
'nid',
));
}
// Make boxes.bid unsigned.
db_drop_primary_key($ret, 'boxes');
db_change_field($ret, 'boxes', 'bid', 'bid', array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
), array(
'primary key' => array(
'bid',
),
));
// Fix primary key
db_drop_primary_key($ret, 'node');
db_add_primary_key($ret, 'node', array(
'nid',
));
break;
case 'mysql':
case 'mysqli':
// Rename key 'link' to 'url'.
if (db_table_exists('aggregator_feed')) {
db_drop_unique_key($ret, 'aggregator_feed', 'link');
db_add_unique_key($ret, 'aggregator_feed', 'url', array(
'url',
));
}
// Change to size => small.
if (db_table_exists('boxes')) {
db_change_field($ret, 'boxes', 'format', 'format', array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
));
}
// Change to size => small.
// Rename index 'lid' to 'nid'.
if (db_table_exists('comments')) {
db_change_field($ret, 'comments', 'format', 'format', array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
));
db_drop_index($ret, 'comments', 'lid');
db_add_index($ret, 'comments', 'nid', array(
'nid',
));
}
// Change to size => small.
db_change_field($ret, 'cache', 'serialized', 'serialized', array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
));
db_change_field($ret, 'cache_filter', 'serialized', 'serialized', array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
));
db_change_field($ret, 'cache_page', 'serialized', 'serialized', array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
));
db_change_field($ret, 'cache_form', 'serialized', 'serialized', array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
));
// Remove default => 0, set auto increment.
$new_uid = 1 + db_result(db_query('SELECT MAX(uid) FROM {users}'));
$ret[] = update_sql('UPDATE {users} SET uid = ' . $new_uid . ' WHERE uid = 0');
db_drop_primary_key($ret, 'users');
db_change_field($ret, 'users', 'uid', 'uid', array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
), array(
'primary key' => array(
'uid',
),
));
$ret[] = update_sql('UPDATE {users} SET uid = 0 WHERE uid = ' . $new_uid);
// Special field names.
$map = array(
'node_revisions' => 'vid',
);
// Make sure these tables have proper auto_increment fields.
foreach (array(
'boxes',
'files',
'node',
'node_revisions',
) as $table) {
$field = isset($map[$table]) ? $map[$table] : $table[0] . 'id';
db_drop_primary_key($ret, $table);
db_change_field($ret, $table, $field, $field, array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
), array(
'primary key' => array(
$field,
),
));
}
break;
}
return $ret;
}