$admin_mail_list
);
+ // No valid result?
+ if (!dbm::is_result($adminlist)) {
+ logger(sprintf('Cannot notify administrators about update_id=%d, error_message=%s', $update_id, $error_message), LOGGER_WARNING);
+
+ // Don't continue
+ return;
+ }
+
// every admin could had different language
foreach ($adminlist as $admin) {
$fielddata = array();
$indexdata = array();
- if (is_array($indexes))
+ if (dbm::is_result($indexes))
foreach ($indexes AS $index) {
if ($index["Index_type"] == "FULLTEXT")
continue;
+ if ($index['Key_name'] != 'PRIMARY' && $index['Non_unique'] == '0' && !isset($indexdata[$index["Key_name"]])) {
+ $indexdata[$index["Key_name"]] = array('UNIQUE');
+ }
+
$column = $index["Column_name"];
// On utf8mb4 a varchar index can only have a length of 191
// To avoid the need to add this to every index definition we just ignore it here.
$indexdata[$index["Key_name"]][] = $column;
}
- if (is_array($structures)) {
+ if (dbm::is_result($structures)) {
foreach($structures AS $field) {
$fielddata[$field["Field"]]["type"] = $field["Type"];
if ($field["Null"] == "NO")
foreach ($tables AS $table) {
$table = current($table);
+ logger(sprintf('updating structure for table %s ...', $table), LOGGER_DEBUG);
$database[$table] = table_structure($table);
}
if (is_null($definition))
$definition = db_definition($charset);
+ // Ensure index conversion to unique removes duplicates
+ $sql_config = "SET session old_alter_table=1;";
+ if ($verbose)
+ echo $sql_config."\n";
+ if ($action)
+ @$db->q($sql_config);
+
+ // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
+ if ((version_compare($db->server_info(), '5.7.4') >= 0) AND
+ !(strpos($db->server_info(), 'MariaDB') !== false)) {
+ $ignore = '';
+ }else {
+ $ignore = ' IGNORE';
+ }
// Compare it
foreach ($definition AS $name => $structure) {
$sql3="";
if (!isset($database[$name])) {
$r = db_create_table($name, $structure["fields"], $charset, $verbose, $action, $structure['indexes']);
- if(false === $r) {
+ if (!dbm::is_result($r)) {
$errors .= t('Errors encountered creating database tables.').$name.EOL;
}
$is_new_table = True;
if ($current_index_definition != $new_index_definition && substr($indexname, 0, 6) != 'local_') {
$sql2=db_drop_index($indexname);
if ($sql3 == "")
- $sql3 = "ALTER TABLE `".$name."` ".$sql2;
+ $sql3 = "ALTER".$ignore." TABLE `".$name."` ".$sql2;
else
$sql3 .= ", ".$sql2;
}
$sql2=db_create_index($indexname, $fieldnames);
if ($sql2 != "") {
if ($sql3 == "")
- $sql3 = "ALTER TABLE `".$name."` ".$sql2;
+ $sql3 = "ALTER" . $ignore . " TABLE `".$name."` ".$sql2;
else
$sql3 .= ", ".$sql2;
}
if ($action) {
$r = @$db->q($sql3);
- if(false === $r)
+ if (dbm::is_result($r))
$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
}
}
killme();
}
+ if ($fieldnames[0] == "UNIQUE") {
+ array_shift($fieldnames);
+ $method .= ' UNIQUE';
+ }
+
$names = "";
foreach ($fieldnames AS $fieldname) {
if ($names != "")
"indexes" => array(
"PRIMARY" => array("k".db_index_suffix($charset)),
"updated" => array("updated"),
+ "expire_mode_updated" => array("expire_mode", "updated"),
)
);
$database["challenge"] = array(
),
"indexes" => array(
"PRIMARY" => array("id"),
- "cat_k" => array("cat(30)","k(30)"),
+ "cat_k" => array("UNIQUE", "cat(30)","k(30)"),
)
);
$database["contact"] = array(
"indexes" => array(
"PRIMARY" => array("id"),
"uid" => array("uid"),
+ "addr_uid" => array("addr", "uid"),
"nurl" => array("nurl"),
)
);
),
"indexes" => array(
"PRIMARY" => array("id"),
+ "cmd_item_contact" => array("UNIQUE", "cmd", "item", "contact"),
)
);
$database["event"] = array(
"ownerid_created" => array("owner-id","created"),
"wall_body" => array("wall","body(6)"),
"uid_visible_moderated_created" => array("uid","visible","moderated","created"),
- "uid_uri" => array("uid","uri"),
+ "uid_uri" => array("uid", "uri"),
"uid_wall_created" => array("uid","wall","created"),
"resource-id" => array("resource-id"),
"uid_type" => array("uid","type"),
"seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
+ "name_cache" => array("type" => "tinytext"),
+ "msg_cache" => array("type" => "mediumtext")
),
"indexes" => array(
"PRIMARY" => array("id"),
),
"indexes" => array(
"PRIMARY" => array("id"),
- "uid_cat_k" => array("uid","cat(30)","k(30)"),
+ "uid_cat_k" => array("UNIQUE", "uid","cat(30)","k(30)"),
)
);
$database["photo"] = array(
),
"indexes" => array(
"PRIMARY" => array("id"),
- "uid" => array("uid"),
+ "uid_contactid" => array("uid", "contact-id"),
+ "uid_profile" => array("uid", "profile"),
+ "uid_album_created" => array("uid", "album", "created"),
"resource-id" => array("resource-id"),
"guid" => array("guid"),
)
"uid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
"password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"language" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
+ "note" => array("type" => "text"),
),
"indexes" => array(
"PRIMARY" => array("id"),
"type_term" => array("type","term"),
"uid_otype_type_term_global_created" => array("uid","otype","type","term","global","created"),
"otype_type_term_tid" => array("otype","type","term","tid"),
+ "uid_otype_type_url" => array("uid","otype","type","url"),
"guid" => array("guid"),
)
);
if ($argc==2) {
switch ($argv[1]) {
+ case "dryrun":
+ update_structure(true, false);
+ return;
case "update":
update_structure(true, true);
// print help
echo $argv[0]." <command>\n";
echo "\n";
- echo "commands:\n";
+ echo "Commands:\n";
+ echo "dryrun show database update schema queries without running them\n";
echo "update update database schema\n";
echo "dumpsql dump database schema\n";
return;