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