]> git.mxchange.org Git - friendica.git/blob - src/Database/DBStructure.php
Rename DBA::inArray to DBA::toArray
[friendica.git] / src / Database / DBStructure.php
1 <?php
2 /**
3  * @file src/Database/DBStructure.php
4  */
5 namespace Friendica\Database;
6
7 use Exception;
8 use Friendica\Core\Addon;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11
12 require_once 'boot.php';
13 require_once 'include/dba.php';
14 require_once 'include/enotify.php';
15 require_once 'include/text.php';
16
17 /**
18  * @brief This class contain functions for the database management
19  *
20  * This class contains functions that doesn't need to know if pdo, mysqli or whatever is used.
21  */
22 class DBStructure
23 {
24         /*
25          * Converts all tables from MyISAM to InnoDB
26          */
27         public static function convertToInnoDB() {
28                 $r = q("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `engine` = 'MyISAM' AND `table_schema` = '%s'",
29                         dbesc(DBA::databaseName()));
30
31                 if (!DBM::is_result($r)) {
32                         echo L10n::t('There are no tables on MyISAM.')."\n";
33                         return;
34                 }
35
36                 foreach ($r AS $table) {
37                         $sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", dbesc($table['TABLE_NAME']));
38                         echo $sql."\n";
39
40                         $result = DBA::e($sql);
41                         if (!DBM::is_result($result)) {
42                                 self::printUpdateError($sql);
43                         }
44                 }
45         }
46
47         /*
48          * send the email and do what is needed to do on update fails
49          *
50          * @param update_id             (int) number of failed update
51          * @param error_message (str) error message
52          */
53         public static function updateFail($update_id, $error_message) {
54                 $a = get_app();
55
56                 //send the administrators an e-mail
57                 $admin_mail_list = "'".implode("','", array_map('dbesc', explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))))."'";
58                 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
59                         $admin_mail_list
60                 );
61
62                 // No valid result?
63                 if (!DBM::is_result($adminlist)) {
64                         logger(sprintf('Cannot notify administrators about update_id=%d, error_message=%s', $update_id, $error_message), LOGGER_INFO);
65
66                         // Don't continue
67                         return;
68                 }
69
70                 // every admin could had different language
71                 foreach ($adminlist as $admin) {
72                         $lang = (($admin['language'])?$admin['language']:'en');
73                         L10n::pushLang($lang);
74
75                         $preamble = deindent(L10n::t("
76                                 The friendica developers released update %s recently,
77                                 but when I tried to install it, something went terribly wrong.
78                                 This needs to be fixed soon and I can't do it alone. Please contact a
79                                 friendica developer if you can not help me on your own. My database might be invalid."));
80                         $body = L10n::t("The error message is\n[pre]%s[/pre]");
81                         $preamble = sprintf($preamble, $update_id);
82                         $body = sprintf($body, $error_message);
83
84                         notification([
85                                 'type' => SYSTEM_EMAIL,
86                                 'to_email' => $admin['email'],
87                                 'preamble' => $preamble,
88                                 'body' => $body,
89                                 'language' => $lang]
90                         );
91                 }
92
93                 //try the logger
94                 logger("CRITICAL: Database structure update failed: ".$error_message);
95         }
96
97
98         private static function tableStructure($table) {
99                 $structures = q("DESCRIBE `%s`", $table);
100
101                 $full_columns = q("SHOW FULL COLUMNS FROM `%s`", $table);
102
103                 $indexes = q("SHOW INDEX FROM `%s`", $table);
104
105                 $table_status = q("SHOW TABLE STATUS WHERE `name` = '%s'", $table);
106
107                 if (DBM::is_result($table_status)) {
108                         $table_status = $table_status[0];
109                 } else {
110                         $table_status = [];
111                 }
112
113                 $fielddata = [];
114                 $indexdata = [];
115
116                 if (DBM::is_result($indexes)) {
117                         foreach ($indexes AS $index) {
118                                 if ($index['Key_name'] != 'PRIMARY' && $index['Non_unique'] == '0' && !isset($indexdata[$index["Key_name"]])) {
119                                         $indexdata[$index["Key_name"]] = ['UNIQUE'];
120                                 }
121
122                                 $column = $index["Column_name"];
123
124                                 if ($index["Sub_part"] != "") {
125                                         $column .= "(".$index["Sub_part"].")";
126                                 }
127
128                                 $indexdata[$index["Key_name"]][] = $column;
129                         }
130                 }
131                 if (DBM::is_result($structures)) {
132                         foreach ($structures AS $field) {
133                                 // Replace the default size values so that we don't have to define them
134                                 $search = ['tinyint(1)', 'tinyint(3) unsigned', 'tinyint(4)', 'smallint(5) unsigned', 'smallint(6)', 'mediumint(8) unsigned', 'mediumint(9)', 'bigint(20)', 'int(10) unsigned', 'int(11)'];
135                                 $replace = ['boolean', 'tinyint unsigned', 'tinyint', 'smallint unsigned', 'smallint', 'mediumint unsigned', 'mediumint', 'bigint', 'int unsigned', 'int'];
136                                 $field["Type"] = str_replace($search, $replace, $field["Type"]);
137
138                                 $fielddata[$field["Field"]]["type"] = $field["Type"];
139                                 if ($field["Null"] == "NO") {
140                                         $fielddata[$field["Field"]]["not null"] = true;
141                                 }
142
143                                 if (isset($field["Default"])) {
144                                         $fielddata[$field["Field"]]["default"] = $field["Default"];
145                                 }
146
147                                 if ($field["Extra"] != "") {
148                                         $fielddata[$field["Field"]]["extra"] = $field["Extra"];
149                                 }
150
151                                 if ($field["Key"] == "PRI") {
152                                         $fielddata[$field["Field"]]["primary"] = true;
153                                 }
154                         }
155                 }
156                 if (DBM::is_result($full_columns)) {
157                         foreach ($full_columns AS $column) {
158                                 $fielddata[$column["Field"]]["Collation"] = $column["Collation"];
159                                 $fielddata[$column["Field"]]["comment"] = $column["Comment"];
160                         }
161                 }
162
163                 return ["fields" => $fielddata, "indexes" => $indexdata, "table_status" => $table_status];
164         }
165
166         public static function printStructure() {
167                 $database = self::definition();
168
169                 echo "-- ------------------------------------------\n";
170                 echo "-- ".FRIENDICA_PLATFORM." ".FRIENDICA_VERSION." (".FRIENDICA_CODENAME,")\n";
171                 echo "-- DB_UPDATE_VERSION ".DB_UPDATE_VERSION."\n";
172                 echo "-- ------------------------------------------\n\n\n";
173                 foreach ($database AS $name => $structure) {
174                         echo "--\n";
175                         echo "-- TABLE $name\n";
176                         echo "--\n";
177                         self::createTable($name, $structure, true, false);
178
179                         echo "\n";
180                 }
181         }
182
183         /**
184          * @brief Print out database error messages
185          *
186          * @param string $message Message to be added to the error message
187          *
188          * @return string Error message
189          */
190         private static function printUpdateError($message) {
191                 echo L10n::t("\nError %d occurred during database update:\n%s\n",
192                         DBA::errorNo(), DBA::errorMessage());
193
194                 return L10n::t('Errors encountered performing database changes: ').$message.EOL;
195         }
196
197         /**
198          * Updates DB structure and returns eventual errors messages
199          *
200          * @param bool  $verbose
201          * @param bool  $action     Whether to actually apply the update
202          * @param bool  $install    Is this the initial update during the installation?
203          * @param array $tables     An array of the database tables
204          * @param array $definition An array of the definition tables
205          * @return string Empty string if the update is successful, error messages otherwise
206          */
207         public static function update($verbose, $action, $install = false, array $tables = null, array $definition = null) {
208                 if ($action && !$install) {
209                         Config::set('system', 'maintenance', 1);
210                         Config::set('system', 'maintenance_reason', L10n::t('%s: Database update', DBM::date().' '.date('e')));
211                 }
212
213                 $errors = '';
214
215                 logger('updating structure', LOGGER_DEBUG);
216
217                 // Get the current structure
218                 $database = [];
219
220                 if (is_null($tables)) {
221                         $tables = q("SHOW TABLES");
222                 }
223
224                 if (DBM::is_result($tables)) {
225                         foreach ($tables AS $table) {
226                                 $table = current($table);
227
228                                 logger(sprintf('updating structure for table %s ...', $table), LOGGER_DEBUG);
229                                 $database[$table] = self::tableStructure($table);
230                         }
231                 }
232
233                 // Get the definition
234                 if (is_null($definition)) {
235                         $definition = self::definition();
236                 }
237
238                 // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
239                 if ((version_compare(DBA::server_info(), '5.7.4') >= 0) &&
240                         !(strpos(DBA::server_info(), 'MariaDB') !== false)) {
241                         $ignore = '';
242                 } else {
243                         $ignore = ' IGNORE';
244                 }
245
246                 // Compare it
247                 foreach ($definition AS $name => $structure) {
248                         $is_new_table = false;
249                         $group_by = "";
250                         $sql3 = "";
251                         $is_unique = false;
252                         $temp_name = $name;
253                         if (!isset($database[$name])) {
254                                 $r = self::createTable($name, $structure, $verbose, $action);
255                                 if (!DBM::is_result($r)) {
256                                         $errors .= self::printUpdateError($name);
257                                 }
258                                 $is_new_table = true;
259                         } else {
260                                 foreach ($structure["indexes"] AS $indexname => $fieldnames) {
261                                         if (isset($database[$name]["indexes"][$indexname])) {
262                                                 $current_index_definition = implode(",",$database[$name]["indexes"][$indexname]);
263                                         } else {
264                                                 $current_index_definition = "__NOT_SET__";
265                                         }
266                                         $new_index_definition = implode(",",$fieldnames);
267                                         if ($current_index_definition != $new_index_definition) {
268                                                 if ($fieldnames[0] == "UNIQUE") {
269                                                         $is_unique = true;
270                                                         if ($ignore == "") {
271                                                                 $temp_name = "temp-".$name;
272                                                         }
273                                                 }
274                                         }
275                                 }
276
277                                 /*
278                                  * Drop the index if it isn't present in the definition
279                                  * or the definition differ from current status
280                                  * and index name doesn't start with "local_"
281                                  */
282                                 foreach ($database[$name]["indexes"] as $indexname => $fieldnames) {
283                                         $current_index_definition = implode(",",$fieldnames);
284                                         if (isset($structure["indexes"][$indexname])) {
285                                                 $new_index_definition = implode(",",$structure["indexes"][$indexname]);
286                                         } else {
287                                                 $new_index_definition = "__NOT_SET__";
288                                         }
289                                         if ($current_index_definition != $new_index_definition && substr($indexname, 0, 6) != 'local_') {
290                                                 $sql2=self::dropIndex($indexname);
291                                                 if ($sql3 == "") {
292                                                         $sql3 = "ALTER".$ignore." TABLE `".$temp_name."` ".$sql2;
293                                                 } else {
294                                                         $sql3 .= ", ".$sql2;
295                                                 }
296                                         }
297                                 }
298                                 // Compare the field structure field by field
299                                 foreach ($structure["fields"] AS $fieldname => $parameters) {
300                                         if (!isset($database[$name]["fields"][$fieldname])) {
301                                                 $sql2=self::addTableField($fieldname, $parameters);
302                                                 if ($sql3 == "") {
303                                                         $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
304                                                 } else {
305                                                         $sql3 .= ", ".$sql2;
306                                                 }
307                                         } else {
308                                                 // Compare the field definition
309                                                 $field_definition = $database[$name]["fields"][$fieldname];
310
311                                                 // Remove the relation data that is used for the referential integrity
312                                                 unset($parameters['relation']);
313
314                                                 // We change the collation after the indexes had been changed.
315                                                 // This is done to avoid index length problems.
316                                                 // So here we always ensure that there is no need to change it.
317                                                 unset($parameters['Collation']);
318                                                 unset($field_definition['Collation']);
319
320                                                 // Only update the comment when it is defined
321                                                 if (!isset($parameters['comment'])) {
322                                                         $parameters['comment'] = "";
323                                                 }
324
325                                                 $current_field_definition = DBA::cleanQuery(implode(",", $field_definition));
326                                                 $new_field_definition = DBA::cleanQuery(implode(",", $parameters));
327                                                 if ($current_field_definition != $new_field_definition) {
328                                                         $sql2 = self::modifyTableField($fieldname, $parameters);
329                                                         if ($sql3 == "") {
330                                                                 $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
331                                                         } else {
332                                                                 $sql3 .= ", ".$sql2;
333                                                         }
334                                                 }
335                                         }
336                                 }
337                         }
338
339                         /*
340                          * Create the index if the index don't exists in database
341                          * or the definition differ from the current status.
342                          * Don't create keys if table is new
343                          */
344                         if (!$is_new_table) {
345                                 foreach ($structure["indexes"] AS $indexname => $fieldnames) {
346                                         if (isset($database[$name]["indexes"][$indexname])) {
347                                                 $current_index_definition = implode(",",$database[$name]["indexes"][$indexname]);
348                                         } else {
349                                                 $current_index_definition = "__NOT_SET__";
350                                         }
351                                         $new_index_definition = implode(",",$fieldnames);
352                                         if ($current_index_definition != $new_index_definition) {
353                                                 $sql2 = self::createIndex($indexname, $fieldnames);
354
355                                                 // Fetch the "group by" fields for unique indexes
356                                                 if ($fieldnames[0] == "UNIQUE") {
357                                                         $group_by = self::groupBy($indexname, $fieldnames);
358                                                 }
359                                                 if ($sql2 != "") {
360                                                         if ($sql3 == "") {
361                                                                 $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
362                                                         } else {
363                                                                 $sql3 .= ", ".$sql2;
364                                                         }
365                                                 }
366                                         }
367                                 }
368
369                                 if (isset($database[$name]["table_status"]["Comment"])) {
370                                         if ($database[$name]["table_status"]["Comment"] != $structure['comment']) {
371                                                 $sql2 = "COMMENT = '".dbesc($structure['comment'])."'";
372
373                                                 if ($sql3 == "") {
374                                                         $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
375                                                 } else {
376                                                         $sql3 .= ", ".$sql2;
377                                                 }
378                                         }
379                                 }
380
381                                 if (isset($database[$name]["table_status"]["Engine"]) && isset($structure['engine'])) {
382                                         if ($database[$name]["table_status"]["Engine"] != $structure['engine']) {
383                                                 $sql2 = "ENGINE = '".dbesc($structure['engine'])."'";
384
385                                                 if ($sql3 == "") {
386                                                         $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
387                                                 } else {
388                                                         $sql3 .= ", ".$sql2;
389                                                 }
390                                         }
391                                 }
392
393                                 if (isset($database[$name]["table_status"]["Collation"])) {
394                                         if ($database[$name]["table_status"]["Collation"] != 'utf8mb4_general_ci') {
395                                                 $sql2 = "DEFAULT COLLATE utf8mb4_general_ci";
396
397                                                 if ($sql3 == "") {
398                                                         $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
399                                                 } else {
400                                                         $sql3 .= ", ".$sql2;
401                                                 }
402                                         }
403                                 }
404
405                                 if ($sql3 != "") {
406                                         $sql3 .= "; ";
407                                 }
408
409                                 // Now have a look at the field collations
410                                 // Compare the field structure field by field
411                                 foreach ($structure["fields"] AS $fieldname => $parameters) {
412                                         // Compare the field definition
413                                         $field_definition = defaults($database[$name]["fields"], $fieldname, ['Collation' => '']);
414
415                                         // Define the default collation if not given
416                                         if (!isset($parameters['Collation']) && !empty($field_definition['Collation'])) {
417                                                 $parameters['Collation'] = 'utf8mb4_general_ci';
418                                         } else {
419                                                 $parameters['Collation'] = null;
420                                         }
421
422                                         if ($field_definition['Collation'] != $parameters['Collation']) {
423                                                 $sql2 = self::modifyTableField($fieldname, $parameters);
424                                                 if (($sql3 == "") || (substr($sql3, -2, 2) == "; ")) {
425                                                         $sql3 .= "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
426                                                 } else {
427                                                         $sql3 .= ", ".$sql2;
428                                                 }
429                                         }
430                                 }
431                         }
432
433                         if ($sql3 != "") {
434                                 if (substr($sql3, -2, 2) != "; ") {
435                                         $sql3 .= ";";
436                                 }
437
438                                 $field_list = '';
439                                 if ($is_unique && $ignore == '') {
440                                         foreach ($database[$name]["fields"] AS $fieldname => $parameters) {
441                                                 $field_list .= 'ANY_VALUE(`' . $fieldname . '`),';
442                                         }
443                                         $field_list = rtrim($field_list, ',');
444                                 }
445
446                                 if ($verbose) {
447                                         // Ensure index conversion to unique removes duplicates
448                                         if ($is_unique && ($temp_name != $name)) {
449                                                 if ($ignore != "") {
450                                                         echo "SET session old_alter_table=1;\n";
451                                                 } else {
452                                                         echo "DROP TABLE IF EXISTS `".$temp_name."`;\n";
453                                                         echo "CREATE TABLE `".$temp_name."` LIKE `".$name."`;\n";
454                                                 }
455                                         }
456
457                                         echo $sql3."\n";
458
459                                         if ($is_unique && ($temp_name != $name)) {
460                                                 if ($ignore != "") {
461                                                         echo "SET session old_alter_table=0;\n";
462                                                 } else {
463                                                         echo "INSERT INTO `".$temp_name."` SELECT ".DBA::anyValueFallback($field_list)." FROM `".$name."`".$group_by.";\n";
464                                                         echo "DROP TABLE `".$name."`;\n";
465                                                         echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
466                                                 }
467                                         }
468                                 }
469
470                                 if ($action) {
471                                         if (!$install) {
472                                                 Config::set('system', 'maintenance_reason', L10n::t('%s: updating %s table.', DBM::date().' '.date('e'), $name));
473                                         }
474
475                                         // Ensure index conversion to unique removes duplicates
476                                         if ($is_unique && ($temp_name != $name)) {
477                                                 if ($ignore != "") {
478                                                         DBA::e("SET session old_alter_table=1;");
479                                                 } else {
480                                                         $r = DBA::e("DROP TABLE IF EXISTS `".$temp_name."`;");
481                                                         if (!DBM::is_result($r)) {
482                                                                 $errors .= self::printUpdateError($sql3);
483                                                                 return $errors;
484                                                         }
485
486                                                         $r = DBA::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
487                                                         if (!DBM::is_result($r)) {
488                                                                 $errors .= self::printUpdateError($sql3);
489                                                                 return $errors;
490                                                         }
491                                                 }
492                                         }
493
494                                         $r = DBA::e($sql3);
495                                         if (!DBM::is_result($r)) {
496                                                 $errors .= self::printUpdateError($sql3);
497                                         }
498                                         if ($is_unique && ($temp_name != $name)) {
499                                                 if ($ignore != "") {
500                                                         DBA::e("SET session old_alter_table=0;");
501                                                 } else {
502                                                         $r = DBA::e("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";");
503                                                         if (!DBM::is_result($r)) {
504                                                                 $errors .= self::printUpdateError($sql3);
505                                                                 return $errors;
506                                                         }
507                                                         $r = DBA::e("DROP TABLE `".$name."`;");
508                                                         if (!DBM::is_result($r)) {
509                                                                 $errors .= self::printUpdateError($sql3);
510                                                                 return $errors;
511                                                         }
512                                                         $r = DBA::e("RENAME TABLE `".$temp_name."` TO `".$name."`;");
513                                                         if (!DBM::is_result($r)) {
514                                                                 $errors .= self::printUpdateError($sql3);
515                                                                 return $errors;
516                                                         }
517                                                 }
518                                         }
519                                 }
520                         }
521                 }
522
523                 if ($action && !$install) {
524                         Config::set('system', 'maintenance', 0);
525                         Config::set('system', 'maintenance_reason', '');
526
527                         if ($errors) {
528                                 Config::set('system', 'dbupdate', DB_UPDATE_FAILED);
529                         } else {
530                                 Config::set('system', 'dbupdate', DB_UPDATE_SUCCESSFUL);
531                         }
532                 }
533
534                 return $errors;
535         }
536
537         private static function FieldCommand($parameters, $create = true) {
538                 $fieldstruct = $parameters["type"];
539
540                 if (isset($parameters["Collation"])) {
541                         $fieldstruct .= " COLLATE ".$parameters["Collation"];
542                 }
543
544                 if (isset($parameters["not null"])) {
545                         $fieldstruct .= " NOT NULL";
546                 }
547
548                 if (isset($parameters["default"])) {
549                         if (strpos(strtolower($parameters["type"]),"int")!==false) {
550                                 $fieldstruct .= " DEFAULT ".$parameters["default"];
551                         } else {
552                                 $fieldstruct .= " DEFAULT '".$parameters["default"]."'";
553                         }
554                 }
555                 if (isset($parameters["extra"])) {
556                         $fieldstruct .= " ".$parameters["extra"];
557                 }
558
559                 if (isset($parameters["comment"])) {
560                         $fieldstruct .= " COMMENT '".dbesc($parameters["comment"])."'";
561                 }
562
563                 /*if (($parameters["primary"] != "") && $create)
564                         $fieldstruct .= " PRIMARY KEY";*/
565
566                 return($fieldstruct);
567         }
568
569         private static function createTable($name, $structure, $verbose, $action) {
570                 $r = true;
571
572                 $engine = "";
573                 $comment = "";
574                 $sql_rows = [];
575                 $primary_keys = [];
576                 foreach ($structure["fields"] AS $fieldname => $field) {
577                         $sql_rows[] = "`".dbesc($fieldname)."` ".self::FieldCommand($field);
578                         if (x($field,'primary') && $field['primary']!='') {
579                                 $primary_keys[] = $fieldname;
580                         }
581                 }
582
583                 if (!empty($structure["indexes"])) {
584                         foreach ($structure["indexes"] AS $indexname => $fieldnames) {
585                                 $sql_index = self::createIndex($indexname, $fieldnames, "");
586                                 if (!is_null($sql_index)) {
587                                         $sql_rows[] = $sql_index;
588                                 }
589                         }
590                 }
591
592                 if (isset($structure["engine"])) {
593                         $engine = " ENGINE=" . $structure["engine"];
594                 }
595
596                 if (isset($structure["comment"])) {
597                         $comment = " COMMENT='" . dbesc($structure["comment"]) . "'";
598                 }
599
600                 $sql = implode(",\n\t", $sql_rows);
601
602                 $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n\t", dbesc($name)).$sql.
603                                 "\n)" . $engine . " DEFAULT COLLATE utf8mb4_general_ci" . $comment;
604                 if ($verbose) {
605                         echo $sql.";\n";
606                 }
607
608                 if ($action) {
609                         $r = DBA::e($sql);
610                 }
611
612                 return $r;
613         }
614
615         private static function addTableField($fieldname, $parameters) {
616                 $sql = sprintf("ADD `%s` %s", dbesc($fieldname), self::FieldCommand($parameters));
617                 return($sql);
618         }
619
620         private static function modifyTableField($fieldname, $parameters) {
621                 $sql = sprintf("MODIFY `%s` %s", dbesc($fieldname), self::FieldCommand($parameters, false));
622                 return($sql);
623         }
624
625         private static function dropIndex($indexname) {
626                 $sql = sprintf("DROP INDEX `%s`", dbesc($indexname));
627                 return($sql);
628         }
629
630         private static function createIndex($indexname, $fieldnames, $method = "ADD") {
631                 $method = strtoupper(trim($method));
632                 if ($method!="" && $method!="ADD") {
633                         throw new Exception("Invalid parameter 'method' in self::createIndex(): '$method'");
634                 }
635
636                 if ($fieldnames[0] == "UNIQUE") {
637                         array_shift($fieldnames);
638                         $method .= ' UNIQUE';
639                 }
640
641                 $names = "";
642                 foreach ($fieldnames AS $fieldname) {
643                         if ($names != "") {
644                                 $names .= ",";
645                         }
646
647                         if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches)) {
648                                 $names .= "`".dbesc($matches[1])."`(".intval($matches[2]).")";
649                         } else {
650                                 $names .= "`".dbesc($fieldname)."`";
651                         }
652                 }
653
654                 if ($indexname == "PRIMARY") {
655                         return sprintf("%s PRIMARY KEY(%s)", $method, $names);
656                 }
657
658
659                 $sql = sprintf("%s INDEX `%s` (%s)", $method, dbesc($indexname), $names);
660                 return($sql);
661         }
662
663         private static function groupBy($indexname, $fieldnames) {
664                 if ($fieldnames[0] != "UNIQUE") {
665                         return "";
666                 }
667
668                 array_shift($fieldnames);
669
670                 $names = "";
671                 foreach ($fieldnames AS $fieldname) {
672                         if ($names != "") {
673                                 $names .= ",";
674                         }
675
676                         if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches)) {
677                                 $names .= "`".dbesc($matches[1])."`";
678                         } else {
679                                 $names .= "`".dbesc($fieldname)."`";
680                         }
681                 }
682
683                 $sql = sprintf(" GROUP BY %s", $names);
684                 return $sql;
685         }
686
687         /**
688          *      Check if a table exists
689          *
690          * @param string $table Table name
691          *
692          * @return boolean Does the table exist?
693          */
694         public static function existsTable($table)
695         {
696                 if (empty($table)) {
697                         return false;
698                 }
699
700                 $table = DBA::escape($table);
701
702                 $sql = "SHOW TABLES LIKE '" . $table . "';";
703
704                 $stmt = DBA::p($sql);
705
706                 if (is_bool($stmt)) {
707                         $retval = $stmt;
708                 } else {
709                         $retval = (DBA::num_rows($stmt) > 0);
710                 }
711
712                 DBA::close($stmt);
713
714                 return $retval;
715         }
716
717         /**
718          *      Check if the columns of the table exists
719          *
720          * @param string $table   Table name
721          * @param array  $columns Columns to check ( Syntax: [ $col1, $col2, .. ] )
722          *
723          * @return boolean Does the table exist?
724          */
725         public static function existsColumn($table, $columns = []) {
726                 if (empty($table)) {
727                         return false;
728                 }
729
730                 if (is_null($columns) || empty($columns)) {
731                         return self::existsTable($table);
732                 }
733
734                 $table = DBA::escape($table);
735
736                 foreach ($columns AS $column) {
737                         $sql = "SHOW COLUMNS FROM `" . $table . "` LIKE '" . $column . "';";
738
739                         $stmt = DBA::p($sql);
740
741                         if (is_bool($stmt)) {
742                                 $retval = $stmt;
743                         } else {
744                                 $retval = (DBA::num_rows($stmt) > 0);
745                         }
746
747                         DBA::close($stmt);
748
749                         if (!$retval) {
750                                 return false;
751                         }
752                 }
753
754                 return true;
755         }
756
757         const RENAME_COLUMN = 0;
758         const RENAME_PRIMARY_KEY = 1;
759
760         /**
761          * Renames columns or the primary key of a table
762          * @todo You cannot rename a primary key if "auto increment" is set
763          *
764          * @param string $table    Table name
765          * @param array  $columns  Columns Syntax for Rename: [ $old1 => [ $new1, $type1 ], $old2 => [ $new2, $type2 ], ... ] )
766          *                                 Syntax for Primary Key: [ $col1, $col2, ...] )
767          * @param int    $type     The type of renaming (Default is Column)
768          *
769          * @return boolean Was the renaming successful?
770          *
771          */
772         public static function rename($table, $columns, $type = self::RENAME_COLUMN) {
773                 if (empty($table) || empty($columns)) {
774                         return false;
775                 }
776
777                 if (!is_array($columns)) {
778                         return false;
779                 }
780
781                 $table = DBA::escape($table);
782
783                 $sql = "ALTER TABLE `" . $table . "`";
784                 switch ($type) {
785                         case self::RENAME_COLUMN:
786                                 if (!self::existsColumn($table, array_keys($columns))) {
787                                         return false;
788                                 }
789                                 $sql .= implode(',', array_map(
790                                         function ($to, $from) {
791                                                 return " CHANGE `" . $from . "` `" . $to[0] . "` " . $to[1];
792                                         },
793                                         $columns,
794                                         array_keys($columns)
795                                 ));
796                                 break;
797                         case self::RENAME_PRIMARY_KEY:
798                                 if (!self::existsColumn($table, $columns)) {
799                                         return false;
800                                 }
801                                 $sql .= " DROP PRIMARY KEY, ADD PRIMARY KEY(`" . implode('`, `', $columns) . "`)";
802                                 break;
803                         default:
804                                 return false;
805                 }
806
807                 $sql .= ";";
808
809                 $stmt = DBA::p($sql);
810
811                 if (is_bool($stmt)) {
812                         $retval = $stmt;
813                 } else {
814                         $retval = true;
815                 }
816
817                 DBA::close($stmt);
818
819                 return $retval;
820         }
821
822         public static function definition() {
823                 $database = [];
824
825                 $database["addon"] = [
826                                 "comment" => "registered addons",
827                                 "fields" => [
828                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
829                                                 "name" => ["type" => "varchar(50)", "not null" => "1", "default" => "", "comment" => "addon base (file)name"],
830                                                 "version" => ["type" => "varchar(50)", "not null" => "1", "default" => "", "comment" => "currently unused"],
831                                                 "installed" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "currently always 1"],
832                                                 "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "currently unused"],
833                                                 "timestamp" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "file timestamp to check for reloads"],
834                                                 "plugin_admin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = has admin config, 0 = has no admin config"],
835                                                 ],
836                                 "indexes" => [
837                                                 "PRIMARY" => ["id"],
838                                                 "name" => ["UNIQUE", "name"],
839                                                 ]
840                                 ];
841                 $database["attach"] = [
842                                 "comment" => "file attachments",
843                                 "fields" => [
844                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "generated index"],
845                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
846                                                 "hash" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "hash"],
847                                                 "filename" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "filename of original"],
848                                                 "filetype" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "mimetype"],
849                                                 "filesize" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "size in bytes"],
850                                                 "data" => ["type" => "longblob", "not null" => "1", "comment" => "file data"],
851                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "creation time"],
852                                                 "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "last edit time"],
853                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>"],
854                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
855                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
856                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
857                                                 ],
858                                 "indexes" => [
859                                                 "PRIMARY" => ["id"],
860                                                 ]
861                                 ];
862                 $database["auth_codes"] = [
863                                 "comment" => "OAuth usage",
864                                 "fields" => [
865                                                 "id" => ["type" => "varchar(40)", "not null" => "1", "primary" => "1", "comment" => ""],
866                                                 "client_id" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => ["clients" => "client_id"], "comment" => ""],
867                                                 "redirect_uri" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""],
868                                                 "expires" => ["type" => "int", "not null" => "1", "default" => "0", "comment" => ""],
869                                                 "scope" => ["type" => "varchar(250)", "not null" => "1", "default" => "", "comment" => ""],
870                                                 ],
871                                 "indexes" => [
872                                                 "PRIMARY" => ["id"],
873                                                 ]
874                                 ];
875                 $database["cache"] = [
876                                 "comment" => "Stores temporary data",
877                                 "fields" => [
878                                                 "k" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "cache key"],
879                                                 "v" => ["type" => "mediumtext", "comment" => "cached serialized value"],
880                                                 "expires" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of cache expiration"],
881                                                 "updated" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of cache insertion"],
882                                                 ],
883                                 "indexes" => [
884                                                 "PRIMARY" => ["k"],
885                                                 "k_expires" => ["k", "expires"],
886                                                 ]
887                                 ];
888                 $database["challenge"] = [
889                                 "comment" => "",
890                                 "fields" => [
891                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
892                                                 "challenge" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
893                                                 "dfrn-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
894                                                 "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
895                                                 "type" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
896                                                 "last_update" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
897                                                 ],
898                                 "indexes" => [
899                                                 "PRIMARY" => ["id"],
900                                                 ]
901                                 ];
902                 $database["clients"] = [
903                                 "comment" => "OAuth usage",
904                                 "fields" => [
905                                                 "client_id" => ["type" => "varchar(20)", "not null" => "1", "primary" => "1", "comment" => ""],
906                                                 "pw" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""],
907                                                 "redirect_uri" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""],
908                                                 "name" => ["type" => "text", "comment" => ""],
909                                                 "icon" => ["type" => "text", "comment" => ""],
910                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
911                                                 ],
912                                 "indexes" => [
913                                                 "PRIMARY" => ["client_id"],
914                                                 ]
915                                 ];
916                 $database["config"] = [
917                                 "comment" => "main configuration storage",
918                                 "fields" => [
919                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
920                                                 "cat" => ["type" => "varbinary(50)", "not null" => "1", "default" => "", "comment" => ""],
921                                                 "k" => ["type" => "varbinary(50)", "not null" => "1", "default" => "", "comment" => ""],
922                                                 "v" => ["type" => "mediumtext", "comment" => ""],
923                                                 ],
924                                 "indexes" => [
925                                                 "PRIMARY" => ["id"],
926                                                 "cat_k" => ["UNIQUE", "cat", "k"],
927                                                 ]
928                                 ];
929                 $database["contact"] = [
930                                 "comment" => "contact table",
931                                 "fields" => [
932                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
933                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
934                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
935                                                 "self" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 if the contact is the user him/her self"],
936                                                 "remote_self" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
937                                                 "rel" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "The kind of the relation between the user and the contact"],
938                                                 "duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
939                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network protocol of the contact"],
940                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this contact is known by"],
941                                                 "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Nick- and user name of the contact"],
942                                                 "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
943                                                 "about" => ["type" => "text", "comment" => ""],
944                                                 "keywords" => ["type" => "text", "comment" => "public keywords (interests) of the contact"],
945                                                 "gender" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
946                                                 "xmpp" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
947                                                 "attag" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
948                                                 "avatar" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
949                                                 "photo" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo of the contact"],
950                                                 "thumb" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo (thumb size)"],
951                                                 "micro" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo (micro size)"],
952                                                 "site-pubkey" => ["type" => "text", "comment" => ""],
953                                                 "issued-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
954                                                 "dfrn-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
955                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
956                                                 "nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
957                                                 "addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
958                                                 "alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
959                                                 "pubkey" => ["type" => "text", "comment" => "RSA public key 4096 bit"],
960                                                 "prvkey" => ["type" => "text", "comment" => "RSA private key 4096 bit"],
961                                                 "batch" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
962                                                 "request" => ["type" => "varchar(255)", "comment" => ""],
963                                                 "notify" => ["type" => "varchar(255)", "comment" => ""],
964                                                 "poll" => ["type" => "varchar(255)", "comment" => ""],
965                                                 "confirm" => ["type" => "varchar(255)", "comment" => ""],
966                                                 "poco" => ["type" => "varchar(255)", "comment" => ""],
967                                                 "aes_allow" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
968                                                 "ret-aes" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
969                                                 "usehub" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
970                                                 "subhub" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
971                                                 "hub-verify" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
972                                                 "last-update" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of the last try to update the contact info"],
973                                                 "success_update" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of the last successful contact update"],
974                                                 "failure_update" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of the last failed update"],
975                                                 "name-date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
976                                                 "uri-date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
977                                                 "avatar-date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
978                                                 "term-date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
979                                                 "last-item" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "date of the last post"],
980                                                 "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
981                                                 "blocked" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
982                                                 "readonly" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "posts of the contact are readonly"],
983                                                 "writable" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
984                                                 "forum" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a forum"],
985                                                 "prv" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a private group"],
986                                                 "contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => ""],
987                                                 "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
988                                                 "archive" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
989                                                 "pending" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
990                                                 "rating" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => ""],
991                                                 "reason" => ["type" => "text", "comment" => ""],
992                                                 "closeness" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "99", "comment" => ""],
993                                                 "info" => ["type" => "mediumtext", "comment" => ""],
994                                                 "profile-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
995                                                 "bdyear" => ["type" => "varchar(4)", "not null" => "1", "default" => "", "comment" => ""],
996                                                 "bd" => ["type" => "date", "not null" => "1", "default" => "0001-01-01", "comment" => ""],
997                                                 "notify_new_posts" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
998                                                 "fetch_further_information" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
999                                                 "ffi_keyword_blacklist" => ["type" => "text", "comment" => ""],
1000                                                 ],
1001                                 "indexes" => [
1002                                                 "PRIMARY" => ["id"],
1003                                                 "uid_name" => ["uid", "name(190)"],
1004                                                 "self_uid" => ["self", "uid"],
1005                                                 "alias_uid" => ["alias(32)", "uid"],
1006                                                 "pending_uid" => ["pending", "uid"],
1007                                                 "blocked_uid" => ["blocked", "uid"],
1008                                                 "uid_rel_network_poll" => ["uid", "rel", "network", "poll(64)", "archive"],
1009                                                 "uid_network_batch" => ["uid", "network", "batch(64)"],
1010                                                 "addr_uid" => ["addr(32)", "uid"],
1011                                                 "nurl_uid" => ["nurl(32)", "uid"],
1012                                                 "nick_uid" => ["nick(32)", "uid"],
1013                                                 "dfrn-id" => ["dfrn-id(64)"],
1014                                                 "issued-id" => ["issued-id(64)"],
1015                                                 ]
1016                                 ];
1017                 $database["conv"] = [
1018                                 "comment" => "private messages",
1019                                 "fields" => [
1020                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1021                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this conversation"],
1022                                                 "recips" => ["type" => "text", "comment" => "sender_handle;recipient_handle"],
1023                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1024                                                 "creator" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "handle of creator"],
1025                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "creation timestamp"],
1026                                                 "updated" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "edited timestamp"],
1027                                                 "subject" => ["type" => "text", "comment" => "subject of initial message"],
1028                                                 ],
1029                                 "indexes" => [
1030                                                 "PRIMARY" => ["id"],
1031                                                 "uid" => ["uid"],
1032                                                 ]
1033                                 ];
1034                 $database["conversation"] = [
1035                                 "comment" => "Raw data and structure information for messages",
1036                                 "fields" => [
1037                                                 "item-uri" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "URI of the item"],
1038                                                 "reply-to-uri" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "URI to which this item is a reply"],
1039                                                 "conversation-uri" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "GNU Social conversation URI"],
1040                                                 "conversation-href" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "GNU Social conversation link"],
1041                                                 "protocol" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "The protocol of the item"],
1042                                                 "source" => ["type" => "mediumtext", "comment" => "Original source"],
1043                                                 "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Receiving date"],
1044                                                 ],
1045                                 "indexes" => [
1046                                                 "PRIMARY" => ["item-uri"],
1047                                                 "conversation-uri" => ["conversation-uri"],
1048                                                 "received" => ["received"],
1049                                                 ]
1050                                 ];
1051                 $database["event"] = [
1052                                 "comment" => "Events",
1053                                 "fields" => [
1054                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1055                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1056                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1057                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact_id (ID of the contact in contact table)"],
1058                                                 "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1059                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "creation time"],
1060                                                 "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "last edit time"],
1061                                                 "start" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "event start time"],
1062                                                 "finish" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "event end time"],
1063                                                 "summary" => ["type" => "text", "comment" => "short description or title of the event"],
1064                                                 "desc" => ["type" => "text", "comment" => "event description"],
1065                                                 "location" => ["type" => "text", "comment" => "event location"],
1066                                                 "type" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => "event or birthday"],
1067                                                 "nofinish" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if event does have no end this is 1"],
1068                                                 "adjust" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "adjust to timezone of the recipient (0 or 1)"],
1069                                                 "ignore" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "0 or 1"],
1070                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
1071                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
1072                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
1073                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
1074                                                 ],
1075                                 "indexes" => [
1076                                                 "PRIMARY" => ["id"],
1077                                                 "uid_start" => ["uid", "start"],
1078                                                 ]
1079                                 ];
1080                 $database["fcontact"] = [
1081                                 "comment" => "Diaspora compatible contacts - used in the Diaspora implementation",
1082                                 "fields" => [
1083                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1084                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "unique id"],
1085                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1086                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1087                                                 "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1088                                                 "request" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1089                                                 "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1090                                                 "addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1091                                                 "batch" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1092                                                 "notify" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1093                                                 "poll" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1094                                                 "confirm" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1095                                                 "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1096                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
1097                                                 "alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1098                                                 "pubkey" => ["type" => "text", "comment" => ""],
1099                                                 "updated" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1100                                                 ],
1101                                 "indexes" => [
1102                                                 "PRIMARY" => ["id"],
1103                                                 "addr" => ["addr(32)"],
1104                                                 "url" => ["UNIQUE", "url(190)"],
1105                                                 ]
1106                                 ];
1107                 $database["fsuggest"] = [
1108                                 "comment" => "friend suggestion stuff",
1109                                 "fields" => [
1110                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
1111                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1112                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
1113                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1114                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1115                                                 "request" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1116                                                 "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1117                                                 "note" => ["type" => "text", "comment" => ""],
1118                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1119                                                 ],
1120                                 "indexes" => [
1121                                                 "PRIMARY" => ["id"],
1122                                                 ]
1123                                 ];
1124                 $database["gcign"] = [
1125                                 "comment" => "contacts ignored by friend suggestions",
1126                                 "fields" => [
1127                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1128                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Local User id"],
1129                                                 "gcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => "gcontact.id of ignored contact"],
1130                                                 ],
1131                                 "indexes" => [
1132                                                 "PRIMARY" => ["id"],
1133                                                 "uid" => ["uid"],
1134                                                 "gcid" => ["gcid"],
1135                                                 ]
1136                                 ];
1137                 $database["gcontact"] = [
1138                                 "comment" => "global contacts",
1139                                 "fields" => [
1140                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1141                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this contact is known by"],
1142                                                 "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Nick- and user name of the contact"],
1143                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the contacts profile page"],
1144                                                 "nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1145                                                 "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the profile photo"],
1146                                                 "connect" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1147                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1148                                                 "updated" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1149                                                 "last_contact" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1150                                                 "last_failure" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1151                                                 "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1152                                                 "about" => ["type" => "text", "comment" => ""],
1153                                                 "keywords" => ["type" => "text", "comment" => "puplic keywords (interests)"],
1154                                                 "gender" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
1155                                                 "birthday" => ["type" => "varchar(32)", "not null" => "1", "default" => "0001-01-01", "comment" => ""],
1156                                                 "community" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 if contact is forum account"],
1157                                                 "contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "-1", "comment" => ""],
1158                                                 "hide" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = should be hidden from search"],
1159                                                 "nsfw" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = contact posts nsfw content"],
1160                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "social network protocol"],
1161                                                 "addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1162                                                 "notify" => ["type" => "varchar(255)", "comment" => ""],
1163                                                 "alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1164                                                 "generation" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1165                                                 "server_url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "baseurl of the contacts server"],
1166                                                 ],
1167                                 "indexes" => [
1168                                                 "PRIMARY" => ["id"],
1169                                                 "nurl" => ["UNIQUE", "nurl(190)"],
1170                                                 "name" => ["name(64)"],
1171                                                 "nick" => ["nick(32)"],
1172                                                 "addr" => ["addr(64)"],
1173                                                 "hide_network_updated" => ["hide", "network", "updated"],
1174                                                 "updated" => ["updated"],
1175                                                 ]
1176                                 ];
1177                 $database["glink"] = [
1178                                 "comment" => "'friends of friends' linkages derived from poco",
1179                                 "fields" => [
1180                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1181                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
1182                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1183                                                 "gcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => ""],
1184                                                 "zcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => ""],
1185                                                 "updated" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1186                                                 ],
1187                                 "indexes" => [
1188                                                 "PRIMARY" => ["id"],
1189                                                 "cid_uid_gcid_zcid" => ["UNIQUE", "cid","uid","gcid","zcid"],
1190                                                 "gcid" => ["gcid"],
1191                                                 ]
1192                                 ];
1193                 $database["group"] = [
1194                                 "comment" => "privacy groups, group info",
1195                                 "fields" => [
1196                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1197                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1198                                                 "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 indicates the member list is not private"],
1199                                                 "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 indicates the group has been deleted"],
1200                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "human readable name of group"],
1201                                                 ],
1202                                 "indexes" => [
1203                                                 "PRIMARY" => ["id"],
1204                                                 "uid" => ["uid"],
1205                                                 ]
1206                                 ];
1207                 $database["group_member"] = [
1208                                 "comment" => "privacy groups, member info",
1209                                 "fields" => [
1210                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1211                                                 "gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["group" => "id"], "comment" => "groups.id of the associated group"],
1212                                                 "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id of the member assigned to the associated group"],
1213                                                 ],
1214                                 "indexes" => [
1215                                                 "PRIMARY" => ["id"],
1216                                                 "contactid" => ["contact-id"],
1217                                                 "gid_contactid" => ["UNIQUE", "gid", "contact-id"],
1218                                                 ]
1219                                 ];
1220                 $database["gserver"] = [
1221                                 "comment" => "Global servers",
1222                                 "fields" => [
1223                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1224                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1225                                                 "nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1226                                                 "version" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1227                                                 "site_name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1228                                                 "info" => ["type" => "text", "comment" => ""],
1229                                                 "register_policy" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => ""],
1230                                                 "registered-users" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Number of registered users"],
1231                                                 "poco" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1232                                                 "noscrape" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1233                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
1234                                                 "platform" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1235                                                 "relay-subscribe" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Has the server subscribed to the relay system"],
1236                                                 "relay-scope" => ["type" => "varchar(10)", "not null" => "1", "default" => "", "comment" => "The scope of messages that the server wants to get"],
1237                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1238                                                 "last_poco_query" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1239                                                 "last_contact" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1240                                                 "last_failure" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1241                                                 ],
1242                                 "indexes" => [
1243                                                 "PRIMARY" => ["id"],
1244                                                 "nurl" => ["UNIQUE", "nurl(190)"],
1245                                                 ]
1246                                 ];
1247                 $database["gserver-tag"] = [
1248                                 "comment" => "Tags that the server has subscribed",
1249                                 "fields" => [
1250                                                 "gserver-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gserver" => "id"], "primary" => "1", "comment" => "The id of the gserver"],
1251                                                 "tag" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "primary" => "1", "comment" => "Tag that the server has subscribed"],
1252                                                 ],
1253                                 "indexes" => [
1254                                                 "PRIMARY" => ["gserver-id", "tag"],
1255                                                 "tag" => ["tag"],
1256                                                 ]
1257                                 ];
1258                 $database["hook"] = [
1259                                 "comment" => "addon hook registry",
1260                                 "fields" => [
1261                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1262                                                 "hook" => ["type" => "varbinary(100)", "not null" => "1", "default" => "", "comment" => "name of hook"],
1263                                                 "file" => ["type" => "varbinary(200)", "not null" => "1", "default" => "", "comment" => "relative filename of hook handler"],
1264                                                 "function" => ["type" => "varbinary(200)", "not null" => "1", "default" => "", "comment" => "function name of hook handler"],
1265                                                 "priority" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => "not yet implemented - can be used to sort conflicts in hook handling by calling handlers in priority order"],
1266                                                 ],
1267                                 "indexes" => [
1268                                                 "PRIMARY" => ["id"],
1269                                                 "hook_file_function" => ["UNIQUE", "hook", "file", "function"],
1270                                                 ]
1271                                 ];
1272                 $database["intro"] = [
1273                                 "comment" => "",
1274                                 "fields" => [
1275                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1276                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1277                                                 "fid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["fcontact" => "id"], "comment" => ""],
1278                                                 "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
1279                                                 "knowyou" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1280                                                 "duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1281                                                 "note" => ["type" => "text", "comment" => ""],
1282                                                 "hash" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1283                                                 "datetime" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1284                                                 "blocked" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
1285                                                 "ignore" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1286                                                 ],
1287                                 "indexes" => [
1288                                                 "PRIMARY" => ["id"],
1289                                                 ]
1290                                 ];
1291                 $database["item"] = [
1292                                 "comment" => "Structure for all posts",
1293                                 "fields" => [
1294                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
1295                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this item"],
1296                                                 "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1297                                                 "uri-hash" => ["type" => "varchar(80)", "not null" => "1", "default" => "", "comment" => "RIPEMD-128 hash from uri"],
1298                                                 "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"],
1299                                                 "parent-uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "uri of the parent to this item"],
1300                                                 "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"],
1301                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Creation timestamp."],
1302                                                 "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last edit (default is created)"],
1303                                                 "commented" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last comment/reply to this item"],
1304                                                 "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime"],
1305                                                 "changed" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date that something in the conversation changed, indicating clients should fetch the conversation again"],
1306                                                 "gravity" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1307                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"],
1308                                                 "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"],
1309                                                 "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"],
1310                                                 "icid" => ["type" => "int unsigned", "relation" => ["item-content" => "id"], "comment" => "Id of the item-content table entry that contains the whole item content"],
1311                                                 "iaid" => ["type" => "int unsigned", "relation" => ["item-activity" => "id"], "comment" => "Id of the item-activity table entry that contains the activity data"],
1312                                                 "extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1313                                                 "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
1314                                                 "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1315                                                 "private" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "distribution is restricted"],
1316                                                 "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1317                                                 "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1318                                                 "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been deleted"],
1319                                                 // User specific fields. Eventually they will move to user-item
1320                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
1321                                                 "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
1322                                                 "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "This item was posted to the wall of uid"],
1323                                                 "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item originated at this site"],
1324                                                 "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1325                                                 "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been favourited"],
1326                                                 "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
1327                                                 "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"],
1328                                                 "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1329                                                 "psid" => ["type" => "int unsigned", "relation" => ["permissionset" => "id"], "comment" => "ID of the permission set of this post"],
1330                                                 // These fields will be replaced by the "psid" from above
1331                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
1332                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
1333                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
1334                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
1335                                                 // It is to be decided whether these fields belong to the user or the structure
1336                                                 "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"],
1337                                                 "event-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
1338                                                 // Could possibly be replaced by the "attach" table?
1339                                                 "attach" => ["type" => "mediumtext", "comment" => "JSON structure representing attachments to this item"],
1340                                                 // Deprecated fields. Will be removed in upcoming versions
1341                                                 "postopts" => ["type" => "text", "comment" => "Deprecated"],
1342                                                 "inform" => ["type" => "mediumtext", "comment" => "Deprecated"],
1343                                                 "type" => ["type" => "varchar(20)", "comment" => "Deprecated"],
1344                                                 "bookmark" => ["type" => "boolean", "comment" => "Deprecated"],
1345                                                 "file" => ["type" => "mediumtext", "comment" => "Deprecated"],
1346                                                 "location" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1347                                                 "coord" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1348                                                 "tag" => ["type" => "mediumtext", "comment" => "Deprecated"],
1349                                                 "plink" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1350                                                 "title" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1351                                                 "content-warning" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1352                                                 "body" => ["type" => "mediumtext", "comment" => "Deprecated"],
1353                                                 "app" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1354                                                 "verb" => ["type" => "varchar(100)", "comment" => "Deprecated"],
1355                                                 "object-type" => ["type" => "varchar(100)", "comment" => "Deprecated"],
1356                                                 "object" => ["type" => "text", "comment" => "Deprecated"],
1357                                                 "target-type" => ["type" => "varchar(100)", "comment" => "Deprecated"],
1358                                                 "target" => ["type" => "text", "comment" => "Deprecated"],
1359                                                 "author-name" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1360                                                 "author-link" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1361                                                 "author-avatar" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1362                                                 "owner-name" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1363                                                 "owner-link" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1364                                                 "owner-avatar" => ["type" => "varchar(255)", "comment" => "Deprecated"],
1365                                                 "rendered-hash" => ["type" => "varchar(32)", "comment" => "Deprecated"],
1366                                                 "rendered-html" => ["type" => "mediumtext", "comment" => "Deprecated"],
1367                                                 ],
1368                                 "indexes" => [
1369                                                 "PRIMARY" => ["id"],
1370                                                 "guid" => ["guid(191)"],
1371                                                 "uri" => ["uri(191)"],
1372                                                 "parent" => ["parent"],
1373                                                 "parent-uri" => ["parent-uri(191)"],
1374                                                 "extid" => ["extid(191)"],
1375                                                 "uid_id" => ["uid","id"],
1376                                                 "uid_contactid_id" => ["uid","contact-id","id"],
1377                                                 "uid_created" => ["uid","created"],
1378                                                 "uid_commented" => ["uid","commented"],
1379                                                 "uid_unseen_contactid" => ["uid","unseen","contact-id"],
1380                                                 "uid_network_received" => ["uid","network","received"],
1381                                                 "uid_network_commented" => ["uid","network","commented"],
1382                                                 "uid_thrparent" => ["uid","thr-parent(190)"],
1383                                                 "uid_parenturi" => ["uid","parent-uri(190)"],
1384                                                 "uid_contactid_created" => ["uid","contact-id","created"],
1385                                                 "authorid_created" => ["author-id","created"],
1386                                                 "ownerid" => ["owner-id"],
1387                                                 "uid_uri" => ["uid", "uri(190)"],
1388                                                 "resource-id" => ["resource-id"],
1389                                                 "deleted_changed" => ["deleted","changed"],
1390                                                 "uid_wall_changed" => ["uid","wall","changed"],
1391                                                 "uid_eventid" => ["uid","event-id"],
1392                                                 "icid" => ["icid"],
1393                                                 "iaid" => ["iaid"],
1394                                                 "psid" => ["psid"],
1395                                                 ]
1396                                 ];
1397                 $database["item-activity"] = [
1398                                 "comment" => "Activities for items",
1399                                 "fields" => [
1400                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
1401                                                 "uri" => ["type" => "varchar(255)", "comment" => ""],
1402                                                 "uri-hash" => ["type" => "varchar(80)", "not null" => "1", "default" => "", "comment" => "RIPEMD-128 hash from uri"],
1403                                                 "activity" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1404                                                 ],
1405                                 "indexes" => [
1406                                                 "PRIMARY" => ["id"],
1407                                                 "uri-hash" => ["UNIQUE", "uri-hash"],
1408                                                 "uri" => ["uri(191)"],
1409                                                 ]
1410                                 ];
1411                 $database["item-content"] = [
1412                                 "comment" => "Content for all posts",
1413                                 "fields" => [
1414                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
1415                                                 "uri" => ["type" => "varchar(255)", "comment" => ""],
1416                                                 "uri-plink-hash" => ["type" => "varchar(80)", "not null" => "1", "default" => "", "comment" => "RIPEMD-128 hash from uri"],
1417                                                 "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "item title"],
1418                                                 "content-warning" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1419                                                 "body" => ["type" => "mediumtext", "comment" => "item body content"],
1420                                                 "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "text location where this item originated"],
1421                                                 "coord" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "longitude/latitude pair representing location where this item originated"],
1422                                                 "language" => ["type" => "text", "comment" => "Language information about this post"],
1423                                                 "app" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "application which generated this item"],
1424                                                 "rendered-hash" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
1425                                                 "rendered-html" => ["type" => "mediumtext", "comment" => "item.body converted to html"],
1426                                                 "object-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams object type"],
1427                                                 "object" => ["type" => "text", "comment" => "JSON encoded object structure unless it is an implied object (normal post)"],
1428                                                 "target-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams target type if applicable (URI)"],
1429                                                 "target" => ["type" => "text", "comment" => "JSON encoded target structure if used"],
1430                                                 "plink" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "permalink or URL to a displayable copy of the message at its source"],
1431                                                 "verb" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams verb"],
1432                                                 ],
1433                                 "indexes" => [
1434                                                 "PRIMARY" => ["id"],
1435                                                 "uri-plink-hash" => ["UNIQUE", "uri-plink-hash"],
1436                                                 "uri" => ["uri(191)"],
1437                                                 ]
1438                                 ];
1439                 $database["item-delivery-data"] = [
1440                                 "comment" => "Delivery data for items",
1441                                 "fields" => [
1442                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
1443                                                 "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"],
1444                                                 "inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"],
1445                                                 ],
1446                                 "indexes" => [
1447                                                 "PRIMARY" => ["iid"],
1448                                                 ]
1449                                 ];
1450                 $database["locks"] = [
1451                                 "comment" => "",
1452                                 "fields" => [
1453                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1454                                                 "name" => ["type" => "varchar(128)", "not null" => "1", "default" => "", "comment" => ""],
1455                                                 "locked" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1456                                                 "pid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Process ID"],
1457                                                 "expires" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of cache expiration"],
1458                                 ],
1459                                 "indexes" => [
1460                                                 "PRIMARY" => ["id"],
1461                                                 "name_expires" => ["name", "expires"]
1462                                                 ]
1463                                 ];
1464                 $database["mail"] = [
1465                                 "comment" => "private messages",
1466                                 "fields" => [
1467                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1468                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1469                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this private message"],
1470                                                 "from-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "name of the sender"],
1471                                                 "from-photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "contact photo link of the sender"],
1472                                                 "from-url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "profile linke of the sender"],
1473                                                 "contact-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "relation" => ["contact" => "id"], "comment" => "contact.id"],
1474                                                 "convid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["conv" => "id"], "comment" => "conv.id"],
1475                                                 "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1476                                                 "body" => ["type" => "mediumtext", "comment" => ""],
1477                                                 "seen" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if message visited it is 1"],
1478                                                 "reply" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1479                                                 "replied" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1480                                                 "unknown" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if sender not in the contact table this is 1"],
1481                                                 "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1482                                                 "parent-uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1483                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "creation time of the private message"],
1484                                                 ],
1485                                 "indexes" => [
1486                                                 "PRIMARY" => ["id"],
1487                                                 "uid_seen" => ["uid", "seen"],
1488                                                 "convid" => ["convid"],
1489                                                 "uri" => ["uri(64)"],
1490                                                 "parent-uri" => ["parent-uri(64)"],
1491                                                 "contactid" => ["contact-id(32)"],
1492                                                 ]
1493                                 ];
1494                 $database["mailacct"] = [
1495                                 "comment" => "Mail account data for fetching mails",
1496                                 "fields" => [
1497                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1498                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1499                                                 "server" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1500                                                 "port" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1501                                                 "ssltype" => ["type" => "varchar(16)", "not null" => "1", "default" => "", "comment" => ""],
1502                                                 "mailbox" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1503                                                 "user" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1504                                                 "pass" => ["type" => "text", "comment" => ""],
1505                                                 "reply_to" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1506                                                 "action" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1507                                                 "movetofolder" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1508                                                 "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1509                                                 "last_check" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1510                                                 ],
1511                                 "indexes" => [
1512                                                 "PRIMARY" => ["id"],
1513                                                 ]
1514                                 ];
1515                 $database["manage"] = [
1516                                 "comment" => "table of accounts that can manage each other",
1517                                 "fields" => [
1518                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1519                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1520                                                 "mid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1521                                                 ],
1522                                 "indexes" => [
1523                                                 "PRIMARY" => ["id"],
1524                                                 "uid_mid" => ["UNIQUE", "uid","mid"],
1525                                                 ]
1526                                 ];
1527                 $database["notify"] = [
1528                                 "comment" => "notifications",
1529                                 "fields" => [
1530                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1531                                                 "hash" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => ""],
1532                                                 "type" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1533                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1534                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1535                                                 "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1536                                                 "date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1537                                                 "msg" => ["type" => "mediumtext", "comment" => ""],
1538                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1539                                                 "link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1540                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => "item.id"],
1541                                                 "parent" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => ""],
1542                                                 "seen" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1543                                                 "verb" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => ""],
1544                                                 "otype" => ["type" => "varchar(10)", "not null" => "1", "default" => "", "comment" => ""],
1545                                                 "name_cache" => ["type" => "tinytext", "comment" => "Cached bbcode parsing of name"],
1546                                                 "msg_cache" => ["type" => "mediumtext", "comment" => "Cached bbcode parsing of msg"]
1547                                                 ],
1548                                 "indexes" => [
1549                                                 "PRIMARY" => ["id"],
1550                                                 "hash_uid" => ["hash", "uid"],
1551                                                 "seen_uid_date" => ["seen", "uid", "date"],
1552                                                 "uid_date" => ["uid", "date"],
1553                                                 "uid_type_link" => ["uid", "type", "link(190)"],
1554                                                 ]
1555                                 ];
1556                 $database["notify-threads"] = [
1557                                 "comment" => "",
1558                                 "fields" => [
1559                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1560                                                 "notify-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["notify" => "id"], "comment" => ""],
1561                                                 "master-parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => ""],
1562                                                 "parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1563                                                 "receiver-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1564                                                 ],
1565                                 "indexes" => [
1566                                                 "PRIMARY" => ["id"],
1567                                                 ]
1568                                 ];
1569                 $database["oembed"] = [
1570                                 "comment" => "cache for OEmbed queries",
1571                                 "fields" => [
1572                                                 "url" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "page url"],
1573                                                 "maxwidth" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "comment" => "Maximum width passed to Oembed"],
1574                                                 "content" => ["type" => "mediumtext", "comment" => "OEmbed data of the page"],
1575                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of creation"],
1576                                                 ],
1577                                 "indexes" => [
1578                                                 "PRIMARY" => ["url", "maxwidth"],
1579                                                 "created" => ["created"],
1580                                                 ]
1581                                 ];
1582                 $database["openwebauth-token"] = [
1583                                 "comment" => "Store OpenWebAuth token to verify contacts",
1584                                 "fields" => [
1585                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1586                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1587                                                 "type" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Verify type"],
1588                                                 "token" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A generated token"],
1589                                                 "meta" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1590                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of creation"],
1591                                         ],
1592                                 "indexes" => [
1593                                                 "PRIMARY" => ["id"],
1594                                                 ]
1595                                 ];
1596                 $database["parsed_url"] = [
1597                                 "comment" => "cache for 'parse_url' queries",
1598                                 "fields" => [
1599                                                 "url" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "page url"],
1600                                                 "guessing" => ["type" => "boolean", "not null" => "1", "default" => "0", "primary" => "1", "comment" => "is the 'guessing' mode active?"],
1601                                                 "oembed" => ["type" => "boolean", "not null" => "1", "default" => "0", "primary" => "1", "comment" => "is the data the result of oembed?"],
1602                                                 "content" => ["type" => "mediumtext", "comment" => "page data"],
1603                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of creation"],
1604                                                 ],
1605                                 "indexes" => [
1606                                                 "PRIMARY" => ["url", "guessing", "oembed"],
1607                                                 "created" => ["created"],
1608                                                 ]
1609                                 ];
1610                 $database["participation"] = [
1611                                 "comment" => "Storage for participation messages from Diaspora",
1612                                 "fields" => [
1613                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item" => "id"], "comment" => ""],
1614                                                 "server" => ["type" => "varchar(60)", "not null" => "1", "primary" => "1", "comment" => ""],
1615                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "relation" => ["contact" => "id"], "comment" => ""],
1616                                                 "fid" => ["type" => "int unsigned", "not null" => "1", "relation" => ["fcontact" => "id"], "comment" => ""],
1617                                                 ],
1618                                 "indexes" => [
1619                                                 "PRIMARY" => ["iid", "server"]
1620                                                 ]
1621                                 ];
1622                 $database["pconfig"] = [
1623                                 "comment" => "personal (per user) configuration storage",
1624                                 "fields" => [
1625                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
1626                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1627                                                 "cat" => ["type" => "varbinary(50)", "not null" => "1", "default" => "", "comment" => ""],
1628                                                 "k" => ["type" => "varbinary(100)", "not null" => "1", "default" => "", "comment" => ""],
1629                                                 "v" => ["type" => "mediumtext", "comment" => ""],
1630                                                 ],
1631                                 "indexes" => [
1632                                                 "PRIMARY" => ["id"],
1633                                                 "uid_cat_k" => ["UNIQUE", "uid", "cat", "k"],
1634                                                 ]
1635                                 ];
1636                 $database["permissionset"] = [
1637                                 "comment" => "",
1638                                 "fields" => [
1639                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1640                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id of this permission set"],
1641                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
1642                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
1643                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
1644                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
1645                                                 ],
1646                                 "indexes" => [
1647                                                 "PRIMARY" => ["id"],
1648                                                 "uid_allow_cid_allow_gid_deny_cid_deny_gid" => ["allow_cid(50)", "allow_gid(30)", "deny_cid(50)", "deny_gid(30)"],
1649                                                 ]
1650                                 ];
1651                 $database["photo"] = [
1652                                 "comment" => "photo storage",
1653                                 "fields" => [
1654                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1655                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1656                                                 "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
1657                                                 "guid" => ["type" => "char(16)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this photo"],
1658                                                 "resource-id" => ["type" => "char(32)", "not null" => "1", "default" => "", "comment" => ""],
1659                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "creation date"],
1660                                                 "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "last edited date"],
1661                                                 "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1662                                                 "desc" => ["type" => "text", "comment" => ""],
1663                                                 "album" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "The name of the album to which the photo belongs"],
1664                                                 "filename" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1665                                                 "type" => ["type" => "varchar(30)", "not null" => "1", "default" => "image/jpeg"],
1666                                                 "height" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1667                                                 "width" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1668                                                 "datasize" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1669                                                 "data" => ["type" => "mediumblob", "not null" => "1", "comment" => ""],
1670                                                 "scale" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1671                                                 "profile" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1672                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
1673                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
1674                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
1675                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
1676                                                 ],
1677                                 "indexes" => [
1678                                                 "PRIMARY" => ["id"],
1679                                                 "contactid" => ["contact-id"],
1680                                                 "uid_contactid" => ["uid", "contact-id"],
1681                                                 "uid_profile" => ["uid", "profile"],
1682                                                 "uid_album_scale_created" => ["uid", "album(32)", "scale", "created"],
1683                                                 "uid_album_resource-id_created" => ["uid", "album(32)", "resource-id", "created"],
1684                                                 "resource-id" => ["resource-id"],
1685                                                 ]
1686                                 ];
1687                 $database["poll"] = [
1688                                 "comment" => "Currently unused table for storing poll results",
1689                                 "fields" => [
1690                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
1691                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1692                                                 "q0" => ["type" => "text", "comment" => ""],
1693                                                 "q1" => ["type" => "text", "comment" => ""],
1694                                                 "q2" => ["type" => "text", "comment" => ""],
1695                                                 "q3" => ["type" => "text", "comment" => ""],
1696                                                 "q4" => ["type" => "text", "comment" => ""],
1697                                                 "q5" => ["type" => "text", "comment" => ""],
1698                                                 "q6" => ["type" => "text", "comment" => ""],
1699                                                 "q7" => ["type" => "text", "comment" => ""],
1700                                                 "q8" => ["type" => "text", "comment" => ""],
1701                                                 "q9" => ["type" => "text", "comment" => ""],
1702                                                 ],
1703                                 "indexes" => [
1704                                                 "PRIMARY" => ["id"],
1705                                                 "uid" => ["uid"],
1706                                                 ]
1707                                 ];
1708                 $database["poll_result"] = [
1709                                 "comment" => "data for polls - currently unused",
1710                                 "fields" => [
1711                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1712                                                 "poll_id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["poll" => "id"]],
1713                                                 "choice" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1714                                                 ],
1715                                 "indexes" => [
1716                                                 "PRIMARY" => ["id"],
1717                                                 "poll_id" => ["poll_id"],
1718                                                 ]
1719                                 ];
1720                 $database["process"] = [
1721                                 "comment" => "Currently running system processes",
1722                                 "fields" => [
1723                                                 "pid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "comment" => ""],
1724                                                 "command" => ["type" => "varbinary(32)", "not null" => "1", "default" => "", "comment" => ""],
1725                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1726                                                 ],
1727                                 "indexes" => [
1728                                                 "PRIMARY" => ["pid"],
1729                                                 "command" => ["command"],
1730                                                 ]
1731                                 ];
1732                 $database["profile"] = [
1733                                 "comment" => "user profiles data",
1734                                 "fields" => [
1735                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1736                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1737                                                 "profile-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name of the profile"],
1738                                                 "is-default" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Mark this profile as default profile"],
1739                                                 "hide-friends" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Hide friend list from viewers of this profile"],
1740                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1741                                                 "pdesc" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Title or description"],
1742                                                 "dob" => ["type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00", "comment" => "Day of birth"],
1743                                                 "address" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1744                                                 "locality" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1745                                                 "region" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1746                                                 "postal-code" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
1747                                                 "country-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1748                                                 "hometown" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1749                                                 "gender" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
1750                                                 "marital" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1751                                                 "with" => ["type" => "text", "comment" => ""],
1752                                                 "howlong" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1753                                                 "sexual" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1754                                                 "politic" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1755                                                 "religion" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1756                                                 "pub_keywords" => ["type" => "text", "comment" => ""],
1757                                                 "prv_keywords" => ["type" => "text", "comment" => ""],
1758                                                 "likes" => ["type" => "text", "comment" => ""],
1759                                                 "dislikes" => ["type" => "text", "comment" => ""],
1760                                                 "about" => ["type" => "text", "comment" => ""],
1761                                                 "summary" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1762                                                 "music" => ["type" => "text", "comment" => ""],
1763                                                 "book" => ["type" => "text", "comment" => ""],
1764                                                 "tv" => ["type" => "text", "comment" => ""],
1765                                                 "film" => ["type" => "text", "comment" => ""],
1766                                                 "interest" => ["type" => "text", "comment" => ""],
1767                                                 "romance" => ["type" => "text", "comment" => ""],
1768                                                 "work" => ["type" => "text", "comment" => ""],
1769                                                 "education" => ["type" => "text", "comment" => ""],
1770                                                 "contact" => ["type" => "text", "comment" => ""],
1771                                                 "homepage" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1772                                                 "xmpp" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1773                                                 "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1774                                                 "thumb" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1775                                                 "publish" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "publish default profile in local directory"],
1776                                                 "net-publish" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "publish profile in global directory"],
1777                                                 ],
1778                                 "indexes" => [
1779                                                 "PRIMARY" => ["id"],
1780                                                 "uid_is-default" => ["uid", "is-default"],
1781                                                 ]
1782                                 ];
1783                 $database["profile_check"] = [
1784                                 "comment" => "DFRN remote auth use",
1785                                 "fields" => [
1786                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1787                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1788                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
1789                                                 "dfrn_id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1790                                                 "sec" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1791                                                 "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1792                                                 ],
1793                                 "indexes" => [
1794                                                 "PRIMARY" => ["id"],
1795                                                 ]
1796                                 ];
1797                 $database["push_subscriber"] = [
1798                                 "comment" => "Used for OStatus: Contains feed subscribers",
1799                                 "fields" => [
1800                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1801                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1802                                                 "callback_url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1803                                                 "topic" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1804                                                 "nickname" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1805                                                 "push" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Retrial counter"],
1806                                                 "last_update" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last successful trial"],
1807                                                 "next_try" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Next retrial date"],
1808                                                 "renewed" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last subscription renewal"],
1809                                                 "secret" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1810                                                 ],
1811                                 "indexes" => [
1812                                                 "PRIMARY" => ["id"],
1813                                                 "next_try" => ["next_try"],
1814                                                 ]
1815                                 ];
1816                 $database["queue"] = [
1817                                 "comment" => "Queue for messages that couldn't be delivered",
1818                                 "fields" => [
1819                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1820                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Message receiver"],
1821                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Receiver's network"],
1822                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Unique GUID of the message"],
1823                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date, when the message was created"],
1824                                                 "last" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last trial"],
1825                                                 "next" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Next retrial date"],
1826                                                 "retrial" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Retrial counter"],
1827                                                 "content" => ["type" => "mediumtext", "comment" => ""],
1828                                                 "batch" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1829                                                 ],
1830                                 "indexes" => [
1831                                                 "PRIMARY" => ["id"],
1832                                                 "last" => ["last"],
1833                                                 "next" => ["next"],
1834                                                 ]
1835                                 ];
1836                 $database["register"] = [
1837                                 "comment" => "registrations requiring admin approval",
1838                                 "fields" => [
1839                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1840                                                 "hash" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1841                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1842                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1843                                                 "password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1844                                                 "language" => ["type" => "varchar(16)", "not null" => "1", "default" => "", "comment" => ""],
1845                                                 "note" => ["type" => "text", "comment" => ""],
1846                                                 ],
1847                                 "indexes" => [
1848                                                 "PRIMARY" => ["id"],
1849                                                 ]
1850                                 ];
1851                 $database["search"] = [
1852                                 "comment" => "",
1853                                 "fields" => [
1854                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1855                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1856                                                 "term" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1857                                                 ],
1858                                 "indexes" => [
1859                                                 "PRIMARY" => ["id"],
1860                                                 "uid" => ["uid"],
1861                                                 ]
1862                                 ];
1863                 $database["session"] = [
1864                                 "comment" => "web session storage",
1865                                 "fields" => [
1866                                                 "id" => ["type" => "bigint unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1867                                                 "sid" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => ""],
1868                                                 "data" => ["type" => "text", "comment" => ""],
1869                                                 "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1870                                                 ],
1871                                 "indexes" => [
1872                                                 "PRIMARY" => ["id"],
1873                                                 "sid" => ["sid(64)"],
1874                                                 "expire" => ["expire"],
1875                                                 ]
1876                                 ];
1877                 $database["sign"] = [
1878                                 "comment" => "Diaspora signatures",
1879                                 "fields" => [
1880                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1881                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => "item.id"],
1882                                                 "signed_text" => ["type" => "mediumtext", "comment" => ""],
1883                                                 "signature" => ["type" => "text", "comment" => ""],
1884                                                 "signer" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1885                                                 ],
1886                                 "indexes" => [
1887                                                 "PRIMARY" => ["id"],
1888                                                 "iid" => ["UNIQUE", "iid"],
1889                                                 ]
1890                                 ];
1891                 $database["term"] = [
1892                                 "comment" => "item taxonomy (categories, tags, etc.) table",
1893                                 "fields" => [
1894                                                 "tid" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
1895                                                 "oid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => ""],
1896                                                 "otype" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1897                                                 "type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1898                                                 "term" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1899                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1900                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1901                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1902                                                 "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1903                                                 "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1904                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1905                                                 ],
1906                                 "indexes" => [
1907                                                 "PRIMARY" => ["tid"],
1908                                                 "oid_otype_type_term" => ["oid","otype","type","term(32)"],
1909                                                 "uid_otype_type_term_global_created" => ["uid","otype","type","term(32)","global","created"],
1910                                                 "uid_otype_type_url" => ["uid","otype","type","url(64)"],
1911                                                 "guid" => ["guid(64)"],
1912                                                 ]
1913                                 ];
1914                 $database["thread"] = [
1915                                 "comment" => "Thread related data",
1916                                 "fields" => [
1917                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "comment" => "sequential ID"],
1918                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1919                                                 "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
1920                                                 "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Item owner"],
1921                                                 "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Item author"],
1922                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1923                                                 "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1924                                                 "commented" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1925                                                 "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1926                                                 "changed" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1927                                                 "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1928                                                 "private" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1929                                                 "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1930                                                 "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1931                                                 "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1932                                                 "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1933                                                 "ignored" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1934                                                 "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
1935                                                 "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
1936                                                 "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1937                                                 "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1938                                                 "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1939                                                 "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1940                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
1941                                                 "bookmark" => ["type" => "boolean", "comment" => ""],
1942                                                 ],
1943                                 "indexes" => [
1944                                                 "PRIMARY" => ["iid"],
1945                                                 "uid_network_commented" => ["uid","network","commented"],
1946                                                 "uid_network_created" => ["uid","network","created"],
1947                                                 "uid_contactid_commented" => ["uid","contact-id","commented"],
1948                                                 "uid_contactid_created" => ["uid","contact-id","created"],
1949                                                 "contactid" => ["contact-id"],
1950                                                 "ownerid" => ["owner-id"],
1951                                                 "authorid" => ["author-id"],
1952                                                 "uid_created" => ["uid","created"],
1953                                                 "uid_commented" => ["uid","commented"],
1954                                                 "uid_wall_created" => ["uid","wall","created"],
1955                                                 "private_wall_origin_commented" => ["private","wall","origin","commented"],
1956                                                 ]
1957                                 ];
1958                 $database["tokens"] = [
1959                                 "comment" => "OAuth usage",
1960                                 "fields" => [
1961                                                 "id" => ["type" => "varchar(40)", "not null" => "1", "primary" => "1", "comment" => ""],
1962                                                 "secret" => ["type" => "text", "comment" => ""],
1963                                                 "client_id" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => ["clients" => "client_id"]],
1964                                                 "expires" => ["type" => "int", "not null" => "1", "default" => "0", "comment" => ""],
1965                                                 "scope" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""],
1966                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1967                                                 ],
1968                                 "indexes" => [
1969                                                 "PRIMARY" => ["id"],
1970                                                 ]
1971                                 ];
1972                 $database["user"] = [
1973                                 "comment" => "The local users",
1974                                 "fields" => [
1975                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1976                                                 "parent-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "The parent user that has full control about this user"],
1977                                                 "guid" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this user"],
1978                                                 "username" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this user is known by"],
1979                                                 "password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "encrypted password"],
1980                                                 "legacy_password" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Is the password hash double-hashed?"],
1981                                                 "nickname" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "nick- and user name"],
1982                                                 "email" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "the users email address"],
1983                                                 "openid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1984                                                 "timezone" => ["type" => "varchar(128)", "not null" => "1", "default" => "", "comment" => "PHP-legal timezone"],
1985                                                 "language" => ["type" => "varchar(32)", "not null" => "1", "default" => "en", "comment" => "default language"],
1986                                                 "register_date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "timestamp of registration"],
1987                                                 "login_date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "timestamp of last login"],
1988                                                 "default-location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Default for item.location"],
1989                                                 "allow_location" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 allows to display the location"],
1990                                                 "theme" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "user theme preference"],
1991                                                 "pubkey" => ["type" => "text", "comment" => "RSA public key 4096 bit"],
1992                                                 "prvkey" => ["type" => "text", "comment" => "RSA private key 4096 bit"],
1993                                                 "spubkey" => ["type" => "text", "comment" => ""],
1994                                                 "sprvkey" => ["type" => "text", "comment" => ""],
1995                                                 "verified" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "user is verified through email"],
1996                                                 "blocked" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 for user is blocked"],
1997                                                 "blockwall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Prohibit contacts to post to the profile page of the user"],
1998                                                 "hidewall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Hide profile details from unkown viewers"],
1999                                                 "blocktags" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Prohibit contacts to tag the post of this user"],
2000                                                 "unkmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Permit unknown people to send private mails to this user"],
2001                                                 "cntunkmail" => ["type" => "int unsigned", "not null" => "1", "default" => "10", "comment" => ""],
2002                                                 "notify-flags" => ["type" => "smallint unsigned", "not null" => "1", "default" => "65535", "comment" => "email notification options"],
2003                                                 "page-flags" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "page/profile type"],
2004                                                 "account-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
2005                                                 "prvnets" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
2006                                                 "pwdreset" => ["type" => "varchar(255)", "comment" => "Password reset request token"],
2007                                                 "pwdreset_time" => ["type" => "datetime", "comment" => "Timestamp of the last password reset request"],
2008                                                 "maxreq" => ["type" => "int unsigned", "not null" => "1", "default" => "10", "comment" => ""],
2009                                                 "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
2010                                                 "account_removed" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if 1 the account is removed"],
2011                                                 "account_expired" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
2012                                                 "account_expires_on" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "timestamp when account expires and will be deleted"],
2013                                                 "expire_notification_sent" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "timestamp of last warning of account expiration"],
2014                                                 "def_gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
2015                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
2016                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
2017                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
2018                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
2019                                                 "openidserver" => ["type" => "text", "comment" => ""],
2020                                                 ],
2021                                 "indexes" => [
2022                                                 "PRIMARY" => ["uid"],
2023                                                 "nickname" => ["nickname(32)"],
2024                                                 ]
2025                                 ];
2026                 $database["userd"] = [
2027                                 "comment" => "Deleted usernames",
2028                                 "fields" => [
2029                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
2030                                                 "username" => ["type" => "varchar(255)", "not null" => "1", "comment" => ""],
2031                                                 ],
2032                                 "indexes" => [
2033                                                 "PRIMARY" => ["id"],
2034                                                 "username" => ["username(32)"],
2035                                                 ]
2036                                 ];
2037                 $database["user-item"] = [
2038                                 "comment" => "User specific item data",
2039                                 "fields" => [
2040                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
2041                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["user" => "uid"], "comment" => "User id"],
2042                                                 "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide an item from the user"],
2043                                                 ],
2044                                 "indexes" => [
2045                                                 "PRIMARY" => ["uid", "iid"],
2046                                                 ]
2047                                 ];
2048                 $database["worker-ipc"] = [
2049                                 "comment" => "Inter process communication between the frontend and the worker",
2050                                 "fields" => [
2051                                                 "key" => ["type" => "int", "not null" => "1", "primary" => "1", "comment" => ""],
2052                                                 "jobs" => ["type" => "boolean", "comment" => "Flag for outstanding jobs"],
2053                                                 ],
2054                                 "indexes" => [
2055                                                 "PRIMARY" => ["key"],
2056                                                 ],
2057                                 "engine" => "MEMORY",
2058                                 ];
2059
2060                 $database["workerqueue"] = [
2061                                 "comment" => "Background tasks queue entries",
2062                                 "fields" => [
2063                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Auto incremented worker task id"],
2064                                                 "parameter" => ["type" => "mediumblob", "comment" => "Task command"],
2065                                                 "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Task priority"],
2066                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Creation date"],
2067                                                 "pid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Process id of the worker"],
2068                                                 "executed" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Execution date"],
2069                                                 "done" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marked 1 when the task was done - will be deleted later"],
2070                                                 ],
2071                                 "indexes" => [
2072                                                 "PRIMARY" => ["id"],
2073                                                 "pid" => ["pid"],
2074                                                 "parameter" => ["parameter(64)"],
2075                                                 "priority_created" => ["priority", "created"],
2076                                                 "done_executed" => ["done", "executed"],
2077                                                 ]
2078                                 ];
2079
2080                 Addon::callHooks('dbstructure_definition', $database);
2081
2082                 return $database;
2083         }
2084 }