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