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