]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBStructure.php
We now have a pre update script (#5425)
[friendica.git] / src / Database / DBStructure.php
index c285528e00e1ef43ecc18ba9848c4f632e764b1f..55188d2b39c19a42e3666721d2e4d0f6caf04221 100644 (file)
@@ -4,10 +4,10 @@
  */
 namespace Friendica\Database;
 
+use Exception;
+use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
-use Friendica\Database\DBM;
-use dba;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
@@ -26,7 +26,7 @@ class DBStructure
         */
        public static function convertToInnoDB() {
                $r = q("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `engine` = 'MyISAM' AND `table_schema` = '%s'",
-                       dbesc(dba::database_name()));
+                       dbesc(DBA::database_name()));
 
                if (!DBM::is_result($r)) {
                        echo L10n::t('There are no tables on MyISAM.')."\n";
@@ -37,7 +37,7 @@ class DBStructure
                        $sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", dbesc($table['TABLE_NAME']));
                        echo $sql."\n";
 
-                       $result = dba::e($sql);
+                       $result = DBA::e($sql);
                        if (!DBM::is_result($result)) {
                                self::printUpdateError($sql);
                        }
@@ -54,7 +54,7 @@ class DBStructure
                $a = get_app();
 
                //send the administrators an e-mail
-               $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
+               $admin_mail_list = "'".implode("','", array_map('dbesc', explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))))."'";
                $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
                        $admin_mail_list
                );
@@ -174,7 +174,7 @@ class DBStructure
                        echo "--\n";
                        echo "-- TABLE $name\n";
                        echo "--\n";
-                       self::createTable($name, $structure['fields'], true, false, $structure["indexes"]);
+                       self::createTable($name, $structure, true, false);
 
                        echo "\n";
                }
@@ -189,7 +189,7 @@ class DBStructure
         */
        private static function printUpdateError($message) {
                echo L10n::t("\nError %d occurred during database update:\n%s\n",
-                       dba::errorNo(), dba::errorMessage());
+                       DBA::errorNo(), DBA::errorMessage());
 
                return L10n::t('Errors encountered performing database changes: ').$message.EOL;
        }
@@ -236,8 +236,8 @@ class DBStructure
                }
 
                // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
