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