function maillog_update_8100 in Maillog / Mail Developer 8
Rename the 'idmaillog' field to just 'id'.
File
- ./
maillog.install, line 102 - Provides the installation and update routines for the Maillog module.
Code
function maillog_update_8100() {
$connection = Database::getConnection();
$schema = $connection
->schema();
if (!$schema
->fieldExists('maillog', 'id')) {
// Add the new 'id' field.
$spec = [
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => "The primary key of this table.",
];
$schema
->addField('maillog', 'id', $spec);
// Fill in all of the 'id' fields.
$connection
->query("UPDATE {maillog} SET id=idmaillog");
// Drop the 'idmaillog' field.
$schema
->dropField('maillog', 'idmaillog');
// Change the 'id' field to a serial.
$spec = [
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "The primary key of this table.",
];
$keys = [
'primary key' => [
'id',
],
];
$schema
->changeField('maillog', 'id', 'id', $spec, $keys);
}
}