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