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