-               if ((version_compare(dba::server_info(), '5.7.4') >= 0) &&
-                       !(strpos(dba::server_info(), 'MariaDB') !== false)) {
+               if ((version_compare(DBA::server_info(), '5.7.4') >= 0) &&
+                       !(strpos(DBA::server_info(), 'MariaDB') !== false)) {
                        $ignore = '';
                } else {
                        $ignore = ' IGNORE';
@@ -251,7 +251,7 @@ class DBStructure
                        $is_unique = false;
                        $temp_name = $name;
                        if (!isset($database[$name])) {
-                               $r = self::createTable($name, $structure["fields"], $verbose, $action, $structure['indexes']);
+                               $r = self::createTable($name, $structure, $verbose, $action);
                                if (!DBM::is_result($r)) {
                                        $errors .= self::printUpdateError($name);
                                }
@@ -322,8 +322,8 @@ class DBStructure
                                                        $parameters['comment'] = "";
                                                }
 
-                                               $current_field_definition = implode(",", $field_definition);
-                                               $new_field_definition = implode(",", $parameters);
+                                               $current_field_definition = DBA::clean_query(implode(",", $field_definition));
+                                               $new_field_definition = DBA::clean_query(implode(",", $parameters));
                                                if ($current_field_definition != $new_field_definition) {
                                                        $sql2 = self::modifyTableField($fieldname, $parameters);
                                                        if ($sql3 == "") {
@@ -378,6 +378,18 @@ class DBStructure
                                        }
                                }
 
+                               if (isset($database[$name]["table_status"]["Engine"]) && isset($structure['engine'])) {
+                                       if ($database[$name]["table_status"]["Engine"] != $structure['engine']) {
+                                               $sql2 = "ENGINE = '".dbesc($structure['engine'])."'";
+
+                                               if ($sql3 == "") {
+                                                       $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
+                                               } else {
+                                                       $sql3 .= ", ".$sql2;
+                                               }
+                                       }
+                               }
+
                                if (isset($database[$name]["table_status"]["Collation"])) {
                                        if ($database[$name]["table_status"]["Collation"] != 'utf8mb4_general_ci') {
                                                $sql2 = "DEFAULT COLLATE utf8mb4_general_ci";
@@ -398,10 +410,10 @@ class DBStructure
                                // Compare the field structure field by field
                                foreach ($structure["fields"] AS $fieldname => $parameters) {
                                        // Compare the field definition
-                                       $field_definition = $database[$name]["fields"][$fieldname];
+                                       $field_definition = defaults($database[$name]["fields"], $fieldname, ['Collation' => '']);
 
                                        // Define the default collation if not given
-                                       if (!isset($parameters['Collation']) && !is_null($field_definition['Collation'])) {
+                                       if (!isset($parameters['Collation']) && !empty($field_definition['Collation'])) {
                                                $parameters['Collation'] = 'utf8mb4_general_ci';
                                        } else {
                                                $parameters['Collation'] = null;
@@ -448,7 +460,7 @@ class DBStructure
                                                if ($ignore != "") {
                                                        echo "SET session old_alter_table=0;\n";
                                                } else {
-                                                       echo "INSERT INTO `".$temp_name."` SELECT ".dba::any_value_fallback($field_list)." FROM `".$name."`".$group_by.";\n";
+                                                       echo "INSERT INTO `".$temp_name."` SELECT ".DBA::any_value_fallback($field_list)." FROM `".$name."`".$group_by.";\n";
                                                        echo "DROP TABLE `".$name."`;\n";
                                                        echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
                                                }
@@ -463,15 +475,15 @@ class DBStructure
                                        // Ensure index conversion to unique removes duplicates
                                        if ($is_unique && ($temp_name != $name)) {
                                                if ($ignore != "") {
-                                                       dba::e("SET session old_alter_table=1;");
+                                                       DBA::e("SET session old_alter_table=1;");
                                                } else {
-                                                       $r = dba::e("DROP TABLE IF EXISTS `".$temp_name."`;");
+                                                       $r = DBA::e("DROP TABLE IF EXISTS `".$temp_name."`;");
                                                        if (!DBM::is_result($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
                                                        }
 
-                                                       $r = dba::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
+                                                       $r = DBA::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
                                                        if (!DBM::is_result($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
@@ -479,25 +491,25 @@ class DBStructure
                                                }
                                        }
 
-                                       $r = dba::e($sql3);
+                                       $r = DBA::e($sql3);
                                        if (!DBM::is_result($r)) {
                                                $errors .= self::printUpdateError($sql3);
                                        }
                                        if ($is_unique && ($temp_name != $name)) {
                                                if ($ignore != "") {
-                                                       dba::e("SET session old_alter_table=0;");
+                                                       DBA::e("SET session old_alter_table=0;");
                                                } else {
-                                                       $r = dba::e("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";");
+                                                       $r = DBA::e("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";");
                                                        if (!DBM::is_result($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
                                                        }
-                                                       $r = dba::e("DROP TABLE `".$name."`;");
+                                                       $r = DBA::e("DROP TABLE `".$name."`;");
                                                        if (!DBM::is_result($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
                                                        }
-                                                       $r = dba::e("RENAME TABLE `".$temp_name."` TO `".$name."`;");
+                                                       $r = DBA::e("RENAME TABLE `".$temp_name."` TO `".$name."`;");
                                                        if (!DBM::is_result($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
@@ -525,11 +537,11 @@ class DBStructure
        private static function FieldCommand($parameters, $create = true) {
                $fieldstruct = $parameters["type"];
 
-               if (!is_null($parameters["Collation"])) {
+               if (isset($parameters["Collation"])) {
                        $fieldstruct .= " COLLATE ".$parameters["Collation"];
                }
 
-               if ($parameters["not null"]) {
+               if (isset($parameters["not null"])) {
                        $fieldstruct .= " NOT NULL";
                }
 
@@ -540,11 +552,11 @@ class DBStructure
                                $fieldstruct .= " DEFAULT '".$parameters["default"]."'";
                        }
                }
-               if ($parameters["extra"] != "") {
+               if (isset($parameters["extra"])) {
                        $fieldstruct .= " ".$parameters["extra"];
                }
 
-               if (!is_null($parameters["comment"])) {
+               if (isset($parameters["comment"])) {
                        $fieldstruct .= " COMMENT '".dbesc($parameters["comment"])."'";
                }
 
@@ -554,20 +566,22 @@ class DBStructure
                return($fieldstruct);
        }
 
-       private static function createTable($name, $fields, $verbose, $action, $indexes=null) {
+       private static function createTable($name, $structure, $verbose, $action) {
                $r = true;
 
+               $engine = "";
+               $comment = "";
                $sql_rows = [];
                $primary_keys = [];
-               foreach ($fields AS $fieldname => $field) {
+               foreach ($structure["fields"] AS $fieldname => $field) {
                        $sql_rows[] = "`".dbesc($fieldname)."` ".self::FieldCommand($field);
                        if (x($field,'primary') && $field['primary']!='') {
                                $primary_keys[] = $fieldname;
                        }
                }
 
-               if (!is_null($indexes)) {
-                       foreach ($indexes AS $indexname => $fieldnames) {
+               if (!empty($structure["indexes"])) {
+                       foreach ($structure["indexes"] AS $indexname => $fieldnames) {
                                $sql_index = self::createIndex($indexname, $fieldnames, "");
                                if (!is_null($sql_index)) {
                                        $sql_rows[] = $sql_index;
@@ -575,15 +589,24 @@ class DBStructure
                        }
                }
 
+               if (isset($structure["engine"])) {
+                       $engine = " ENGINE=" . $structure["engine"];
+               }
+
+               if (isset($structure["comment"])) {
+                       $comment = " COMMENT='" . dbesc($structure["comment"]) . "'";
+               }
+
                $sql = implode(",\n\t", $sql_rows);
 
-               $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n\t", dbesc($name)).$sql."\n) DEFAULT COLLATE utf8mb4_general_ci";
+               $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n\t", dbesc($name)).$sql.
+                               "\n)" . $engine . " DEFAULT COLLATE utf8mb4_general_ci" . $comment;
                if ($verbose) {
                        echo $sql.";\n";
                }
 
                if ($action) {
-                       $r = dba::e($sql);
+                       $r = DBA::e($sql);
                }
 
                return $r;
@@ -607,7 +630,7 @@ class DBStructure
        private static function createIndex($indexname, $fieldnames, $method = "ADD") {
                $method = strtoupper(trim($method));
                if ($method!="" && $method!="ADD") {
-                       throw new \Exception("Invalid parameter 'method' in self::createIndex(): '$method'");
+                       throw new Exception("Invalid parameter 'method' in self::createIndex(): '$method'");
                }
 
                if ($fieldnames[0] == "UNIQUE") {
@@ -1051,7 +1074,7 @@ class DBStructure
                                "fields" => [
                                                "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
                                                "gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["group" => "id"], "comment" => "groups.id of the associated group"],
-                                               "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id  of the member assigned to the associated group"],
+                                               "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id of the member assigned to the associated group"],
                                                ],
                                "indexes" => [
                                                "PRIMARY" => ["id"],
@@ -1131,72 +1154,81 @@ class DBStructure
                                                ]
                                ];
                $database["item"] = [
-                               "comment" => "All posts",
+                               "comment" => "Structure for all posts",
                                "fields" => [
                                                "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
                                                "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this item"],
                                                "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
-                                               "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
-                                               "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
-                                               "type" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""],
-                                               "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "This item was posted to the wall of uid"],
-                                               "gravity" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                                               "uri-hash" => ["type" => "varchar(80)", "not null" => "1", "default" => "", "comment" => "RIPEMD-128 hash from uri"],
                                                "parent" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => "item.id of the parent to this item if it is a reply of some form; otherwise this must be set to the id of this item"],
                                                "parent-uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "uri of the parent to this item"],
-                                               "extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
                                                "thr-parent" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "If the parent of this item is not the top-level item in the conversation, the uri of the immediate parent; otherwise set to parent-uri"],
                                                "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Creation timestamp."],
-                                               "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of  last edit (default is created)"],
+                                               "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last edit (default is created)"],
                                                "commented" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last comment/reply to this item"],
                                                "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime"],
                                                "changed" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date that something in the conversation changed, indicating clients should fetch the conversation again"],
+                                               "gravity" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                                               "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"],
                                                "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Link to the contact table with uid=0 of the owner of this item"],
-                                               "owner-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name of the owner of this item"],
-                                               "owner-link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the profile page of the owner of this item"],
-                                               "owner-avatar" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the avatar picture of the owner of this item"],
                                                "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Link to the contact table with uid=0 of the author of this item"],
-                                               "author-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name of the author of this item"],
-                                               "author-link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the profile page of the author of this item"],
-                                               "author-avatar" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the avatar picture of the author of this item"],
-                                               "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "item title"],
-                                               "content-warning" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
-                                               "body" => ["type" => "mediumtext", "comment" => "item body content"],
-                                               "app" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "application which generated this item"],
-                                               "verb" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams verb"],
-                                               "object-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams object type"],
-                                               "object" => ["type" => "text", "comment" => "JSON encoded object structure unless it is an implied object (normal post)"],
-                                               "target-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams target type if applicable (URI)"],
-                                               "target" => ["type" => "text", "comment" => "JSON encoded target structure if used"],
-                                               "postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
-                                               "plink" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "permalink or URL toa displayable copy  of the message at its source"],
-                                               "resource-id" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type"],
-                                               "event-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
-                                               "tag" => ["type" => "mediumtext", "comment" => ""],
-                                               "attach" => ["type" => "mediumtext", "comment" => "JSON structure representing attachments to this item"],
-                                               "inform" => ["type" => "mediumtext", "comment" => ""],
-                                               "file" => ["type" => "mediumtext", "comment" => ""],
-                                               "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "text location where this item originated"],
-                                               "coord" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "longitude/latitude pair representing location where this item originated"],
-                                               "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
-                                               "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
-                                               "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
-                                               "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
+                                               "icid" => ["type" => "int unsigned", "relation" => ["item-content" => "id"], "comment" => "Id of the item-content table entry that contains the whole item content"],
+                                               "iaid" => ["type" => "int unsigned", "relation" => ["item-activity" => "id"], "comment" => "Id of the item-activity table entry that contains the activity data"],
+                                               "extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
+                                               "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "private" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "distribution is restricted"],
-                                               "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
-                                               "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
-                                               "spam" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
-                                               "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been favourited"],
-                                               "bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been bookmarked"],
-                                               "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
+                                               "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been deleted"],
+                                               // User specific fields. Eventually they will move to user-item
+                                               "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
+                                               "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
+                                               "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "This item was posted to the wall of uid"],
                                                "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item originated at this site"],
-                                               "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                                               "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                                               "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been favourited"],
+                                               "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
                                                "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"],
