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