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