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