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