-                                               "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"],
-                                               "rendered-hash" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
-                                               "rendered-html" => ["type" => "mediumtext", "comment" => "item.body converted to html"],
-                                               "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                                               "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                                               "psid" => ["type" => "int unsigned", "relation" => ["permissionset" => "id"], "comment" => "ID of the permission set of this post"],
+                                               // These fields will be replaced by the "psid" from above
+                                               "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
+                                               "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
+                                               "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
+                                               "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
+                                               // It is to be decided whether these fields belong to the user or the structure
+                                               "resource-id" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type"],
+                                               "event-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
+                                               // Could possibly be replaced by the "attach" table?
+                                               "attach" => ["type" => "mediumtext", "comment" => "JSON structure representing attachments to this item"],
+                                               // Deprecated fields. Will be removed in upcoming versions
+                                               "postopts" => ["type" => "text", "comment" => "Deprecated"],
+                                               "inform" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                                               "type" => ["type" => "varchar(20)", "comment" => "Deprecated"],
+                                               "bookmark" => ["type" => "boolean", "comment" => "Deprecated"],
+                                               "file" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                                               "location" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "coord" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "tag" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                                               "plink" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "title" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "content-warning" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "body" => ["type" => "mediumtext", "comment" => "Deprecated"],
+                                               "app" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "verb" => ["type" => "varchar(100)", "comment" => "Deprecated"],
+                                               "object-type" => ["type" => "varchar(100)", "comment" => "Deprecated"],
+                                               "object" => ["type" => "text", "comment" => "Deprecated"],
+                                               "target-type" => ["type" => "varchar(100)", "comment" => "Deprecated"],
+                                               "target" => ["type" => "text", "comment" => "Deprecated"],
+                                               "author-name" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "author-link" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "author-avatar" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "owner-name" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "owner-link" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "owner-avatar" => ["type" => "varchar(255)", "comment" => "Deprecated"],
+                                               "rendered-hash" => ["type" => "varchar(32)", "comment" => "Deprecated"],
+                                               "rendered-html" => ["type" => "mediumtext", "comment" => "Deprecated"],
                                                ],
                                "indexes" => [
                                                "PRIMARY" => ["id"],
@@ -1219,14 +1251,65 @@ class DBStructure
                                                "ownerid" => ["owner-id"],
                                                "uid_uri" => ["uid", "uri(190)"],
                                                "resource-id" => ["resource-id"],
-                                               "contactid_allowcid_allowpid_denycid_denygid" => ["contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"], //
-                                               "uid_type_changed" => ["uid","type","changed"],
-                                               "contactid_verb" => ["contact-id","verb"],
                                                "deleted_changed" => ["deleted","changed"],
                                                "uid_wall_changed" => ["uid","wall","changed"],
                                                "uid_eventid" => ["uid","event-id"],
-                                               "uid_authorlink" => ["uid","author-link(190)"],
-                                               "uid_ownerlink" => ["uid","owner-link(190)"],
+                                               "icid" => ["icid"],
+                                               "iaid" => ["iaid"],
+                                               "psid" => ["psid"],
+                                               ]
+                               ];
+               $database["item-activity"] = [
+                               "comment" => "Activities for items",
+                               "fields" => [
+                                               "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
+                                               "uri" => ["type" => "varchar(255)", "comment" => ""],
+                                               "uri-hash" => ["type" => "varchar(80)", "not null" => "1", "default" => "", "comment" => "RIPEMD-128 hash from uri"],
+                                               "activity" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
+                                               ],
+                               "indexes" => [
+                                               "PRIMARY" => ["id"],
+                                               "uri-hash" => ["UNIQUE", "uri-hash"],
+                                               "uri" => ["uri(191)"],
+                                               ]
+                               ];
+               $database["item-content"] = [
+                               "comment" => "Content for all posts",
+                               "fields" => [
+                                               "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
+                                               "uri" => ["type" => "varchar(255)", "comment" => ""],
+                                               "uri-plink-hash" => ["type" => "varchar(80)", "not null" => "1", "default" => "", "comment" => "RIPEMD-128 hash from uri"],
+                                               "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "item title"],
+                                               "content-warning" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "body" => ["type" => "mediumtext", "comment" => "item body content"],
+                                               "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "text location where this item originated"],
+                                               "coord" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "longitude/latitude pair representing location where this item originated"],
+                                               "language" => ["type" => "text", "comment" => "Language information about this post"],
+                                               "app" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "application which generated this item"],
+                                               "rendered-hash" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "rendered-html" => ["type" => "mediumtext", "comment" => "item.body converted to html"],
+                                               "object-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams object type"],
+                                               "object" => ["type" => "text", "comment" => "JSON encoded object structure unless it is an implied object (normal post)"],
+                                               "target-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams target type if applicable (URI)"],
+                                               "target" => ["type" => "text", "comment" => "JSON encoded target structure if used"],
+                                               "plink" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "permalink or URL to a displayable copy of the message at its source"],
+                                               "verb" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams verb"],
+                                               ],
+                               "indexes" => [
+                                               "PRIMARY" => ["id"],
+                                               "uri-plink-hash" => ["UNIQUE", "uri-plink-hash"],
+                                               "uri" => ["uri(191)"],
+                                               ]
+                               ];
+               $database["item-delivery-data"] = [
+                               "comment" => "Delivery data for items",
+                               "fields" => [
+                                               "iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
+                                               "postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
+                                               "inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"],
+                                               ],
+                               "indexes" => [
+                                               "PRIMARY" => ["iid"],
                                                ]
                                ];
                $database["locks"] = [
@@ -1236,9 +1319,11 @@ class DBStructure
                                                "name" => ["type" => "varchar(128)", "not null" => "1", "default" => "", "comment" => ""],
                                                "locked" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "pid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Process ID"],
