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