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