]> git.mxchange.org Git - friendica.git/blobdiff - include/dbstructure.php
Global is an integer, do not set it to an empty string
[friendica.git] / include / dbstructure.php
index 9a84cfbc8d441dc6ce3d75f79f232aa27ef301d1..346920ab0702c0f4db80cf6891cccaffe55ec414 100644 (file)
@@ -208,9 +208,10 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                if ($current_index_definition != $new_index_definition) {
                                        if ($fieldnames[0] == "UNIQUE") {
                                                $is_unique = true;
-                                               if ($ignore == "") {
-                                                       $temp_name = "temp-".$name;
-                                               }
+                                               // Deactivated. See below for the reason
+                                               //if ($ignore == "") {
+                                               //      $temp_name = "temp-".$name;
+                                               //}
                                        }
                                }
                        }
@@ -292,44 +293,44 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                        if ($verbose) {
                                // Ensure index conversion to unique removes duplicates
                                if ($is_unique) {
-                                       if ($ignore != "") {
+                                       // By now the alternative is commented out.
+                                       // This is a preparation for the time when we found a good SQL routine.
+                                       //if ($ignore != "") {
                                                echo "SET session old_alter_table=1;\n";
-                                       } else {
-                                               echo "DROP TABLE IF EXISTS `".$temp_name."`;\n";
-                                               echo "CREATE TABLE `".$temp_name."` LIKE `".$name."`;\n";
-                                       }
+                                       //} else {
+                                       //      echo "CREATE TABLE `".$temp_name."` LIKE `".$name."`;\n";
+                                       //}
                                }
 
                                echo $sql3."\n";
 
                                if ($is_unique) {
-                                       if ($ignore != "") {
+                                       // By now the alternative is commented out.
+                                       // This is a preparation for the time when we found a good SQL routine.
+                                       //if ($ignore != "") {
                                                echo "SET session old_alter_table=0;\n";
-                                       } else {
-                                               echo "INSERT IGNORE INTO `".$temp_name."` SELECT * FROM `".$name."`;\n";
-                                               echo "DROP TABLE `".$name."`;\n";
-                                               echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
-                                       }
+                                       //} else {
+                                       //      echo "INSERT IGNORE INTO `".$temp_name."` SELECT * FROM `".$name."`;\n";
+                                       //      echo "DROP TABLE `".$name."`;\n";
+                                       //      echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
+                                       //}
                                }
                        }
 
                        if ($action) {
                                // Ensure index conversion to unique removes duplicates
                                if ($is_unique) {
-                                       if ($ignore != "") {
+                                       // By now the alternative is commented out.
+                                       // This is a preparation for the time when we found a good SQL routine.
+                                       //if ($ignore != "") {
                                                $db->q("SET session old_alter_table=1;");
-                                       } else {
-                                               $r = $db->q("DROP TABLE IF EXISTS `".$temp_name."`;");
-                                               if (!dbm::is_result($r)) {
-                                                       $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
-                                                       return $errors;
-                                               }
-                                               $r = $db->q("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
-                                               if (!dbm::is_result($r)) {
-                                                       $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
-                                                       return $errors;
-                                               }
-                                       }
+                                       //} else {
+                                       //      $r = $db->q("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
+                                       //      if (!dbm::is_result($r)) {
+                                       //              $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
+                                       //              return $errors;
+                                       //      }
+                                       //}
                                }
 
                                $r = @$db->q($sql3);
@@ -337,25 +338,28 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                        $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
 
                                if ($is_unique) {
-                                       if ($ignore != "") {
+                                       // By now the alternative is commented out.
+                                       // This is a preparation for the time when we found a good SQL routine.
+                                       //if ($ignore != "") {
                                                $db->q("SET session old_alter_table=0;");
-                                       } else {
-                                               $r = $db->q("INSERT IGNORE INTO `".$temp_name."` SELECT * FROM `".$name."`;");
-                                               if (!dbm::is_result($r)) {
-                                                       $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
-                                                       return $errors;
-                                               }
-                                               $r = $db->q("DROP TABLE `".$name."`;");
-                                               if (!dbm::is_result($r)) {
-                                                       $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
-                                                       return $errors;
-                                               }
-                                               $r = $db->q("RENAME TABLE `".$temp_name."` TO `".$name."`;");
-                                               if (!dbm::is_result($r)) {
-                                                       $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
-                                                       return $errors;
-                                               }
-                                       }
+                                       //} else {
+                                       //      We have to check if "INSERT IGNORE" will work on newer MySQL versions
+                                       //      $r = $db->q("INSERT IGNORE INTO `".$temp_name."` SELECT * FROM `".$name."`;");
+                                       //      if (!dbm::is_result($r)) {
+                                       //              $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
+                                       //              return $errors;
+                                       //      }
+                                       //      $r = $db->q("DROP TABLE `".$name."`;");
+                                       //      if (!dbm::is_result($r)) {
+                                       //              $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
+                                       //              return $errors;
+                                       //      }
+                                       //      $r = $db->q("RENAME TABLE `".$temp_name."` TO `".$name."`;");
+                                       //      if (!dbm::is_result($r)) {
+                                       //              $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
+                                       //              return $errors;
+                                       //      }
+                                       //}
                                }
                        }
                }