-                                               ],
+                                               "expires" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of cache expiration"],
+                               ],
                                "indexes" => [
                                                "PRIMARY" => ["id"],
+                                               "name_expires" => ["name", "expires"]
                                                ]
                                ];
                $database["mail"] = [
@@ -1359,6 +1444,20 @@ class DBStructure
                                                "created" => ["created"],
                                                ]
                                ];
+               $database["openwebauth-token"] = [
+                               "comment" => "Store OpenWebAuth token to verify contacts",
+                               "fields" => [
+                                               "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                                               "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
+                                               "type" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Verify type"],
+                                               "token" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A generated token"],
+                                               "meta" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of creation"],
+                                       ],
+                               "indexes" => [
+                                               "PRIMARY" => ["id"],
+                                               ]
+                               ];
                $database["parsed_url"] = [
                                "comment" => "cache for 'parse_url' queries",
                                "fields" => [
@@ -1399,6 +1498,21 @@ class DBStructure
                                                "uid_cat_k" => ["UNIQUE", "uid", "cat", "k"],
                                                ]
                                ];
+               $database["permissionset"] = [
+                               "comment" => "",
+                               "fields" => [
+                                               "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+                                               "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id of this permission set"],
+                                               "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
+                                               "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
+                                               "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
+                                               "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
+                                               ],
+                               "indexes" => [
+                                               "PRIMARY" => ["id"],
+                                               "uid_allow_cid_allow_gid_deny_cid_deny_gid" => ["allow_cid(50)", "allow_gid(30)", "deny_cid(50)", "deny_gid(30)"],
+                                               ]
+                               ];
                $database["photo"] = [
                                "comment" => "photo storage",
                                "fields" => [
@@ -1652,7 +1766,6 @@ class DBStructure
                                                "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
                                                "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
                                                "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
-                                               "aid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
                                                "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
                                                ],
                                "indexes" => [
@@ -1681,16 +1794,16 @@ class DBStructure
                                                "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
-                                               "spam" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "ignored" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
-                                               "bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+                                               "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
                                                "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
                                                "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
                                                "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "bookmark" => ["type" => "boolean", "comment" => ""],
                                                ],
                                "indexes" => [
                                                "PRIMARY" => ["iid"],
@@ -1797,6 +1910,18 @@ class DBStructure
                                                "PRIMARY" => ["uid", "iid"],
                                                ]
                                ];
+               $database["worker-ipc"] = [
+                               "comment" => "Inter process communication between the frontend and the worker",
+                               "fields" => [
+                                               "key" => ["type" => "int", "not null" => "1", "primary" => "1", "comment" => ""],
+                                               "jobs" => ["type" => "boolean", "comment" => "Flag for outstanding jobs"],
+                                               ],
+                               "indexes" => [
+                                               "PRIMARY" => ["key"],
+                                               ],
+                               "engine" => "MEMORY",
+                               ];
+
                $database["workerqueue"] = [
                                "comment" => "Background tasks queue entries",
                                "fields" => [
@@ -1817,7 +1942,7 @@ class DBStructure
                                                ]
                                ];
 
-               \Friendica\Core\Addon::callHooks('dbstructure_definition', $database);
+               Addon::callHooks('dbstructure_definition', $database);
 
                return $database;
        }