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