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