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