]> git.mxchange.org Git - friendica.git/blob - src/Database/DBStructure.php
8fb2afddb22214cdcac440a7683ad135972f718b
[friendica.git] / src / Database / DBStructure.php
1 <?php
2 /**
3  * @file src/Database/DBStructure.php
4  */
5 namespace Friendica\Database;
6
7 use Friendica\Core\Config;
8 use Friendica\Core\L10n;
9 use Friendica\Database\DBM;
10 use dba;
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::database_name()));
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(" ", "", $a->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_NORMAL);
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::clean_query(implode(",", $field_definition));
326                                                 $new_field_definition = dba::clean_query(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 = $database[$name]["fields"][$fieldname];
414
415                                         // Define the default collation if not given
416                                         if (!isset($parameters['Collation']) && !is_null($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::any_value_fallback($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 (!is_null($parameters["Collation"])) {
541                         $fieldstruct .= " COLLATE ".$parameters["Collation"];
542                 }
543
544                 if ($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 ($parameters["extra"] != "") {
556                         $fieldstruct .= " ".$parameters["extra"];
557                 }
558
559                 if (!is_null($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 (!is_null($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 (!is_null($structure["engine"])) {
593                         $engine = " ENGINE=" . $structure["engine"];
594                 }
595
596                 if (!is_null($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         public static function definition() {
688                 $database = [];
689
690                 $database["addon"] = [
691                                 "comment" => "registered addons",
692                                 "fields" => [
693                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
694                                                 "name" => ["type" => "varchar(50)", "not null" => "1", "default" => "", "comment" => "addon base (file)name"],
695                                                 "version" => ["type" => "varchar(50)", "not null" => "1", "default" => "", "comment" => "currently unused"],
696                                                 "installed" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "currently always 1"],
697                                                 "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "currently unused"],
698                                                 "timestamp" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "file timestamp to check for reloads"],
699                                                 "plugin_admin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = has admin config, 0 = has no admin config"],
700                                                 ],
701                                 "indexes" => [
702                                                 "PRIMARY" => ["id"],
703                                                 "name" => ["UNIQUE", "name"],
704                                                 ]
705                                 ];
706                 $database["attach"] = [
707                                 "comment" => "file attachments",
708                                 "fields" => [
709                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "generated index"],
710                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
711                                                 "hash" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "hash"],
712                                                 "filename" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "filename of original"],
713                                                 "filetype" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "mimetype"],
714                                                 "filesize" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "size in bytes"],
715                                                 "data" => ["type" => "longblob", "not null" => "1", "comment" => "file data"],
716                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "creation time"],
717                                                 "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "last edit time"],
718                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>"],
719                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
720                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
721                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
722                                                 ],
723                                 "indexes" => [
724                                                 "PRIMARY" => ["id"],
725                                                 ]
726                                 ];
727                 $database["auth_codes"] = [
728                                 "comment" => "OAuth usage",
729                                 "fields" => [
730                                                 "id" => ["type" => "varchar(40)", "not null" => "1", "primary" => "1", "comment" => ""],
731                                                 "client_id" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => ["clients" => "client_id"], "comment" => ""],
732                                                 "redirect_uri" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""],
733                                                 "expires" => ["type" => "int", "not null" => "1", "default" => "0", "comment" => ""],
734                                                 "scope" => ["type" => "varchar(250)", "not null" => "1", "default" => "", "comment" => ""],
735                                                 ],
736                                 "indexes" => [
737                                                 "PRIMARY" => ["id"],
738                                                 ]
739                                 ];
740                 $database["cache"] = [
741                                 "comment" => "Stores temporary data",
742                                 "fields" => [
743                                                 "k" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "cache key"],
744                                                 "v" => ["type" => "mediumtext", "comment" => "cached serialized value"],
745                                                 "expires" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of cache expiration"],
746                                                 "updated" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of cache insertion"],
747                                                 ],
748                                 "indexes" => [
749                                                 "PRIMARY" => ["k"],
750                                                 "k_expires" => ["k", "expires"],
751                                                 ]
752                                 ];
753                 $database["challenge"] = [
754                                 "comment" => "",
755                                 "fields" => [
756                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
757                                                 "challenge" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
758                                                 "dfrn-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
759                                                 "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
760                                                 "type" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
761                                                 "last_update" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
762                                                 ],
763                                 "indexes" => [
764                                                 "PRIMARY" => ["id"],
765                                                 ]
766                                 ];
767                 $database["clients"] = [
768                                 "comment" => "OAuth usage",
769                                 "fields" => [
770                                                 "client_id" => ["type" => "varchar(20)", "not null" => "1", "primary" => "1", "comment" => ""],
771                                                 "pw" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""],
772                                                 "redirect_uri" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""],
773                                                 "name" => ["type" => "text", "comment" => ""],
774                                                 "icon" => ["type" => "text", "comment" => ""],
775                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
776                                                 ],
777                                 "indexes" => [
778                                                 "PRIMARY" => ["client_id"],
779                                                 ]
780                                 ];
781                 $database["config"] = [
782                                 "comment" => "main configuration storage",
783                                 "fields" => [
784                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
785                                                 "cat" => ["type" => "varbinary(50)", "not null" => "1", "default" => "", "comment" => ""],
786                                                 "k" => ["type" => "varbinary(50)", "not null" => "1", "default" => "", "comment" => ""],
787                                                 "v" => ["type" => "mediumtext", "comment" => ""],
788                                                 ],
789                                 "indexes" => [
790                                                 "PRIMARY" => ["id"],
791                                                 "cat_k" => ["UNIQUE", "cat", "k"],
792                                                 ]
793                                 ];
794                 $database["contact"] = [
795                                 "comment" => "contact table",
796                                 "fields" => [
797                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
798                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
799                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
800                                                 "self" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 if the contact is the user him/her self"],
801                                                 "remote_self" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
802                                                 "rel" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "The kind of the relation between the user and the contact"],
803                                                 "duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
804                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network protocol of the contact"],
805                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this contact is known by"],
806                                                 "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Nick- and user name of the contact"],
807                                                 "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
808                                                 "about" => ["type" => "text", "comment" => ""],
809                                                 "keywords" => ["type" => "text", "comment" => "public keywords (interests) of the contact"],
810                                                 "gender" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
811                                                 "xmpp" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
812                                                 "attag" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
813                                                 "avatar" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
814                                                 "photo" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo of the contact"],
815                                                 "thumb" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo (thumb size)"],
816                                                 "micro" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo (micro size)"],
817                                                 "site-pubkey" => ["type" => "text", "comment" => ""],
818                                                 "issued-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
819                                                 "dfrn-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
820                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
821                                                 "nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
822                                                 "addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
823                                                 "alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
824                                                 "pubkey" => ["type" => "text", "comment" => "RSA public key 4096 bit"],
825                                                 "prvkey" => ["type" => "text", "comment" => "RSA private key 4096 bit"],
826                                                 "batch" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
827                                                 "request" => ["type" => "varchar(255)", "comment" => ""],
828                                                 "notify" => ["type" => "varchar(255)", "comment" => ""],
829                                                 "poll" => ["type" => "varchar(255)", "comment" => ""],
830                                                 "confirm" => ["type" => "varchar(255)", "comment" => ""],
831                                                 "poco" => ["type" => "varchar(255)", "comment" => ""],
832                                                 "aes_allow" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
833                                                 "ret-aes" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
834                                                 "usehub" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
835                                                 "subhub" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
836                                                 "hub-verify" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
837                                                 "last-update" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of the last try to update the contact info"],
838                                                 "success_update" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of the last successful contact update"],
839                                                 "failure_update" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of the last failed update"],
840                                                 "name-date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
841                                                 "uri-date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
842                                                 "avatar-date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
843                                                 "term-date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
844                                                 "last-item" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "date of the last post"],
845                                                 "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
846                                                 "blocked" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
847                                                 "readonly" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "posts of the contact are readonly"],
848                                                 "writable" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
849                                                 "forum" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a forum"],
850                                                 "prv" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a private group"],
851                                                 "contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => ""],
852                                                 "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
853                                                 "archive" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
854                                                 "pending" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
855                                                 "rating" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => ""],
856                                                 "reason" => ["type" => "text", "comment" => ""],
857                                                 "closeness" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "99", "comment" => ""],
858                                                 "info" => ["type" => "mediumtext", "comment" => ""],
859                                                 "profile-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
860                                                 "bdyear" => ["type" => "varchar(4)", "not null" => "1", "default" => "", "comment" => ""],
861                                                 "bd" => ["type" => "date", "not null" => "1", "default" => "0001-01-01", "comment" => ""],
862                                                 "notify_new_posts" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
863                                                 "fetch_further_information" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
864                                                 "ffi_keyword_blacklist" => ["type" => "text", "comment" => ""],
865                                                 ],
866                                 "indexes" => [
867                                                 "PRIMARY" => ["id"],
868                                                 "uid_name" => ["uid", "name(190)"],
869                                                 "self_uid" => ["self", "uid"],
870                                                 "alias_uid" => ["alias(32)", "uid"],
871                                                 "pending_uid" => ["pending", "uid"],
872                                                 "blocked_uid" => ["blocked", "uid"],
873                                                 "uid_rel_network_poll" => ["uid", "rel", "network", "poll(64)", "archive"],
874                                                 "uid_network_batch" => ["uid", "network", "batch(64)"],
875                                                 "addr_uid" => ["addr(32)", "uid"],
876                                                 "nurl_uid" => ["nurl(32)", "uid"],
877                                                 "nick_uid" => ["nick(32)", "uid"],
878                                                 "dfrn-id" => ["dfrn-id(64)"],
879                                                 "issued-id" => ["issued-id(64)"],
880                                                 ]
881                                 ];
882                 $database["conv"] = [
883                                 "comment" => "private messages",
884                                 "fields" => [
885                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
886                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this conversation"],
887                                                 "recips" => ["type" => "text", "comment" => "sender_handle;recipient_handle"],
888                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
889                                                 "creator" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "handle of creator"],
890                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "creation timestamp"],
891                                                 "updated" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "edited timestamp"],
892                                                 "subject" => ["type" => "text", "comment" => "subject of initial message"],
893                                                 ],
894                                 "indexes" => [
895                                                 "PRIMARY" => ["id"],
896                                                 "uid" => ["uid"],
897                                                 ]
898                                 ];
899                 $database["conversation"] = [
900                                 "comment" => "Raw data and structure information for messages",
901                                 "fields" => [
902                                                 "item-uri" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "URI of the item"],
903                                                 "reply-to-uri" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "URI to which this item is a reply"],
904                                                 "conversation-uri" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "GNU Social conversation URI"],
905                                                 "conversation-href" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "GNU Social conversation link"],
906                                                 "protocol" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "The protocol of the item"],
907                                                 "source" => ["type" => "mediumtext", "comment" => "Original source"],
908                                                 "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Receiving date"],
909                                                 ],
910                                 "indexes" => [
911                                                 "PRIMARY" => ["item-uri"],
912                                                 "conversation-uri" => ["conversation-uri"],
913                                                 "received" => ["received"],
914                                                 ]
915                                 ];
916                 $database["event"] = [
917                                 "comment" => "Events",
918                                 "fields" => [
919                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
920                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
921                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
922                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact_id (ID of the contact in contact table)"],
923                                                 "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
924                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "creation time"],
925                                                 "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "last edit time"],
926                                                 "start" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "event start time"],
927                                                 "finish" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "event end time"],
928                                                 "summary" => ["type" => "text", "comment" => "short description or title of the event"],
929                                                 "desc" => ["type" => "text", "comment" => "event description"],
930                                                 "location" => ["type" => "text", "comment" => "event location"],
931                                                 "type" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => "event or birthday"],
932                                                 "nofinish" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if event does have no end this is 1"],
933                                                 "adjust" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "adjust to timezone of the recipient (0 or 1)"],
934                                                 "ignore" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "0 or 1"],
935                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
936                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
937                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
938                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
939                                                 ],
940                                 "indexes" => [
941                                                 "PRIMARY" => ["id"],
942                                                 "uid_start" => ["uid", "start"],
943                                                 ]
944                                 ];
945                 $database["fcontact"] = [
946                                 "comment" => "Diaspora compatible contacts - used in the Diaspora implementation",
947                                 "fields" => [
948                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
949                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "unique id"],
950                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
951                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
952                                                 "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
953                                                 "request" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
954                                                 "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
955                                                 "addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
956                                                 "batch" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
957                                                 "notify" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
958                                                 "poll" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
959                                                 "confirm" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
960                                                 "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
961                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
962                                                 "alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
963                                                 "pubkey" => ["type" => "text", "comment" => ""],
964                                                 "updated" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
965                                                 ],
966                                 "indexes" => [
967                                                 "PRIMARY" => ["id"],
968                                                 "addr" => ["addr(32)"],
969                                                 "url" => ["UNIQUE", "url(190)"],
970                                                 ]
971                                 ];
972                 $database["fsuggest"] = [
973                                 "comment" => "friend suggestion stuff",
974                                 "fields" => [
975                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
976                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
977                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
978                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
979                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
980                                                 "request" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
981                                                 "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
982                                                 "note" => ["type" => "text", "comment" => ""],
983                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
984                                                 ],
985                                 "indexes" => [
986                                                 "PRIMARY" => ["id"],
987                                                 ]
988                                 ];
989                 $database["gcign"] = [
990                                 "comment" => "contacts ignored by friend suggestions",
991                                 "fields" => [
992                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
993                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Local User id"],
994                                                 "gcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => "gcontact.id of ignored contact"],
995                                                 ],
996                                 "indexes" => [
997                                                 "PRIMARY" => ["id"],
998                                                 "uid" => ["uid"],
999                                                 "gcid" => ["gcid"],
1000                                                 ]
1001                                 ];
1002                 $database["gcontact"] = [
1003                                 "comment" => "global contacts",
1004                                 "fields" => [
1005                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1006                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this contact is known by"],
1007                                                 "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Nick- and user name of the contact"],
1008                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the contacts profile page"],
1009                                                 "nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1010                                                 "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the profile photo"],
1011                                                 "connect" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1012                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1013                                                 "updated" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1014                                                 "last_contact" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1015                                                 "last_failure" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1016                                                 "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1017                                                 "about" => ["type" => "text", "comment" => ""],
1018                                                 "keywords" => ["type" => "text", "comment" => "puplic keywords (interests)"],
1019                                                 "gender" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
1020                                                 "birthday" => ["type" => "varchar(32)", "not null" => "1", "default" => "0001-01-01", "comment" => ""],
1021                                                 "community" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 if contact is forum account"],
1022                                                 "contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "-1", "comment" => ""],
1023                                                 "hide" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = should be hidden from search"],
1024                                                 "nsfw" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = contact posts nsfw content"],
1025                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "social network protocol"],
1026                                                 "addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1027                                                 "notify" => ["type" => "varchar(255)", "comment" => ""],
1028                                                 "alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1029                                                 "generation" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1030                                                 "server_url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "baseurl of the contacts server"],
1031                                                 ],
1032                                 "indexes" => [
1033                                                 "PRIMARY" => ["id"],
1034                                                 "nurl" => ["UNIQUE", "nurl(190)"],
1035                                                 "name" => ["name(64)"],
1036                                                 "nick" => ["nick(32)"],
1037                                                 "addr" => ["addr(64)"],
1038                                                 "hide_network_updated" => ["hide", "network", "updated"],
1039                                                 "updated" => ["updated"],
1040                                                 ]
1041                                 ];
1042                 $database["glink"] = [
1043                                 "comment" => "'friends of friends' linkages derived from poco",
1044                                 "fields" => [
1045                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1046                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
1047                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1048                                                 "gcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => ""],
1049                                                 "zcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => ""],
1050                                                 "updated" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1051                                                 ],
1052                                 "indexes" => [
1053                                                 "PRIMARY" => ["id"],
1054                                                 "cid_uid_gcid_zcid" => ["UNIQUE", "cid","uid","gcid","zcid"],
1055                                                 "gcid" => ["gcid"],
1056                                                 ]
1057                                 ];
1058                 $database["group"] = [
1059                                 "comment" => "privacy groups, group info",
1060                                 "fields" => [
1061                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1062                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1063                                                 "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 indicates the member list is not private"],
1064                                                 "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 indicates the group has been deleted"],
1065                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "human readable name of group"],
1066                                                 ],
1067                                 "indexes" => [
1068                                                 "PRIMARY" => ["id"],
1069                                                 "uid" => ["uid"],
1070                                                 ]
1071                                 ];
1072                 $database["group_member"] = [
1073                                 "comment" => "privacy groups, member info",
1074                                 "fields" => [
1075                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1076                                                 "gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["group" => "id"], "comment" => "groups.id of the associated group"],
1077                                                 "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id of the member assigned to the associated group"],
1078                                                 ],
1079                                 "indexes" => [
1080                                                 "PRIMARY" => ["id"],
1081                                                 "contactid" => ["contact-id"],
1082                                                 "gid_contactid" => ["UNIQUE", "gid", "contact-id"],
1083                                                 ]
1084                                 ];
1085                 $database["gserver"] = [
1086                                 "comment" => "Global servers",
1087                                 "fields" => [
1088                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1089                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1090                                                 "nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1091                                                 "version" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1092                                                 "site_name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1093                                                 "info" => ["type" => "text", "comment" => ""],
1094                                                 "register_policy" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => ""],
1095                                                 "registered-users" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Number of registered users"],
1096                                                 "poco" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1097                                                 "noscrape" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1098                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
1099                                                 "platform" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1100                                                 "relay-subscribe" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Has the server subscribed to the relay system"],
1101                                                 "relay-scope" => ["type" => "varchar(10)", "not null" => "1", "default" => "", "comment" => "The scope of messages that the server wants to get"],
1102                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1103                                                 "last_poco_query" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1104                                                 "last_contact" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1105                                                 "last_failure" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
1106                                                 ],
1107                                 "indexes" => [
1108                                                 "PRIMARY" => ["id"],
1109                                                 "nurl" => ["UNIQUE", "nurl(190)"],
1110                                                 ]
1111                                 ];
1112                 $database["gserver-tag"] = [
1113                                 "comment" => "Tags that the server has subscribed",
1114                                 "fields" => [
1115                                                 "gserver-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gserver" => "id"], "primary" => "1", "comment" => "The id of the gserver"],
1116                                                 "tag" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "primary" => "1", "comment" => "Tag that the server has subscribed"],
1117                                                 ],
1118                                 "indexes" => [
1119                                                 "PRIMARY" => ["gserver-id", "tag"],
1120                                                 "tag" => ["tag"],
1121                                                 ]
1122                                 ];
1123                 $database["hook"] = [
1124                                 "comment" => "addon hook registry",
1125                                 "fields" => [
1126                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1127                                                 "hook" => ["type" => "varbinary(100)", "not null" => "1", "default" => "", "comment" => "name of hook"],
1128                                                 "file" => ["type" => "varbinary(200)", "not null" => "1", "default" => "", "comment" => "relative filename of hook handler"],
1129                                                 "function" => ["type" => "varbinary(200)", "not null" => "1", "default" => "", "comment" => "function name of hook handler"],
1130                                                 "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"],
1131                                                 ],
1132                                 "indexes" => [
1133                                                 "PRIMARY" => ["id"],
1134                                                 "hook_file_function" => ["UNIQUE", "hook", "file", "function"],
1135                                                 ]
1136                                 ];
1137                 $database["intro"] = [
1138                                 "comment" => "",
1139                                 "fields" => [
1140                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1141                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1142                                                 "fid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["fcontact" => "id"], "comment" => ""],
1143                                                 "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
1144                                                 "knowyou" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1145                                                 "duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1146                                                 "note" => ["type" => "text", "comment" => ""],
1147                                                 "hash" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1148                                                 "datetime" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1149                                                 "blocked" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
1150                                                 "ignore" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1151                                                 ],
1152                                 "indexes" => [
1153                                                 "PRIMARY" => ["id"],
1154                                                 ]
1155                                 ];
1156                 $database["item"] = [
1157                                 "comment" => "Structure for all posts",
1158                                 "fields" => [
1159                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
1160                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this item"],
1161                                                 "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1162                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
1163                                                 "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
1164                                                 "type" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""],
1165                                                 "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "This item was posted to the wall of uid"],
1166                                                 "gravity" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1167                                                 "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"],
1168                                                 "parent-uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "uri of the parent to this item"],
1169                                                 "extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1170                                                 "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"],
1171                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Creation timestamp."],
1172                                                 "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last edit (default is created)"],
1173                                                 "commented" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last comment/reply to this item"],
1174                                                 "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime"],
1175                                                 "changed" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date that something in the conversation changed, indicating clients should fetch the conversation again"],
1176                                                 "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"],
1177                                                 "owner-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name of the owner of this item"],
1178                                                 "owner-link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the profile page of the owner of this item"],
1179                                                 "owner-avatar" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the avatar picture of the owner of this item"],
1180                                                 "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"],
1181                                                 "author-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name of the author of this item"],
1182                                                 "author-link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the profile page of the author of this item"],
1183                                                 "author-avatar" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the avatar picture of the author of this item"],
1184                                                 "icid" => ["type" => "int unsigned", "relation" => ["item-content" => "id"], "comment" => "Id of the item-content table entry that contains the whole item content"],
1185                                                 "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "item title"],
1186                                                 "content-warning" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1187                                                 "body" => ["type" => "mediumtext", "comment" => "item body content"],
1188                                                 "app" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "application which generated this item"],
1189                                                 "verb" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams verb"],
1190                                                 "object-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams object type"],
1191                                                 "object" => ["type" => "text", "comment" => "JSON encoded object structure unless it is an implied object (normal post)"],
1192                                                 "target-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams target type if applicable (URI)"],
1193                                                 "target" => ["type" => "text", "comment" => "JSON encoded target structure if used"],
1194                                                 "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"],
1195                                                 "plink" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "permalink or URL to a displayable copy of the message at its source"],
1196                                                 "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"],
1197                                                 "event-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
1198                                                 "tag" => ["type" => "mediumtext", "comment" => ""],
1199                                                 "attach" => ["type" => "mediumtext", "comment" => "JSON structure representing attachments to this item"],
1200                                                 "inform" => ["type" => "mediumtext", "comment" => ""],
1201                                                 "file" => ["type" => "mediumtext", "comment" => ""],
1202                                                 "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "text location where this item originated"],
1203                                                 "coord" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "longitude/latitude pair representing location where this item originated"],
1204                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
1205                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
1206                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
1207                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
1208                                                 "private" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "distribution is restricted"],
1209                                                 "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1210                                                 "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1211                                                 "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1212                                                 "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been favourited"],
1213                                                 "bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been bookmarked"],
1214                                                 "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
1215                                                 "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been deleted"],
1216                                                 "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item originated at this site"],
1217                                                 "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1218                                                 "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"],
1219                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"],
1220                                                 "rendered-hash" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
1221                                                 "rendered-html" => ["type" => "mediumtext", "comment" => "item.body converted to html"],
1222                                                 "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1223                                                 ],
1224                                 "indexes" => [
1225                                                 "PRIMARY" => ["id"],
1226                                                 "guid" => ["guid(191)"],
1227                                                 "uri" => ["uri(191)"],
1228                                                 "parent" => ["parent"],
1229                                                 "parent-uri" => ["parent-uri(191)"],
1230                                                 "extid" => ["extid(191)"],
1231                                                 "uid_id" => ["uid","id"],
1232                                                 "uid_contactid_id" => ["uid","contact-id","id"],
1233                                                 "uid_created" => ["uid","created"],
1234                                                 "uid_commented" => ["uid","commented"],
1235                                                 "uid_unseen_contactid" => ["uid","unseen","contact-id"],
1236                                                 "uid_network_received" => ["uid","network","received"],
1237                                                 "uid_network_commented" => ["uid","network","commented"],
1238                                                 "uid_thrparent" => ["uid","thr-parent(190)"],
1239                                                 "uid_parenturi" => ["uid","parent-uri(190)"],
1240                                                 "uid_contactid_created" => ["uid","contact-id","created"],
1241                                                 "authorid_created" => ["author-id","created"],
1242                                                 "ownerid" => ["owner-id"],
1243                                                 "uid_uri" => ["uid", "uri(190)"],
1244                                                 "resource-id" => ["resource-id"],
1245                                                 "contactid_allowcid_allowpid_denycid_denygid" => ["contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"], //
1246                                                 "uid_type_changed" => ["uid","type","changed"],
1247                                                 "contactid_verb" => ["contact-id","verb"],
1248                                                 "deleted_changed" => ["deleted","changed"],
1249                                                 "uid_wall_changed" => ["uid","wall","changed"],
1250                                                 "uid_eventid" => ["uid","event-id"],
1251                                                 "icid" => ["icid"],
1252                                                 ]
1253                                 ];
1254                 $database["item-content"] = [
1255                                 "comment" => "Content for all posts",
1256                                 "fields" => [
1257                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
1258                                                 "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1259                                                 "uri-plink-hash" => ["type" => "char(80)", "not null" => "1", "default" => "", "comment" => "SHA-1 hash from uri and plink"],
1260                                                 "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "item title"],
1261                                                 "content-warning" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1262                                                 "body" => ["type" => "mediumtext", "comment" => "item body content"],
1263                                                 "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "text location where this item originated"],
1264                                                 "coord" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "longitude/latitude pair representing location where this item originated"],
1265                                                 "app" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "application which generated this item"],
1266                                                 "rendered-hash" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
1267                                                 "rendered-html" => ["type" => "mediumtext", "comment" => "item.body converted to html"],
1268                                                 "object-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams object type"],
1269                                                 "object" => ["type" => "text", "comment" => "JSON encoded object structure unless it is an implied object (normal post)"],
1270                                                 "target-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams target type if applicable (URI)"],
1271                                                 "target" => ["type" => "text", "comment" => "JSON encoded target structure if used"],
1272                                                 "plink" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "permalink or URL to a displayable copy of the message at its source"],
1273                                                 "verb" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams verb"],
1274                                                 ],
1275                                 "indexes" => [
1276                                                 "PRIMARY" => ["id"],
1277                                                 "uri-plink-hash" => ["UNIQUE", "uri-plink-hash"],
1278                                                 "uri" => ["uri(191)"],
1279                                                 ]
1280                                 ];
1281                 $database["locks"] = [
1282                                 "comment" => "",
1283                                 "fields" => [
1284                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1285                                                 "name" => ["type" => "varchar(128)", "not null" => "1", "default" => "", "comment" => ""],
1286                                                 "locked" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1287                                                 "pid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Process ID"],
1288                                                 ],
1289                                 "indexes" => [
1290                                                 "PRIMARY" => ["id"],
1291                                                 ]
1292                                 ];
1293                 $database["mail"] = [
1294                                 "comment" => "private messages",
1295                                 "fields" => [
1296                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1297                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1298                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this private message"],
1299                                                 "from-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "name of the sender"],
1300                                                 "from-photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "contact photo link of the sender"],
1301                                                 "from-url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "profile linke of the sender"],
1302                                                 "contact-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "relation" => ["contact" => "id"], "comment" => "contact.id"],
1303                                                 "convid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["conv" => "id"], "comment" => "conv.id"],
1304                                                 "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1305                                                 "body" => ["type" => "mediumtext", "comment" => ""],
1306                                                 "seen" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if message visited it is 1"],
1307                                                 "reply" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1308                                                 "replied" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1309                                                 "unknown" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if sender not in the contact table this is 1"],
1310                                                 "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1311                                                 "parent-uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1312                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "creation time of the private message"],
1313                                                 ],
1314                                 "indexes" => [
1315                                                 "PRIMARY" => ["id"],
1316                                                 "uid_seen" => ["uid", "seen"],
1317                                                 "convid" => ["convid"],
1318                                                 "uri" => ["uri(64)"],
1319                                                 "parent-uri" => ["parent-uri(64)"],
1320                                                 "contactid" => ["contact-id(32)"],
1321                                                 ]
1322                                 ];
1323                 $database["mailacct"] = [
1324                                 "comment" => "Mail account data for fetching mails",
1325                                 "fields" => [
1326                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1327                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1328                                                 "server" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1329                                                 "port" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1330                                                 "ssltype" => ["type" => "varchar(16)", "not null" => "1", "default" => "", "comment" => ""],
1331                                                 "mailbox" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1332                                                 "user" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1333                                                 "pass" => ["type" => "text", "comment" => ""],
1334                                                 "reply_to" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1335                                                 "action" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1336                                                 "movetofolder" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1337                                                 "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1338                                                 "last_check" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1339                                                 ],
1340                                 "indexes" => [
1341                                                 "PRIMARY" => ["id"],
1342                                                 ]
1343                                 ];
1344                 $database["manage"] = [
1345                                 "comment" => "table of accounts that can manage each other",
1346                                 "fields" => [
1347                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1348                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1349                                                 "mid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1350                                                 ],
1351                                 "indexes" => [
1352                                                 "PRIMARY" => ["id"],
1353                                                 "uid_mid" => ["UNIQUE", "uid","mid"],
1354                                                 ]
1355                                 ];
1356                 $database["notify"] = [
1357                                 "comment" => "notifications",
1358                                 "fields" => [
1359                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1360                                                 "hash" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => ""],
1361                                                 "type" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1362                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1363                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1364                                                 "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1365                                                 "date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1366                                                 "msg" => ["type" => "mediumtext", "comment" => ""],
1367                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1368                                                 "link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1369                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => "item.id"],
1370                                                 "parent" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => ""],
1371                                                 "seen" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1372                                                 "verb" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => ""],
1373                                                 "otype" => ["type" => "varchar(10)", "not null" => "1", "default" => "", "comment" => ""],
1374                                                 "name_cache" => ["type" => "tinytext", "comment" => "Cached bbcode parsing of name"],
1375                                                 "msg_cache" => ["type" => "mediumtext", "comment" => "Cached bbcode parsing of msg"]
1376                                                 ],
1377                                 "indexes" => [
1378                                                 "PRIMARY" => ["id"],
1379                                                 "hash_uid" => ["hash", "uid"],
1380                                                 "seen_uid_date" => ["seen", "uid", "date"],
1381                                                 "uid_date" => ["uid", "date"],
1382                                                 "uid_type_link" => ["uid", "type", "link(190)"],
1383                                                 ]
1384                                 ];
1385                 $database["notify-threads"] = [
1386                                 "comment" => "",
1387                                 "fields" => [
1388                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1389                                                 "notify-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["notify" => "id"], "comment" => ""],
1390                                                 "master-parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => ""],
1391                                                 "parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1392                                                 "receiver-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1393                                                 ],
1394                                 "indexes" => [
1395                                                 "PRIMARY" => ["id"],
1396                                                 ]
1397                                 ];
1398                 $database["oembed"] = [
1399                                 "comment" => "cache for OEmbed queries",
1400                                 "fields" => [
1401                                                 "url" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "page url"],
1402                                                 "maxwidth" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "comment" => "Maximum width passed to Oembed"],
1403                                                 "content" => ["type" => "mediumtext", "comment" => "OEmbed data of the page"],
1404                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of creation"],
1405                                                 ],
1406                                 "indexes" => [
1407                                                 "PRIMARY" => ["url", "maxwidth"],
1408                                                 "created" => ["created"],
1409                                                 ]
1410                                 ];
1411                 $database["openwebauth-token"] = [
1412                                 "comment" => "Store OpenWebAuth token to verify contacts",
1413                                 "fields" => [
1414                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1415                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1416                                                 "type" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Verify type"],
1417                                                 "token" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A generated token"],
1418                                                 "meta" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1419                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of creation"],
1420                                         ],
1421                                 "indexes" => [
1422                                                 "PRIMARY" => ["id"],
1423                                                 ]
1424                                 ];
1425                 $database["parsed_url"] = [
1426                                 "comment" => "cache for 'parse_url' queries",
1427                                 "fields" => [
1428                                                 "url" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "page url"],
1429                                                 "guessing" => ["type" => "boolean", "not null" => "1", "default" => "0", "primary" => "1", "comment" => "is the 'guessing' mode active?"],
1430                                                 "oembed" => ["type" => "boolean", "not null" => "1", "default" => "0", "primary" => "1", "comment" => "is the data the result of oembed?"],
1431                                                 "content" => ["type" => "mediumtext", "comment" => "page data"],
1432                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of creation"],
1433                                                 ],
1434                                 "indexes" => [
1435                                                 "PRIMARY" => ["url", "guessing", "oembed"],
1436                                                 "created" => ["created"],
1437                                                 ]
1438                                 ];
1439                 $database["participation"] = [
1440                                 "comment" => "Storage for participation messages from Diaspora",
1441                                 "fields" => [
1442                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item" => "id"], "comment" => ""],
1443                                                 "server" => ["type" => "varchar(60)", "not null" => "1", "primary" => "1", "comment" => ""],
1444                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "relation" => ["contact" => "id"], "comment" => ""],
1445                                                 "fid" => ["type" => "int unsigned", "not null" => "1", "relation" => ["fcontact" => "id"], "comment" => ""],
1446                                                 ],
1447                                 "indexes" => [
1448                                                 "PRIMARY" => ["iid", "server"]
1449                                                 ]
1450                                 ];
1451                 $database["pconfig"] = [
1452                                 "comment" => "personal (per user) configuration storage",
1453                                 "fields" => [
1454                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
1455                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1456                                                 "cat" => ["type" => "varbinary(50)", "not null" => "1", "default" => "", "comment" => ""],
1457                                                 "k" => ["type" => "varbinary(100)", "not null" => "1", "default" => "", "comment" => ""],
1458                                                 "v" => ["type" => "mediumtext", "comment" => ""],
1459                                                 ],
1460                                 "indexes" => [
1461                                                 "PRIMARY" => ["id"],
1462                                                 "uid_cat_k" => ["UNIQUE", "uid", "cat", "k"],
1463                                                 ]
1464                                 ];
1465                 $database["photo"] = [
1466                                 "comment" => "photo storage",
1467                                 "fields" => [
1468                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1469                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1470                                                 "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
1471                                                 "guid" => ["type" => "char(16)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this photo"],
1472                                                 "resource-id" => ["type" => "char(32)", "not null" => "1", "default" => "", "comment" => ""],
1473                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "creation date"],
1474                                                 "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "last edited date"],
1475                                                 "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1476                                                 "desc" => ["type" => "text", "comment" => ""],
1477                                                 "album" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "The name of the album to which the photo belongs"],
1478                                                 "filename" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1479                                                 "type" => ["type" => "varchar(30)", "not null" => "1", "default" => "image/jpeg"],
1480                                                 "height" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1481                                                 "width" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1482                                                 "datasize" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1483                                                 "data" => ["type" => "mediumblob", "not null" => "1", "comment" => ""],
1484                                                 "scale" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1485                                                 "profile" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1486                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
1487                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
1488                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
1489                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
1490                                                 ],
1491                                 "indexes" => [
1492                                                 "PRIMARY" => ["id"],
1493                                                 "contactid" => ["contact-id"],
1494                                                 "uid_contactid" => ["uid", "contact-id"],
1495                                                 "uid_profile" => ["uid", "profile"],
1496                                                 "uid_album_scale_created" => ["uid", "album(32)", "scale", "created"],
1497                                                 "uid_album_resource-id_created" => ["uid", "album(32)", "resource-id", "created"],
1498                                                 "resource-id" => ["resource-id"],
1499                                                 ]
1500                                 ];
1501                 $database["poll"] = [
1502                                 "comment" => "Currently unused table for storing poll results",
1503                                 "fields" => [
1504                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
1505                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1506                                                 "q0" => ["type" => "text", "comment" => ""],
1507                                                 "q1" => ["type" => "text", "comment" => ""],
1508                                                 "q2" => ["type" => "text", "comment" => ""],
1509                                                 "q3" => ["type" => "text", "comment" => ""],
1510                                                 "q4" => ["type" => "text", "comment" => ""],
1511                                                 "q5" => ["type" => "text", "comment" => ""],
1512                                                 "q6" => ["type" => "text", "comment" => ""],
1513                                                 "q7" => ["type" => "text", "comment" => ""],
1514                                                 "q8" => ["type" => "text", "comment" => ""],
1515                                                 "q9" => ["type" => "text", "comment" => ""],
1516                                                 ],
1517                                 "indexes" => [
1518                                                 "PRIMARY" => ["id"],
1519                                                 "uid" => ["uid"],
1520                                                 ]
1521                                 ];
1522                 $database["poll_result"] = [
1523                                 "comment" => "data for polls - currently unused",
1524                                 "fields" => [
1525                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1526                                                 "poll_id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["poll" => "id"]],
1527                                                 "choice" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1528                                                 ],
1529                                 "indexes" => [
1530                                                 "PRIMARY" => ["id"],
1531                                                 "poll_id" => ["poll_id"],
1532                                                 ]
1533                                 ];
1534                 $database["process"] = [
1535                                 "comment" => "Currently running system processes",
1536                                 "fields" => [
1537                                                 "pid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "comment" => ""],
1538                                                 "command" => ["type" => "varbinary(32)", "not null" => "1", "default" => "", "comment" => ""],
1539                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1540                                                 ],
1541                                 "indexes" => [
1542                                                 "PRIMARY" => ["pid"],
1543                                                 "command" => ["command"],
1544                                                 ]
1545                                 ];
1546                 $database["profile"] = [
1547                                 "comment" => "user profiles data",
1548                                 "fields" => [
1549                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1550                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"],
1551                                                 "profile-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name of the profile"],
1552                                                 "is-default" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Mark this profile as default profile"],
1553                                                 "hide-friends" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Hide friend list from viewers of this profile"],
1554                                                 "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1555                                                 "pdesc" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Title or description"],
1556                                                 "dob" => ["type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00", "comment" => "Day of birth"],
1557                                                 "address" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1558                                                 "locality" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1559                                                 "region" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1560                                                 "postal-code" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
1561                                                 "country-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1562                                                 "hometown" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1563                                                 "gender" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
1564                                                 "marital" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1565                                                 "with" => ["type" => "text", "comment" => ""],
1566                                                 "howlong" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1567                                                 "sexual" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1568                                                 "politic" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1569                                                 "religion" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1570                                                 "pub_keywords" => ["type" => "text", "comment" => ""],
1571                                                 "prv_keywords" => ["type" => "text", "comment" => ""],
1572                                                 "likes" => ["type" => "text", "comment" => ""],
1573                                                 "dislikes" => ["type" => "text", "comment" => ""],
1574                                                 "about" => ["type" => "text", "comment" => ""],
1575                                                 "summary" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1576                                                 "music" => ["type" => "text", "comment" => ""],
1577                                                 "book" => ["type" => "text", "comment" => ""],
1578                                                 "tv" => ["type" => "text", "comment" => ""],
1579                                                 "film" => ["type" => "text", "comment" => ""],
1580                                                 "interest" => ["type" => "text", "comment" => ""],
1581                                                 "romance" => ["type" => "text", "comment" => ""],
1582                                                 "work" => ["type" => "text", "comment" => ""],
1583                                                 "education" => ["type" => "text", "comment" => ""],
1584                                                 "contact" => ["type" => "text", "comment" => ""],
1585                                                 "homepage" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1586                                                 "xmpp" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1587                                                 "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1588                                                 "thumb" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1589                                                 "publish" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "publish default profile in local directory"],
1590                                                 "net-publish" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "publish profile in global directory"],
1591                                                 ],
1592                                 "indexes" => [
1593                                                 "PRIMARY" => ["id"],
1594                                                 "uid_is-default" => ["uid", "is-default"],
1595                                                 ]
1596                                 ];
1597                 $database["profile_check"] = [
1598                                 "comment" => "DFRN remote auth use",
1599                                 "fields" => [
1600                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1601                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1602                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"],
1603                                                 "dfrn_id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1604                                                 "sec" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1605                                                 "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1606                                                 ],
1607                                 "indexes" => [
1608                                                 "PRIMARY" => ["id"],
1609                                                 ]
1610                                 ];
1611                 $database["push_subscriber"] = [
1612                                 "comment" => "Used for OStatus: Contains feed subscribers",
1613                                 "fields" => [
1614                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1615                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1616                                                 "callback_url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1617                                                 "topic" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1618                                                 "nickname" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1619                                                 "push" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Retrial counter"],
1620                                                 "last_update" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last successful trial"],
1621                                                 "next_try" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Next retrial date"],
1622                                                 "renewed" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last subscription renewal"],
1623                                                 "secret" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1624                                                 ],
1625                                 "indexes" => [
1626                                                 "PRIMARY" => ["id"],
1627                                                 "next_try" => ["next_try"],
1628                                                 ]
1629                                 ];
1630                 $database["queue"] = [
1631                                 "comment" => "Queue for messages that couldn't be delivered",
1632                                 "fields" => [
1633                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1634                                                 "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Message receiver"],
1635                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Receiver's network"],
1636                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Unique GUID of the message"],
1637                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date, when the message was created"],
1638                                                 "last" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Date of last trial"],
1639                                                 "next" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Next retrial date"],
1640                                                 "retrial" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Retrial counter"],
1641                                                 "content" => ["type" => "mediumtext", "comment" => ""],
1642                                                 "batch" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1643                                                 ],
1644                                 "indexes" => [
1645                                                 "PRIMARY" => ["id"],
1646                                                 "last" => ["last"],
1647                                                 "next" => ["next"],
1648                                                 ]
1649                                 ];
1650                 $database["register"] = [
1651                                 "comment" => "registrations requiring admin approval",
1652                                 "fields" => [
1653                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1654                                                 "hash" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1655                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1656                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1657                                                 "password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1658                                                 "language" => ["type" => "varchar(16)", "not null" => "1", "default" => "", "comment" => ""],
1659                                                 "note" => ["type" => "text", "comment" => ""],
1660                                                 ],
1661                                 "indexes" => [
1662                                                 "PRIMARY" => ["id"],
1663                                                 ]
1664                                 ];
1665                 $database["search"] = [
1666                                 "comment" => "",
1667                                 "fields" => [
1668                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1669                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1670                                                 "term" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1671                                                 ],
1672                                 "indexes" => [
1673                                                 "PRIMARY" => ["id"],
1674                                                 "uid" => ["uid"],
1675                                                 ]
1676                                 ];
1677                 $database["session"] = [
1678                                 "comment" => "web session storage",
1679                                 "fields" => [
1680                                                 "id" => ["type" => "bigint unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1681                                                 "sid" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => ""],
1682                                                 "data" => ["type" => "text", "comment" => ""],
1683                                                 "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1684                                                 ],
1685                                 "indexes" => [
1686                                                 "PRIMARY" => ["id"],
1687                                                 "sid" => ["sid(64)"],
1688                                                 "expire" => ["expire"],
1689                                                 ]
1690                                 ];
1691                 $database["sign"] = [
1692                                 "comment" => "Diaspora signatures",
1693                                 "fields" => [
1694                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1695                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => "item.id"],
1696                                                 "signed_text" => ["type" => "mediumtext", "comment" => ""],
1697                                                 "signature" => ["type" => "text", "comment" => ""],
1698                                                 "signer" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1699                                                 ],
1700                                 "indexes" => [
1701                                                 "PRIMARY" => ["id"],
1702                                                 "iid" => ["UNIQUE", "iid"],
1703                                                 ]
1704                                 ];
1705                 $database["term"] = [
1706                                 "comment" => "item taxonomy (categories, tags, etc.) table",
1707                                 "fields" => [
1708                                                 "tid" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""],
1709                                                 "oid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => ""],
1710                                                 "otype" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1711                                                 "type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1712                                                 "term" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1713                                                 "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1714                                                 "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1715                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1716                                                 "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1717                                                 "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1718                                                 "aid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1719                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1720                                                 ],
1721                                 "indexes" => [
1722                                                 "PRIMARY" => ["tid"],
1723                                                 "oid_otype_type_term" => ["oid","otype","type","term(32)"],
1724                                                 "uid_otype_type_term_global_created" => ["uid","otype","type","term(32)","global","created"],
1725                                                 "uid_otype_type_url" => ["uid","otype","type","url(64)"],
1726                                                 "guid" => ["guid(64)"],
1727                                                 ]
1728                                 ];
1729                 $database["thread"] = [
1730                                 "comment" => "Thread related data",
1731                                 "fields" => [
1732                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "comment" => "sequential ID"],
1733                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1734                                                 "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
1735                                                 "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Item owner"],
1736                                                 "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Item author"],
1737                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1738                                                 "edited" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1739                                                 "commented" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1740                                                 "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1741                                                 "changed" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
1742                                                 "wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1743                                                 "private" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1744                                                 "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1745                                                 "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1746                                                 "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1747                                                 "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1748                                                 "ignored" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1749                                                 "bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1750                                                 "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
1751                                                 "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1752                                                 "origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1753                                                 "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1754                                                 "mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1755                                                 "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
1756                                                 ],
1757                                 "indexes" => [
1758                                                 "PRIMARY" => ["iid"],
1759                                                 "uid_network_commented" => ["uid","network","commented"],
1760                                                 "uid_network_created" => ["uid","network","created"],
1761                                                 "uid_contactid_commented" => ["uid","contact-id","commented"],
1762                                                 "uid_contactid_created" => ["uid","contact-id","created"],
1763                                                 "contactid" => ["contact-id"],
1764                                                 "ownerid" => ["owner-id"],
1765                                                 "authorid" => ["author-id"],
1766                                                 "uid_created" => ["uid","created"],
1767                                                 "uid_commented" => ["uid","commented"],
1768                                                 "uid_wall_created" => ["uid","wall","created"],
1769                                                 "private_wall_origin_commented" => ["private","wall","origin","commented"],
1770                                                 ]
1771                                 ];
1772                 $database["tokens"] = [
1773                                 "comment" => "OAuth usage",
1774                                 "fields" => [
1775                                                 "id" => ["type" => "varchar(40)", "not null" => "1", "primary" => "1", "comment" => ""],
1776                                                 "secret" => ["type" => "text", "comment" => ""],
1777                                                 "client_id" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => ["clients" => "client_id"]],
1778                                                 "expires" => ["type" => "int", "not null" => "1", "default" => "0", "comment" => ""],
1779                                                 "scope" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""],
1780                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
1781                                                 ],
1782                                 "indexes" => [
1783                                                 "PRIMARY" => ["id"],
1784                                                 ]
1785                                 ];
1786                 $database["user"] = [
1787                                 "comment" => "The local users",
1788                                 "fields" => [
1789                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1790                                                 "parent-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "The parent user that has full control about this user"],
1791                                                 "guid" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this user"],
1792                                                 "username" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this user is known by"],
1793                                                 "password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "encrypted password"],
1794                                                 "legacy_password" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Is the password hash double-hashed?"],
1795                                                 "nickname" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "nick- and user name"],
1796                                                 "email" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "the users email address"],
1797                                                 "openid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
1798                                                 "timezone" => ["type" => "varchar(128)", "not null" => "1", "default" => "", "comment" => "PHP-legal timezone"],
1799                                                 "language" => ["type" => "varchar(32)", "not null" => "1", "default" => "en", "comment" => "default language"],
1800                                                 "register_date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "timestamp of registration"],
1801                                                 "login_date" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "timestamp of last login"],
1802                                                 "default-location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Default for item.location"],
1803                                                 "allow_location" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 allows to display the location"],
1804                                                 "theme" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "user theme preference"],
1805                                                 "pubkey" => ["type" => "text", "comment" => "RSA public key 4096 bit"],
1806                                                 "prvkey" => ["type" => "text", "comment" => "RSA private key 4096 bit"],
1807                                                 "spubkey" => ["type" => "text", "comment" => ""],
1808                                                 "sprvkey" => ["type" => "text", "comment" => ""],
1809                                                 "verified" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "user is verified through email"],
1810                                                 "blocked" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 for user is blocked"],
1811                                                 "blockwall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Prohibit contacts to post to the profile page of the user"],
1812                                                 "hidewall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Hide profile details from unkown viewers"],
1813                                                 "blocktags" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Prohibit contacts to tag the post of this user"],
1814                                                 "unkmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Permit unknown people to send private mails to this user"],
1815                                                 "cntunkmail" => ["type" => "int unsigned", "not null" => "1", "default" => "10", "comment" => ""],
1816                                                 "notify-flags" => ["type" => "smallint unsigned", "not null" => "1", "default" => "65535", "comment" => "email notification options"],
1817                                                 "page-flags" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "page/profile type"],
1818                                                 "account-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1819                                                 "prvnets" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1820                                                 "pwdreset" => ["type" => "varchar(255)", "comment" => "Password reset request token"],
1821                                                 "pwdreset_time" => ["type" => "datetime", "comment" => "Timestamp of the last password reset request"],
1822                                                 "maxreq" => ["type" => "int unsigned", "not null" => "1", "default" => "10", "comment" => ""],
1823                                                 "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1824                                                 "account_removed" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if 1 the account is removed"],
1825                                                 "account_expired" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
1826                                                 "account_expires_on" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "timestamp when account expires and will be deleted"],
1827                                                 "expire_notification_sent" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "timestamp of last warning of account expiration"],
1828                                                 "def_gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
1829                                                 "allow_cid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
1830                                                 "allow_gid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
1831                                                 "deny_cid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
1832                                                 "deny_gid" => ["type" => "mediumtext", "comment" => "default permission for this user"],
1833                                                 "openidserver" => ["type" => "text", "comment" => ""],
1834                                                 ],
1835                                 "indexes" => [
1836                                                 "PRIMARY" => ["uid"],
1837                                                 "nickname" => ["nickname(32)"],
1838                                                 ]
1839                                 ];
1840                 $database["userd"] = [
1841                                 "comment" => "Deleted usernames",
1842                                 "fields" => [
1843                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
1844                                                 "username" => ["type" => "varchar(255)", "not null" => "1", "comment" => ""],
1845                                                 ],
1846                                 "indexes" => [
1847                                                 "PRIMARY" => ["id"],
1848                                                 "username" => ["username(32)"],
1849                                                 ]
1850                                 ];
1851                 $database["user-item"] = [
1852                                 "comment" => "User specific item data",
1853                                 "fields" => [
1854                                                 "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
1855                                                 "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["user" => "uid"], "comment" => "User id"],
1856                                                 "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide an item from the user"],
1857                                                 ],
1858                                 "indexes" => [
1859                                                 "PRIMARY" => ["uid", "iid"],
1860                                                 ]
1861                                 ];
1862                 $database["worker-ipc"] = [
1863                                 "comment" => "Inter process communication between the frontend and the worker",
1864                                 "fields" => [
1865                                                 "key" => ["type" => "int", "not null" => "1", "primary" => "1", "comment" => ""],
1866                                                 "jobs" => ["type" => "boolean", "comment" => "Flag for outstanding jobs"],
1867                                                 ],
1868                                 "indexes" => [
1869                                                 "PRIMARY" => ["key"],
1870                                                 ],
1871                                 "engine" => "MEMORY",
1872                                 ];
1873
1874                 $database["workerqueue"] = [
1875                                 "comment" => "Background tasks queue entries",
1876                                 "fields" => [
1877                                                 "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Auto incremented worker task id"],
1878                                                 "parameter" => ["type" => "mediumblob", "comment" => "Task command"],
1879                                                 "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Task priority"],
1880                                                 "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Creation date"],
1881                                                 "pid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Process id of the worker"],
1882                                                 "executed" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Execution date"],
1883                                                 "done" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marked 1 when the task was done - will be deleted later"],
1884                                                 ],
1885                                 "indexes" => [
1886                                                 "PRIMARY" => ["id"],
1887                                                 "pid" => ["pid"],
1888                                                 "parameter" => ["parameter(64)"],
1889                                                 "priority_created" => ["priority", "created"],
1890                                                 "done_executed" => ["done", "executed"],
1891                                                 ]
1892                                 ];
1893
1894                 \Friendica\Core\Addon::callHooks('dbstructure_definition', $database);
1895
1896                 return $database;
1897         }
1898 }