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