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