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