]> git.mxchange.org Git - friendica.git/blob - include/dbstructure.php
7fcec33a68c2277ec7f7d24a8461e02235971a26
[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                         foreach ($structure['fields'] AS $fieldname => $parameters) {
403                                 $field_list .= 'ANY_VALUE(`' . $fieldname . '`),';
404                         }
405                         $field_list = rtrim($field_list, ',');
406                         
407                         if ($verbose) {
408                                 // Ensure index conversion to unique removes duplicates
409                                 if ($is_unique) {
410                                         if ($ignore != "") {
411                                                 echo "SET session old_alter_table=1;\n";
412                                         } else {
413                                                 echo "CREATE TABLE `".$temp_name."` LIKE `".$name."`;\n";
414                                         }
415                                 }
416
417                                 echo $sql3."\n";
418
419                                 if ($is_unique) {
420                                         if ($ignore != "") {
421                                                 echo "SET session old_alter_table=0;\n";
422                                         } else {
423                                                 echo "INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";\n";
424                                                 echo "DROP TABLE `".$name."`;\n";
425                                                 echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
426                                         }
427                                 }
428                         }
429
430                         if ($action) {
431                                 Config::set('system', 'maintenance_reason', sprintf(t('%s: updating %s table.'), dbm::date().' '.date('e'), $name));
432
433                                 // Ensure index conversion to unique removes duplicates
434                                 if ($is_unique) {
435                                         if ($ignore != "") {
436                                                 $db->q("SET session old_alter_table=1;");
437                                         } else {
438                                                 $r = $db->q("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
439                                                 if (!dbm::is_result($r)) {
440                                                         $errors .= print_update_error($db, $sql3);
441                                                         return $errors;
442                                                 }
443                                         }
444                                 }
445
446                                 $r = @$db->q($sql3);
447                                 if (!dbm::is_result($r)) {
448                                         $errors .= print_update_error($db, $sql3);
449                                 }
450                                 if ($is_unique) {
451                                         if ($ignore != "") {
452                                                 $db->q("SET session old_alter_table=0;");
453                                         } else {
454                                                 $r = $db->q("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";");
455                                                 if (!dbm::is_result($r)) {
456                                                         $errors .= print_update_error($db, $sql3);
457                                                         return $errors;
458                                                 }
459                                                 $r = $db->q("DROP TABLE `".$name."`;");
460                                                 if (!dbm::is_result($r)) {
461                                                         $errors .= print_update_error($db, $sql3);
462                                                         return $errors;
463                                                 }
464                                                 $r = $db->q("RENAME TABLE `".$temp_name."` TO `".$name."`;");
465                                                 if (!dbm::is_result($r)) {
466                                                         $errors .= print_update_error($db, $sql3);
467                                                         return $errors;
468                                                 }
469                                         }
470                                 }
471                         }
472                 }
473         }
474
475         if ($action) {
476                 Config::set('system', 'maintenance', 0);
477                 Config::set('system', 'maintenance_reason', '');
478         }
479
480         return $errors;
481 }
482
483 function db_field_command($parameters, $create = true) {
484         $fieldstruct = $parameters["type"];
485
486         if (!is_null($parameters["Collation"])) {
487                 $fieldstruct .= " COLLATE ".$parameters["Collation"];
488         }
489
490         if ($parameters["not null"])
491                 $fieldstruct .= " NOT NULL";
492
493         if (isset($parameters["default"])) {
494                 if (strpos(strtolower($parameters["type"]),"int")!==false) {
495                         $fieldstruct .= " DEFAULT ".$parameters["default"];
496                 } else {
497                         $fieldstruct .= " DEFAULT '".$parameters["default"]."'";
498                 }
499         }
500         if ($parameters["extra"] != "")
501                 $fieldstruct .= " ".$parameters["extra"];
502
503         /*if (($parameters["primary"] != "") AND $create)
504                 $fieldstruct .= " PRIMARY KEY";*/
505
506         return($fieldstruct);
507 }
508
509 function db_create_table($name, $fields, $verbose, $action, $indexes=null) {
510         global $a, $db;
511
512         $r = true;
513
514         $sql = "";
515
516         $sql_rows = array();
517         $primary_keys = array();
518         foreach ($fields AS $fieldname => $field) {
519                 $sql_rows[] = "`".dbesc($fieldname)."` ".db_field_command($field);
520                 if (x($field,'primary') and $field['primary']!='') {
521                         $primary_keys[] = $fieldname;
522                 }
523         }
524
525         if (!is_null($indexes)) {
526                 foreach ($indexes AS $indexname => $fieldnames) {
527                         $sql_index = db_create_index($indexname, $fieldnames, "");
528                         if (!is_null($sql_index)) $sql_rows[] = $sql_index;
529                 }
530         }
531
532         $sql = implode(",\n\t", $sql_rows);
533
534         $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n\t", dbesc($name)).$sql."\n) DEFAULT COLLATE utf8mb4_general_ci";
535         if ($verbose)
536                 echo $sql.";\n";
537
538         if ($action)
539                 $r = @$db->q($sql);
540
541         return $r;
542 }
543
544 function db_add_table_field($fieldname, $parameters) {
545         $sql = sprintf("ADD `%s` %s", dbesc($fieldname), db_field_command($parameters));
546         return($sql);
547 }
548
549 function db_modify_table_field($fieldname, $parameters) {
550         $sql = sprintf("MODIFY `%s` %s", dbesc($fieldname), db_field_command($parameters, false));
551         return($sql);
552 }
553
554 function db_drop_index($indexname) {
555         $sql = sprintf("DROP INDEX `%s`", dbesc($indexname));
556         return($sql);
557 }
558
559 function db_create_index($indexname, $fieldnames, $method="ADD") {
560
561         $method = strtoupper(trim($method));
562         if ($method!="" && $method!="ADD") {
563                 throw new Exception("Invalid parameter 'method' in db_create_index(): '$method'");
564                 killme();
565         }
566
567         if ($fieldnames[0] == "UNIQUE") {
568                 array_shift($fieldnames);
569                 $method .= ' UNIQUE';
570         }
571
572         $names = "";
573         foreach ($fieldnames AS $fieldname) {
574                 if ($names != "")
575                         $names .= ",";
576
577                 if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches)) {
578                         $names .= "`".dbesc($matches[1])."`(".intval($matches[2]).")";
579                 } else {
580                         $names .= "`".dbesc($fieldname)."`";
581                 }
582         }
583
584         if ($indexname == "PRIMARY") {
585                 return sprintf("%s PRIMARY KEY(%s)", $method, $names);
586         }
587
588
589         $sql = sprintf("%s INDEX `%s` (%s)", $method, dbesc($indexname), $names);
590         return($sql);
591 }
592
593 function db_group_by($indexname, $fieldnames) {
594
595         if ($fieldnames[0] != "UNIQUE") {
596                 return "";
597         }
598
599         array_shift($fieldnames);
600
601         $names = "";
602         foreach ($fieldnames AS $fieldname) {
603                 if ($names != "")
604                         $names .= ",";
605
606                 if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches)) {
607                         $names .= "`".dbesc($matches[1])."`";
608                 } else {
609                         $names .= "`".dbesc($fieldname)."`";
610                 }
611         }
612
613         $sql = sprintf(" GROUP BY %s", $names);
614         return $sql;
615 }
616
617 function db_definition() {
618
619         $database = array();
620
621         $database["addon"] = array(
622                         "fields" => array(
623                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
624                                         "name" => array("type" => "varchar(190)", "not null" => "1", "default" => ""),
625                                         "version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
626                                         "installed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
627                                         "hidden" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
628                                         "timestamp" => array("type" => "bigint(20)", "not null" => "1", "default" => "0"),
629                                         "plugin_admin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
630                                         ),
631                         "indexes" => array(
632                                         "PRIMARY" => array("id"),
633                                         "name" => array("UNIQUE", "name"),
634                                         )
635                         );
636         $database["attach"] = array(
637                         "fields" => array(
638                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
639                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
640                                         "hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
641                                         "filename" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
642                                         "filetype" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
643                                         "filesize" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
644                                         "data" => array("type" => "longblob", "not null" => "1"),
645                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
646                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
647                                         "allow_cid" => array("type" => "mediumtext"),
648                                         "allow_gid" => array("type" => "mediumtext"),
649                                         "deny_cid" => array("type" => "mediumtext"),
650                                         "deny_gid" => array("type" => "mediumtext"),
651                                         ),
652                         "indexes" => array(
653                                         "PRIMARY" => array("id"),
654                                         )
655                         );
656         $database["auth_codes"] = array(
657                         "fields" => array(
658                                         "id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
659                                         "client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => array("clients" => "client_id")),
660                                         "redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
661                                         "expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
662                                         "scope" => array("type" => "varchar(250)", "not null" => "1", "default" => ""),
663                                         ),
664                         "indexes" => array(
665                                         "PRIMARY" => array("id"),
666                                         )
667                         );
668         $database["cache"] = array(
669                         "fields" => array(
670                                         "k" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
671                                         "v" => array("type" => "mediumtext"),
672                                         "expire_mode" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
673                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
674                                         ),
675                         "indexes" => array(
676                                         "PRIMARY" => array("k"),
677                                         "expire_mode_updated" => array("expire_mode", "updated"),
678                                         )
679                         );
680         $database["challenge"] = array(
681                         "fields" => array(
682                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
683                                         "challenge" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
684                                         "dfrn-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
685                                         "expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
686                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
687                                         "last_update" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
688                                         ),
689                         "indexes" => array(
690                                         "PRIMARY" => array("id"),
691                                         )
692                         );
693         $database["clients"] = array(
694                         "fields" => array(
695                                         "client_id" => array("type" => "varchar(20)", "not null" => "1", "primary" => "1"),
696                                         "pw" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
697                                         "redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
698                                         "name" => array("type" => "text"),
699                                         "icon" => array("type" => "text"),
700                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
701                                         ),
702                         "indexes" => array(
703                                         "PRIMARY" => array("client_id"),
704                                         )
705                         );
706         $database["config"] = array(
707                         "fields" => array(
708                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
709                                         "cat" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
710                                         "k" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
711                                         "v" => array("type" => "mediumtext"),
712                                         ),
713                         "indexes" => array(
714                                         "PRIMARY" => array("id"),
715                                         "cat_k" => array("UNIQUE", "cat", "k"),
716                                         )
717                         );
718         $database["contact"] = array(
719                         "fields" => array(
720                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
721                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
722                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
723                                         "self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
724                                         "remote_self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
725                                         "rel" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
726                                         "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
727                                         "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
728                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
729                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
730                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
731                                         "about" => array("type" => "text"),
732                                         "keywords" => array("type" => "text"),
733                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
734                                         "xmpp" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
735                                         "attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
736                                         "avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
737                                         "photo" => array("type" => "text"),
738                                         "thumb" => array("type" => "text"),
739                                         "micro" => array("type" => "text"),
740                                         "site-pubkey" => array("type" => "text"),
741                                         "issued-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
742                                         "dfrn-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
743                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
744                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
745                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
746                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
747                                         "pubkey" => array("type" => "text"),
748                                         "prvkey" => array("type" => "text"),
749                                         "batch" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
750                                         "request" => array("type" => "text"),
751                                         "notify" => array("type" => "text"),
752                                         "poll" => array("type" => "text"),
753                                         "confirm" => array("type" => "text"),
754                                         "poco" => array("type" => "text"),
755                                         "aes_allow" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
756                                         "ret-aes" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
757                                         "usehub" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
758                                         "subhub" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
759                                         "hub-verify" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
760                                         "last-update" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
761                                         "success_update" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
762                                         "failure_update" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
763                                         "name-date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
764                                         "uri-date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
765                                         "avatar-date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
766                                         "term-date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
767                                         "last-item" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
768                                         "priority" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
769                                         "blocked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
770                                         "readonly" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
771                                         "writable" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
772                                         "forum" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
773                                         "prv" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
774                                         "contact-type" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
775                                         "hidden" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
776                                         "archive" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
777                                         "pending" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
778                                         "rating" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
779                                         "reason" => array("type" => "text"),
780                                         "closeness" => array("type" => "tinyint(2)", "not null" => "1", "default" => "99"),
781                                         "info" => array("type" => "mediumtext"),
782                                         "profile-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
783                                         "bdyear" => array("type" => "varchar(4)", "not null" => "1", "default" => ""),
784                                         "bd" => array("type" => "date", "not null" => "1", "default" => "0001-01-01"),
785                                         "notify_new_posts" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
786                                         "fetch_further_information" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
787                                         "ffi_keyword_blacklist" => array("type" => "text"),
788                                         ),
789                         "indexes" => array(
790                                         "PRIMARY" => array("id"),
791                                         "uid_name" => array("uid", "name(190)"),
792                                         "self_uid" => array("self", "uid"),
793                                         "alias_uid" => array("alias(32)", "uid"),
794                                         "pending_uid" => array("pending", "uid"),
795                                         "blocked_uid" => array("blocked", "uid"),
796                                         "uid_rel_network_poll" => array("uid", "rel", "network(4)", "poll(64)", "archive"),
797                                         "uid_network_batch" => array("uid", "network(4)", "batch(64)"),
798                                         "addr_uid" => array("addr(32)", "uid"),
799                                         "nurl_uid" => array("nurl(32)", "uid"),
800                                         "nick_uid" => array("nick(32)", "uid"),
801                                         "dfrn-id" => array("dfrn-id"),
802                                         "issued-id" => array("issued-id"),
803                                         )
804                         );
805         $database["conv"] = array(
806                         "fields" => array(
807                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
808                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
809                                         "recips" => array("type" => "text"),
810                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
811                                         "creator" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
812                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
813                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
814                                         "subject" => array("type" => "text"),
815                                         ),
816                         "indexes" => array(
817                                         "PRIMARY" => array("id"),
818                                         "uid" => array("uid"),
819                                         )
820                         );
821         $database["conversation"] = array(
822                         "fields" => array(
823                                         "item-uri" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
824                                         "reply-to-uri" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
825                                         "conversation-uri" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
826                                         "conversation-href" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
827                                         "protocol" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
828                                         "source" => array("type" => "mediumtext"),
829                                         "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
830                                         ),
831                         "indexes" => array(
832                                         "PRIMARY" => array("item-uri"),
833                                         "conversation-uri" => array("conversation-uri"),
834                                         )
835                         );
836         $database["event"] = array(
837                         "fields" => array(
838                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
839                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
840                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
841                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
842                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
843                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
844                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
845                                         "start" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
846                                         "finish" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
847                                         "summary" => array("type" => "text"),
848                                         "desc" => array("type" => "text"),
849                                         "location" => array("type" => "text"),
850                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
851                                         "nofinish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
852                                         "adjust" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
853                                         "ignore" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
854                                         "allow_cid" => array("type" => "mediumtext"),
855                                         "allow_gid" => array("type" => "mediumtext"),
856                                         "deny_cid" => array("type" => "mediumtext"),
857                                         "deny_gid" => array("type" => "mediumtext"),
858                                         ),
859                         "indexes" => array(
860                                         "PRIMARY" => array("id"),
861                                         "uid_start" => array("uid", "start"),
862                                         )
863                         );
864         $database["fcontact"] = array(
865                         "fields" => array(
866                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
867                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
868                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
869                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
870                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
871                                         "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
872                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
873                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
874                                         "batch" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
875                                         "notify" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
876                                         "poll" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
877                                         "confirm" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
878                                         "priority" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
879                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
880                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
881                                         "pubkey" => array("type" => "text"),
882                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
883                                         ),
884                         "indexes" => array(
885                                         "PRIMARY" => array("id"),
886                                         "addr" => array("addr(32)"),
887                                         "url" => array("UNIQUE", "url(190)"),
888                                         )
889                         );
890         $database["ffinder"] = array(
891                         "fields" => array(
892                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
893                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
894                                         "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
895                                         "fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("fcontact" => "id")),
896                                         ),
897                         "indexes" => array(
898                                         "PRIMARY" => array("id"),
899                                         )
900                         );
901         $database["fserver"] = array(
902                         "fields" => array(
903                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
904                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
905                                         "posturl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
906                                         "key" => array("type" => "text"),
907                                         ),
908                         "indexes" => array(
909                                         "PRIMARY" => array("id"),
910                                         "server" => array("server(32)"),
911                                         )
912                         );
913         $database["fsuggest"] = array(
914                         "fields" => array(
915                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
916                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
917                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
918                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
919                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
920                                         "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
921                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
922                                         "note" => array("type" => "text"),
923                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
924                                         ),
925                         "indexes" => array(
926                                         "PRIMARY" => array("id"),
927                                         )
928                         );
929         $database["gcign"] = array(
930                         "fields" => array(
931                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
932                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
933                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
934                                         ),
935                         "indexes" => array(
936                                         "PRIMARY" => array("id"),
937                                         "uid" => array("uid"),
938                                         "gcid" => array("gcid"),
939                                         )
940                         );
941         $database["gcontact"] = array(
942                         "fields" => array(
943                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
944                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
945                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
946                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
947                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
948                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
949                                         "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
950                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
951                                         "updated" => array("type" => "datetime", "default" => NULL_DATE),
952                                         "last_contact" => array("type" => "datetime", "default" => NULL_DATE),
953                                         "last_failure" => array("type" => "datetime", "default" => NULL_DATE),
954                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
955                                         "about" => array("type" => "text"),
956                                         "keywords" => array("type" => "text"),
957                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
958                                         "birthday" => array("type" => "varchar(32)", "not null" => "1", "default" => "0001-01-01"),
959                                         "community" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
960                                         "contact-type" => array("type" => "tinyint(1)", "not null" => "1", "default" => "-1"),
961                                         "hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
962                                         "nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
963                                         "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
964                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
965                                         "notify" => array("type" => "text"),
966                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
967                                         "generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
968                                         "server_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
969                                         ),
970                         "indexes" => array(
971                                         "PRIMARY" => array("id"),
972                                         "nurl" => array("UNIQUE", "nurl(190)"),
973                                         "name" => array("name(64)"),
974                                         "nick" => array("nick(32)"),
975                                         "addr" => array("addr(64)"),
976                                         "hide_network_updated" => array("hide", "network(4)", "updated"),
977                                         "updated" => array("updated"),
978                                         )
979                         );
980         $database["glink"] = array(
981                         "fields" => array(
982                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
983                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
984                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
985                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
986                                         "zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
987                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
988                                         ),
989                         "indexes" => array(
990                                         "PRIMARY" => array("id"),
991                                         "cid_uid_gcid_zcid" => array("UNIQUE", "cid","uid","gcid","zcid"),
992                                         "gcid" => array("gcid"),
993                                         )
994                         );
995         $database["group"] = array(
996                         "fields" => array(
997                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
998                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
999                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1000                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1001                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1002                                         ),
1003                         "indexes" => array(
1004                                         "PRIMARY" => array("id"),
1005                                         "uid" => array("uid"),
1006                                         )
1007                         );
1008         $database["group_member"] = array(
1009                         "fields" => array(
1010                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1011                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1012                                         "gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("group" => "id")),
1013                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1014                                         ),
1015                         "indexes" => array(
1016                                         "PRIMARY" => array("id"),
1017                                         "contactid" => array("contact-id"),
1018                                         "gid_contactid" => array("gid", "contact-id"),
1019                                         "uid_gid_contactid" => array("UNIQUE", "uid", "gid", "contact-id"),
1020                                         )
1021                         );
1022         $database["gserver"] = array(
1023                         "fields" => array(
1024                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1025                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1026                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1027                                         "version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1028                                         "site_name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1029                                         "info" => array("type" => "text"),
1030                                         "register_policy" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1031                                         "poco" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1032                                         "noscrape" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1033                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1034                                         "platform" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1035                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1036                                         "last_poco_query" => array("type" => "datetime", "default" => NULL_DATE),
1037                                         "last_contact" => array("type" => "datetime", "default" => NULL_DATE),
1038                                         "last_failure" => array("type" => "datetime", "default" => NULL_DATE),
1039                                         ),
1040                         "indexes" => array(
1041                                         "PRIMARY" => array("id"),
1042                                         "nurl" => array("UNIQUE", "nurl(190)"),
1043                                         )
1044                         );
1045         $database["hook"] = array(
1046                         "fields" => array(
1047                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1048                                         "hook" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1049                                         "file" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1050                                         "function" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1051                                         "priority" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1052                                         ),
1053                         "indexes" => array(
1054                                         "PRIMARY" => array("id"),
1055                                         "hook_file_function" => array("UNIQUE", "hook(50)","file(80)","function(60)"),
1056                                         )
1057                         );
1058         $database["intro"] = array(
1059                         "fields" => array(
1060                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1061                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1062                                         "fid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("fcontact" => "id")),
1063                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1064                                         "knowyou" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1065                                         "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1066                                         "note" => array("type" => "text"),
1067                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1068                                         "datetime" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1069                                         "blocked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
1070                                         "ignore" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1071                                         ),
1072                         "indexes" => array(
1073                                         "PRIMARY" => array("id"),
1074                                         )
1075                         );
1076         $database["item"] = array(
1077                         "fields" => array(
1078                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => array("thread" => "iid")),
1079                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1080                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1081                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1082                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1083                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
1084                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1085                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1086                                         "gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1087                                         "parent" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
1088                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1089                                         "extid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1090                                         "thr-parent" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1091                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1092                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1093                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1094                                         "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1095                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1096                                         "owner-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1097                                         "owner-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1098                                         "owner-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1099                                         "owner-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1100                                         "author-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1101                                         "author-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1102                                         "author-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1103                                         "author-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1104                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1105                                         "body" => array("type" => "mediumtext"),
1106                                         "app" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1107                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1108                                         "object-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1109                                         "object" => array("type" => "text"),
1110                                         "target-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1111                                         "target" => array("type" => "text"),
1112                                         "postopts" => array("type" => "text"),
1113                                         "plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1114                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1115                                         "event-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("event" => "id")),
1116                                         "tag" => array("type" => "mediumtext"),
1117                                         "attach" => array("type" => "mediumtext"),
1118                                         "inform" => array("type" => "mediumtext"),
1119                                         "file" => array("type" => "mediumtext"),
1120                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1121                                         "coord" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1122                                         "allow_cid" => array("type" => "mediumtext"),
1123                                         "allow_gid" => array("type" => "mediumtext"),
1124                                         "deny_cid" => array("type" => "mediumtext"),
1125                                         "deny_gid" => array("type" => "mediumtext"),
1126                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1127                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1128                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1129                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1130                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1131                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1132                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1133                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
1134                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1135                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1136                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1137                                         "last-child" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "1"),
1138                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1139                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1140                                         "rendered-hash" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1141                                         "rendered-html" => array("type" => "mediumtext"),
1142                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1143                                         ),
1144                         "indexes" => array(
1145                                         "PRIMARY" => array("id"),
1146                                         "guid" => array("guid"),
1147                                         "uri" => array("uri"),
1148                                         "parent" => array("parent"),
1149                                         "parent-uri" => array("parent-uri"),
1150                                         "extid" => array("extid"),
1151                                         "uid_id" => array("uid","id"),
1152                                         "uid_contactid_id" => array("uid","contact-id","id"),
1153                                         "uid_created" => array("uid","created"),
1154                                         "uid_unseen_contactid" => array("uid","unseen","contact-id"),
1155                                         "uid_network_received" => array("uid","network(4)","received"),
1156                                         "uid_network_commented" => array("uid","network(4)","commented"),
1157                                         "uid_thrparent" => array("uid","thr-parent(190)"),
1158                                         "uid_parenturi" => array("uid","parent-uri(190)"),
1159                                         "uid_contactid_created" => array("uid","contact-id","created"),
1160                                         "authorid_created" => array("author-id","created"),
1161                                         "ownerid" => array("owner-id"),
1162                                         "uid_uri" => array("uid", "uri(190)"),
1163                                         "resource-id" => array("resource-id"),
1164                                         "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), //
1165                                         "uid_type_changed" => array("uid","type(190)","changed"),
1166                                         "contactid_verb" => array("contact-id","verb(190)"),
1167                                         "deleted_changed" => array("deleted","changed"),
1168                                         "uid_wall_changed" => array("uid","wall","changed"),
1169                                         "uid_eventid" => array("uid","event-id"),
1170                                         "uid_authorlink" => array("uid","author-link(190)"),
1171                                         "uid_ownerlink" => array("uid","owner-link(190)"),
1172                                         )
1173                         );
1174         $database["item_id"] = array(
1175                         "fields" => array(
1176                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1177                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
1178                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1179                                         "sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1180                                         "service" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1181                                         ),
1182                         "indexes" => array(
1183                                         "PRIMARY" => array("id"),
1184                                         "uid" => array("uid"),
1185                                         "sid" => array("sid"),
1186                                         "service" => array("service(32)"),
1187                                         "iid" => array("iid"),
1188                                         )
1189                         );
1190         $database["locks"] = array(
1191                         "fields" => array(
1192                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1193                                         "name" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
1194                                         "locked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1195                                         "created" => array("type" => "datetime", "default" => NULL_DATE),
1196                                         ),
1197                         "indexes" => array(
1198                                         "PRIMARY" => array("id"),
1199                                         )
1200                         );
1201         $database["mail"] = array(
1202                         "fields" => array(
1203                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1204                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1205                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1206                                         "from-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1207                                         "from-photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1208                                         "from-url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1209                                         "contact-id" => array("type" => "varchar(255)", "not null" => "1", "default" => "", "relation" => array("contact" => "id")),
1210                                         "convid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("conv" => "id")),
1211                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1212                                         "body" => array("type" => "mediumtext"),
1213                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1214                                         "reply" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1215                                         "replied" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1216                                         "unknown" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1217                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1218                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1219                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1220                                         ),
1221                         "indexes" => array(
1222                                         "PRIMARY" => array("id"),
1223                                         "uid_seen" => array("uid", "seen"),
1224                                         "convid" => array("convid"),
1225                                         "uri" => array("uri(64)"),
1226                                         "parent-uri" => array("parent-uri(64)"),
1227                                         )
1228                         );
1229         $database["mailacct"] = array(
1230                         "fields" => array(
1231                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1232                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1233                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1234                                         "port" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1235                                         "ssltype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1236                                         "mailbox" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1237                                         "user" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1238                                         "pass" => array("type" => "text"),
1239                                         "reply_to" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1240                                         "action" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1241                                         "movetofolder" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1242                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1243                                         "last_check" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1244                                         ),
1245                         "indexes" => array(
1246                                         "PRIMARY" => array("id"),
1247                                         )
1248                         );
1249         $database["manage"] = array(
1250                         "fields" => array(
1251                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1252                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1253                                         "mid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1254                                         ),
1255                         "indexes" => array(
1256                                         "PRIMARY" => array("id"),
1257                                         "uid_mid" => array("UNIQUE", "uid","mid"),
1258                                         )
1259                         );
1260         $database["notify"] = array(
1261                         "fields" => array(
1262                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1263                                         "hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1264                                         "type" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1265                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1266                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1267                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1268                                         "date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1269                                         "msg" => array("type" => "mediumtext"),
1270                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1271                                         "link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1272                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
1273                                         "parent" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
1274                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1275                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1276                                         "otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1277                                         "name_cache" => array("type" => "tinytext"),
1278                                         "msg_cache" => array("type" => "mediumtext")
1279                                         ),
1280                         "indexes" => array(
1281                                         "PRIMARY" => array("id"),
1282                                         "hash_uid" => array("hash", "uid"),
1283                                         "seen_uid_date" => array("seen", "uid", "date"),
1284                                         "uid_date" => array("uid", "date"),
1285                                         "uid_type_link" => array("uid", "type", "link(190)"),
1286                                         )
1287                         );
1288         $database["notify-threads"] = array(
1289                         "fields" => array(
1290                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1291                                         "notify-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("notify" => "id")),
1292                                         "master-parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
1293                                         "parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1294                                         "receiver-uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1295                                         ),
1296                         "indexes" => array(
1297                                         "PRIMARY" => array("id"),
1298                                         )
1299                         );
1300         $database["oembed"] = array(
1301                         "fields" => array(
1302                                         "url" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
1303                                         "content" => array("type" => "mediumtext"),
1304                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1305                                         ),
1306                         "indexes" => array(
1307                                         "PRIMARY" => array("url"),
1308                                         "created" => array("created"),
1309                                         )
1310                         );
1311         $database["parsed_url"] = array(
1312                         "fields" => array(
1313                                         "url" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
1314                                         "guessing" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
1315                                         "oembed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
1316                                         "content" => array("type" => "mediumtext"),
1317                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1318                                         ),
1319                         "indexes" => array(
1320                                         "PRIMARY" => array("url", "guessing", "oembed"),
1321                                         "created" => array("created"),
1322                                         )
1323                         );
1324         $database["pconfig"] = array(
1325                         "fields" => array(
1326                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1327                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1328                                         "cat" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
1329                                         "k" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
1330                                         "v" => array("type" => "mediumtext"),
1331                                         ),
1332                         "indexes" => array(
1333                                         "PRIMARY" => array("id"),
1334                                         "uid_cat_k" => array("UNIQUE", "uid", "cat", "k"),
1335                                         )
1336                         );
1337         $database["photo"] = array(
1338                         "fields" => array(
1339                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1340                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1341                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1342                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1343                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1344                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1345                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1346                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1347                                         "desc" => array("type" => "text"),
1348                                         "album" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1349                                         "filename" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1350                                         "type" => array("type" => "varchar(128)", "not null" => "1", "default" => "image/jpeg"),
1351                                         "height" => array("type" => "smallint(6)", "not null" => "1", "default" => "0"),
1352                                         "width" => array("type" => "smallint(6)", "not null" => "1", "default" => "0"),
1353                                         "datasize" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1354                                         "data" => array("type" => "mediumblob", "not null" => "1"),
1355                                         "scale" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
1356                                         "profile" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1357                                         "allow_cid" => array("type" => "mediumtext"),
1358                                         "allow_gid" => array("type" => "mediumtext"),
1359                                         "deny_cid" => array("type" => "mediumtext"),
1360                                         "deny_gid" => array("type" => "mediumtext"),
1361                                         ),
1362                         "indexes" => array(
1363                                         "PRIMARY" => array("id"),
1364                                         "uid_contactid" => array("uid", "contact-id"),
1365                                         "uid_profile" => array("uid", "profile"),
1366                                         "uid_album_scale_created" => array("uid", "album(32)", "scale", "created"),
1367                                         "uid_album_resource-id_created" => array("uid", "album(32)", "resource-id(64)", "created"),
1368                                         "resource-id" => array("resource-id(64)"),
1369                                         )
1370                         );
1371         $database["poll"] = array(
1372                         "fields" => array(
1373                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1374                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1375                                         "q0" => array("type" => "text"),
1376                                         "q1" => array("type" => "text"),
1377                                         "q2" => array("type" => "text"),
1378                                         "q3" => array("type" => "text"),
1379                                         "q4" => array("type" => "text"),
1380                                         "q5" => array("type" => "text"),
1381                                         "q6" => array("type" => "text"),
1382                                         "q7" => array("type" => "text"),
1383                                         "q8" => array("type" => "text"),
1384                                         "q9" => array("type" => "text"),
1385                                         ),
1386                         "indexes" => array(
1387                                         "PRIMARY" => array("id"),
1388                                         "uid" => array("uid"),
1389                                         )
1390                         );
1391         $database["poll_result"] = array(
1392                         "fields" => array(
1393                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1394                                         "poll_id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("poll" => "id")),
1395                                         "choice" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1396                                         ),
1397                         "indexes" => array(
1398                                         "PRIMARY" => array("id"),
1399                                         "poll_id" => array("poll_id"),
1400                                         "choice" => array("choice"),
1401                                         )
1402                         );
1403         $database["process"] = array(
1404                         "fields" => array(
1405                                         "pid" => array("type" => "int(10) unsigned", "not null" => "1", "primary" => "1"),
1406                                         "command" => array("type" => "varbinary(32)", "not null" => "1", "default" => ""),
1407                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1408                                         ),
1409                         "indexes" => array(
1410                                         "PRIMARY" => array("pid"),
1411                                         "command" => array("command"),
1412                                         )
1413                         );
1414         $database["profile"] = array(
1415                         "fields" => array(
1416                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1417                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1418                                         "profile-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1419                                         "is-default" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1420                                         "hide-friends" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1421                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1422                                         "pdesc" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1423                                         "dob" => array("type" => "varchar(32)", "not null" => "1", "default" => "0001-01-01"),
1424                                         "address" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1425                                         "locality" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1426                                         "region" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1427                                         "postal-code" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1428                                         "country-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1429                                         "hometown" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1430                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1431                                         "marital" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1432                                         "with" => array("type" => "text"),
1433                                         "howlong" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1434                                         "sexual" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1435                                         "politic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1436                                         "religion" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1437                                         "pub_keywords" => array("type" => "text"),
1438                                         "prv_keywords" => array("type" => "text"),
1439                                         "likes" => array("type" => "text"),
1440                                         "dislikes" => array("type" => "text"),
1441                                         "about" => array("type" => "text"),
1442                                         "summary" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1443                                         "music" => array("type" => "text"),
1444                                         "book" => array("type" => "text"),
1445                                         "tv" => array("type" => "text"),
1446                                         "film" => array("type" => "text"),
1447                                         "interest" => array("type" => "text"),
1448                                         "romance" => array("type" => "text"),
1449                                         "work" => array("type" => "text"),
1450                                         "education" => array("type" => "text"),
1451                                         "contact" => array("type" => "text"),
1452                                         "homepage" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1453                                         "xmpp" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1454                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1455                                         "thumb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1456                                         "publish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1457                                         "net-publish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1458                                         ),
1459                         "indexes" => array(
1460                                         "PRIMARY" => array("id"),
1461                                         "uid_is-default" => array("uid", "is-default"),
1462                                         )
1463                         );
1464         $database["profile_check"] = array(
1465                         "fields" => array(
1466                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1467                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1468                                         "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1469                                         "dfrn_id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1470                                         "sec" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1471                                         "expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1472                                         ),
1473                         "indexes" => array(
1474                                         "PRIMARY" => array("id"),
1475                                         )
1476                         );
1477         $database["push_subscriber"] = array(
1478                         "fields" => array(
1479                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1480                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1481                                         "callback_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1482                                         "topic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1483                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1484                                         "push" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1485                                         "last_update" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1486                                         "secret" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1487                                         ),
1488                         "indexes" => array(
1489                                         "PRIMARY" => array("id"),
1490                                         )
1491                         );
1492         $database["queue"] = array(
1493                         "fields" => array(
1494                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1495                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1496                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1497                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1498                                         "last" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1499                                         "content" => array("type" => "mediumtext"),
1500                                         "batch" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1501                                         ),
1502                         "indexes" => array(
1503                                         "PRIMARY" => array("id"),
1504                                         "cid" => array("cid"),
1505                                         "created" => array("created"),
1506                                         "last" => array("last"),
1507                                         "network" => array("network"),
1508                                         "batch" => array("batch"),
1509                                         )
1510                         );
1511         $database["register"] = array(
1512                         "fields" => array(
1513                                         "id" => array("type" => "int(11) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1514                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1515                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1516                                         "uid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1517                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1518                                         "language" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1519                                         "note" => array("type" => "text"),
1520                                         ),
1521                         "indexes" => array(
1522                                         "PRIMARY" => array("id"),
1523                                         )
1524                         );
1525         $database["search"] = array(
1526                         "fields" => array(
1527                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1528                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1529                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1530                                         ),
1531                         "indexes" => array(
1532                                         "PRIMARY" => array("id"),
1533                                         "uid" => array("uid"),
1534                                         )
1535                         );
1536         $database["session"] = array(
1537                         "fields" => array(
1538                                         "id" => array("type" => "bigint(20) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1539                                         "sid" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
1540                                         "data" => array("type" => "text"),
1541                                         "expire" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1542                                         ),
1543                         "indexes" => array(
1544                                         "PRIMARY" => array("id"),
1545                                         "sid" => array("sid(64)"),
1546                                         "expire" => array("expire"),
1547                                         )
1548                         );
1549         $database["sign"] = array(
1550                         "fields" => array(
1551                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1552                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
1553                                         "signed_text" => array("type" => "mediumtext"),
1554                                         "signature" => array("type" => "text"),
1555                                         "signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1556                                         ),
1557                         "indexes" => array(
1558                                         "PRIMARY" => array("id"),
1559                                         "iid" => array("iid"),
1560                                         )
1561                         );
1562         $database["spam"] = array(
1563                         "fields" => array(
1564                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1565                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1566                                         "spam" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1567                                         "ham" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1568                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1569                                         "date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1570                                         ),
1571                         "indexes" => array(
1572                                         "PRIMARY" => array("id"),
1573                                         "uid" => array("uid"),
1574                                         "spam" => array("spam"),
1575                                         "ham" => array("ham"),
1576                                         "term" => array("term"),
1577                                         )
1578                         );
1579         $database["term"] = array(
1580                         "fields" => array(
1581                                         "tid" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1582                                         "oid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
1583                                         "otype" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1584                                         "type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1585                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1586                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1587                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1588                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1589                                         "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1590                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1591                                         "aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1592                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1593                                         ),
1594                         "indexes" => array(
1595                                         "PRIMARY" => array("tid"),
1596                                         "oid_otype_type_term" => array("oid","otype","type","term(32)"),
1597                                         "uid_otype_type_term_global_created" => array("uid","otype","type","term(32)","global","created"),
1598                                         "uid_otype_type_url" => array("uid","otype","type","url(64)"),
1599                                         "guid" => array("guid(64)"),
1600                                         )
1601                         );
1602         $database["thread"] = array(
1603                         "fields" => array(
1604                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => array("item" => "id")),
1605                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1606                                         "contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1607                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
1608                                         "owner-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1609                                         "author-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
1610                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1611                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1612                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1613                                         "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1614                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1615                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1616                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1617                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1618                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1619                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1620                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1621                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1622                                         "ignored" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1623                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1624                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
1625                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1626                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1627                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1628                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1629                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1630                                         ),
1631                         "indexes" => array(
1632                                         "PRIMARY" => array("iid"),
1633                                         "uid_network_commented" => array("uid","network","commented"),
1634                                         "uid_network_created" => array("uid","network","created"),
1635                                         "uid_contactid_commented" => array("uid","contact-id","commented"),
1636                                         "uid_contactid_created" => array("uid","contact-id","created"),
1637                                         "contactid" => array("contact-id"),
1638                                         "ownerid" => array("owner-id"),
1639                                         "authorid" => array("author-id"),
1640                                         "uid_created" => array("uid","created"),
1641                                         "uid_commented" => array("uid","commented"),
1642                                         "uid_wall_created" => array("uid","wall","created"),
1643                                         )
1644                         );
1645         $database["tokens"] = array(
1646                         "fields" => array(
1647                                         "id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
1648                                         "secret" => array("type" => "text"),
1649                                         "client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => array("clients" => "client_id")),
1650                                         "expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1651                                         "scope" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
1652                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
1653                                         ),
1654                         "indexes" => array(
1655                                         "PRIMARY" => array("id"),
1656                                         )
1657                         );
1658         $database["user"] = array(
1659                         "fields" => array(
1660                                         "uid" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1661                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1662                                         "username" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1663                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1664                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1665                                         "email" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1666                                         "openid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1667                                         "timezone" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
1668                                         "language" => array("type" => "varchar(32)", "not null" => "1", "default" => "en"),
1669                                         "register_date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1670                                         "login_date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1671                                         "default-location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1672                                         "allow_location" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1673                                         "theme" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1674                                         "pubkey" => array("type" => "text"),
1675                                         "prvkey" => array("type" => "text"),
1676                                         "spubkey" => array("type" => "text"),
1677                                         "sprvkey" => array("type" => "text"),
1678                                         "verified" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1679                                         "blocked" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1680                                         "blockwall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1681                                         "hidewall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1682                                         "blocktags" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1683                                         "unkmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1684                                         "cntunkmail" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1685                                         "notify-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "65535"),
1686                                         "page-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1687                                         "account-type" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1688                                         "prvnets" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1689                                         "pwdreset" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1690                                         "maxreq" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1691                                         "expire" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1692                                         "account_removed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1693                                         "account_expired" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1694                                         "account_expires_on" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1695                                         "expire_notification_sent" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1696                                         "service_class" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1697                                         "def_gid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1698                                         "allow_cid" => array("type" => "mediumtext"),
1699                                         "allow_gid" => array("type" => "mediumtext"),
1700                                         "deny_cid" => array("type" => "mediumtext"),
1701                                         "deny_gid" => array("type" => "mediumtext"),
1702                                         "openidserver" => array("type" => "text"),
1703                                         ),
1704                         "indexes" => array(
1705                                         "PRIMARY" => array("uid"),
1706                                         "nickname" => array("nickname(32)"),
1707                                         )
1708                         );
1709         $database["userd"] = array(
1710                         "fields" => array(
1711                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1712                                         "username" => array("type" => "varchar(255)", "not null" => "1"),
1713                                         ),
1714                         "indexes" => array(
1715                                         "PRIMARY" => array("id"),
1716                                         "username" => array("username(32)"),
1717                                         )
1718                         );
1719         $database["workerqueue"] = array(
1720                         "fields" => array(
1721                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1722                                         "parameter" => array("type" => "text"),
1723                                         "priority" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1724                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1725                                         "pid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1726                                         "executed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1727                                         ),
1728                         "indexes" => array(
1729                                         "PRIMARY" => array("id"),
1730                                         )
1731                         );
1732
1733         return($database);
1734 }
1735
1736
1737 /*
1738  * run from command line
1739  */
1740 function dbstructure_run(&$argv, &$argc) {
1741         global $a, $db;
1742
1743         if (is_null($a)) {
1744                 $a = new App;
1745         }
1746
1747         if (is_null($db)) {
1748                 @include(".htconfig.php");
1749                 require_once("include/dba.php");
1750                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
1751                         unset($db_host, $db_user, $db_pass, $db_data);
1752         }
1753
1754         if ($argc==2) {
1755                 switch ($argv[1]) {
1756                         case "dryrun":
1757                                 update_structure(true, false);
1758                                 return;
1759                         case "update":
1760                                 update_structure(true, true);
1761
1762                                 $build = get_config('system','build');
1763                                 if (!x($build)) {
1764                                         set_config('system','build',DB_UPDATE_VERSION);
1765                                         $build = DB_UPDATE_VERSION;
1766                                 }
1767
1768                                 $stored = intval($build);
1769                                 $current = intval(DB_UPDATE_VERSION);
1770
1771                                 // run any left update_nnnn functions in update.php
1772                                 for ($x = $stored; $x < $current; $x ++) {
1773                                         $r = run_update_function($x);
1774                                         if (!$r) break;
1775                                 }
1776
1777                                 set_config('system','build',DB_UPDATE_VERSION);
1778                                 return;
1779                         case "dumpsql":
1780                                 print_structure(db_definition());
1781                                 return;
1782                         case "toinnodb":
1783                                 convert_to_innodb();
1784                                 return;
1785                 }
1786         }
1787
1788
1789         // print help
1790         echo $argv[0]." <command>\n";
1791         echo "\n";
1792         echo "Commands:\n";
1793         echo "dryrun            show database update schema queries without running them\n";
1794         echo "update            update database schema\n";
1795         echo "dumpsql           dump database schema\n";
1796         echo "toinnodb  convert all tables from MyISAM to InnoDB\n";
1797         return;
1798
1799 }
1800
1801 if (array_search(__file__,get_included_files())===0) {
1802         dbstructure_run($_SERVER["argv"],$_SERVER["argc"]);
1803         killme();
1804 }