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