@@ -491,7 +495,7 @@ function db_definition($charset) {
        $database["addon"] = array(
                        "fields" => array(
                                        "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
-                                       "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
+                                       "name" => array("type" => "varchar(190)", "not null" => "1", "default" => ""),
                                        "version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
                                        "installed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
                                        "hidden" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
@@ -500,6 +504,7 @@ function db_definition($charset) {
                                        ),
                        "indexes" => array(
                                        "PRIMARY" => array("id"),
+                                       "name" => array("UNIQUE", "name"),
                                        )
                        );
        $database["attach"] = array(
@@ -513,10 +518,10 @@ function db_definition($charset) {
                                        "data" => array("type" => "longblob", "not null" => "1"),
                                        "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
                                        "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
-                                       "allow_cid" => array("type" => "text"),
-                                       "allow_gid" => array("type" => "text"),
-                                       "deny_cid" => array("type" => "text"),
-                                       "deny_gid" => array("type" => "text"),
+                                       "allow_cid" => array("type" => "mediumtext"),
+                                       "allow_gid" => array("type" => "mediumtext"),
+                                       "deny_cid" => array("type" => "mediumtext"),
+                                       "deny_gid" => array("type" => "mediumtext"),
                                        ),
                        "indexes" => array(
                                        "PRIMARY" => array("id"),
@@ -717,10 +722,10 @@ function db_definition($charset) {
                                        "nofinish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
                                        "adjust" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
                                        "ignore" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
-                                       "allow_cid" => array("type" => "text"),
-                                       "allow_gid" => array("type" => "text"),
-                                       "deny_cid" => array("type" => "text"),
-                                       "deny_gid" => array("type" => "text"),
+                                       "allow_cid" => array("type" => "mediumtext"),
+                                       "allow_gid" => array("type" => "mediumtext"),
+                                       "deny_cid" => array("type" => "mediumtext"),
+                                       "deny_gid" => array("type" => "mediumtext"),
                                        ),
                        "indexes" => array(
                                        "PRIMARY" => array("id"),
@@ -835,10 +840,10 @@ function db_definition($charset) {
                                        ),
                        "indexes" => array(
                                        "PRIMARY" => array("id"),
-                                       "nurl" => array("nurl(32)"),
-                                       "name" => array("name(32)"),
+                                       "nurl" => array("nurl(64)"),
+                                       "name" => array("name(64)"),
                                        "nick" => array("nick(32)"),
-                                       "addr" => array("addr(32)"),
+                                       "addr" => array("addr(64)"),
                                        "hide_network_updated" => array("hide", "network", "updated"),
                                        "updated" => array("updated"),
                                        )
@@ -918,7 +923,7 @@ function db_definition($charset) {
                                        ),
                        "indexes" => array(
                                        "PRIMARY" => array("id"),
-                                       "hook_file_function" => array("hook(30)","file(60)","function(30)"),
+                                       "hook_file_function" => array("UNIQUE", "hook(50)","file(80)","function(60)"),
                                        )
                        );
        $database["intro"] = array(
@@ -1555,10 +1560,10 @@ function db_definition($charset) {
                                        "expire_notification_sent" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
                                        "service_class" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
                                        "def_gid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
-                                       "allow_cid" => array("type" => "text"),
-                                       "allow_gid" => array("type" => "text"),
-                                       "deny_cid" => array("type" => "text"),
-                                       "deny_gid" => array("type" => "text"),
+                                       "allow_cid" => array("type" => "mediumtext"),
+                                       "allow_gid" => array("type" => "mediumtext"),
+                                       "deny_cid" => array("type" => "mediumtext"),
+                                       "deny_gid" => array("type" => "mediumtext"),
                                        "openidserver" => array("type" => "text"),
                                        ),
                        "indexes" => array(