]> git.mxchange.org Git - friendica.git/blob - include/dbstructure.php
Merge pull request #3392 from Hypolite/issue/#3387
[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["event"] = array(
813                         "fields" => array(
814                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
815                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
816                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
817                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
818                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
819                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
820                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
821                                         "start" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
822                                         "finish" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
823                                         "summary" => array("type" => "text"),
824                                         "desc" => array("type" => "text"),
825                                         "location" => array("type" => "text"),
826                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
827                                         "nofinish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
828                                         "adjust" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
829                                         "ignore" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
830                                         "allow_cid" => array("type" => "mediumtext"),
831                                         "allow_gid" => array("type" => "mediumtext"),
832                                         "deny_cid" => array("type" => "mediumtext"),
833                                         "deny_gid" => array("type" => "mediumtext"),
834                                         ),
835                         "indexes" => array(
836                                         "PRIMARY" => array("id"),
837                                         "uid_start" => array("uid", "start"),
838                                         )
839                         );
840         $database["fcontact"] = array(
841                         "fields" => array(
842                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
843                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
844                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
845                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
846                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
847                                         "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
848                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
849                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
850                                         "batch" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
851                                         "notify" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
852                                         "poll" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
853                                         "confirm" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
854                                         "priority" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
855                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
856                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
857                                         "pubkey" => array("type" => "text"),
858                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
859                                         ),
860                         "indexes" => array(
861                                         "PRIMARY" => array("id"),
862                                         "addr" => array("addr(32)"),
863                                         "url" => array("url"),
864                                         )
865                         );
866         $database["ffinder"] = array(
867                         "fields" => array(
868                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
869                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
870                                         "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
871                                         "fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
872                                         ),
873                         "indexes" => array(
874                                         "PRIMARY" => array("id"),
875                                         )
876                         );
877         $database["fserver"] = array(
878                         "fields" => array(
879                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
880                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
881                                         "posturl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
882                                         "key" => array("type" => "text"),
883                                         ),
884                         "indexes" => array(
885                                         "PRIMARY" => array("id"),
886                                         "server" => array("server(32)"),
887                                         )
888                         );
889         $database["fsuggest"] = array(
890                         "fields" => array(
891                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
892                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
893                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
894                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
895                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
896                                         "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
897                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
898                                         "note" => array("type" => "text"),
899                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
900                                         ),
901                         "indexes" => array(
902                                         "PRIMARY" => array("id"),
903                                         )
904                         );
905         $database["gcign"] = array(
906                         "fields" => array(
907                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
908                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
909                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
910                                         ),
911                         "indexes" => array(
912                                         "PRIMARY" => array("id"),
913                                         "uid" => array("uid"),
914                                         "gcid" => array("gcid"),
915                                         )
916                         );
917         $database["gcontact"] = array(
918                         "fields" => array(
919                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
920                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
921                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
922                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
923                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
924                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
925                                         "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
926                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
927                                         "updated" => array("type" => "datetime", "default" => NULL_DATE),
928                                         "last_contact" => array("type" => "datetime", "default" => NULL_DATE),
929                                         "last_failure" => array("type" => "datetime", "default" => NULL_DATE),
930                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
931                                         "about" => array("type" => "text"),
932                                         "keywords" => array("type" => "text"),
933                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
934                                         "birthday" => array("type" => "varchar(32)", "not null" => "1", "default" => "0001-01-01"),
935                                         "community" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
936                                         "contact-type" => array("type" => "tinyint(1)", "not null" => "1", "default" => "-1"),
937                                         "hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
938                                         "nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
939                                         "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
940                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
941                                         "notify" => array("type" => "text"),
942                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
943                                         "generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
944                                         "server_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
945                                         ),
946                         "indexes" => array(
947                                         "PRIMARY" => array("id"),
948                                         "nurl" => array("nurl(64)"),
949                                         "name" => array("name(64)"),
950                                         "nick" => array("nick(32)"),
951                                         "addr" => array("addr(64)"),
952                                         "hide_network_updated" => array("hide", "network(4)", "updated"),
953                                         "updated" => array("updated"),
954                                         )
955                         );
956         $database["glink"] = array(
957                         "fields" => array(
958                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
959                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
960                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
961                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
962                                         "zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
963                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
964                                         ),
965                         "indexes" => array(
966                                         "PRIMARY" => array("id"),
967                                         "cid_uid_gcid_zcid" => array("UNIQUE", "cid","uid","gcid","zcid"),
968                                         "gcid" => array("gcid"),
969                                         )
970                         );
971         $database["group"] = array(
972                         "fields" => array(
973                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
974                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
975                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
976                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
977                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
978                                         ),
979                         "indexes" => array(
980                                         "PRIMARY" => array("id"),
981                                         "uid" => array("uid"),
982                                         )
983                         );
984         $database["group_member"] = array(
985                         "fields" => array(
986                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
987                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
988                                         "gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
989                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
990                                         ),
991                         "indexes" => array(
992                                         "PRIMARY" => array("id"),
993                                         "contactid" => array("contact-id"),
994                                         "gid_contactid" => array("gid", "contact-id"),
995                                         "uid_gid_contactid" => array("UNIQUE", "uid", "gid", "contact-id"),
996                                         )
997                         );
998         $database["gserver"] = array(
999                         "fields" => array(
1000                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1001                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1002                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1003                                         "version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1004                                         "site_name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1005                                         "info" => array("type" => "text"),
1006                                         "register_policy" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1007                                         "poco" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1008                                         "noscrape" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1009                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1010                                         "platform" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1011                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1012                                         "last_poco_query" => array("type" => "datetime", "default" => NULL_DATE),
1013                                         "last_contact" => array("type" => "datetime", "default" => NULL_DATE),
1014                                         "last_failure" => array("type" => "datetime", "default" => NULL_DATE),
1015                                         ),
1016                         "indexes" => array(
1017                                         "PRIMARY" => array("id"),
1018                                         "nurl" => array("nurl(32)"),
1019                                         )
1020                         );
1021         $database["hook"] = array(
1022                         "fields" => array(
1023                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1024                                         "hook" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1025                                         "file" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1026                                         "function" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1027                                         "priority" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1028                                         ),
1029                         "indexes" => array(
1030                                         "PRIMARY" => array("id"),
1031                                         "hook_file_function" => array("UNIQUE", "hook(50)","file(80)","function(60)"),
1032                                         )
1033                         );
1034         $database["intro"] = array(
1035                         "fields" => array(
1036                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1037                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1038                                         "fid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1039                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1040                                         "knowyou" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1041                                         "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1042                                         "note" => array("type" => "text"),
1043                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1044                                         "datetime" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1045                                         "blocked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
1046                                         "ignore" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1047                                         ),
1048                         "indexes" => array(
1049                                         "PRIMARY" => array("id"),
1050                                         )
1051                         );
1052         $database["item"] = array(
1053                         "fields" => array(
1054                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1055                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1056                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1057                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1058                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1059                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1060                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1061                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1062                                         "gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1063                                         "parent" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1064                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1065                                         "extid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1066                                         "thr-parent" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1067                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1068                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1069                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1070                                         "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1071                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1072                                         "owner-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1073                                         "owner-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1074                                         "owner-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1075                                         "owner-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1076                                         "author-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1077                                         "author-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1078                                         "author-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1079                                         "author-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1080                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1081                                         "body" => array("type" => "mediumtext"),
1082                                         "app" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1083                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1084                                         "object-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1085                                         "object" => array("type" => "text"),
1086                                         "target-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1087                                         "target" => array("type" => "text"),
1088                                         "postopts" => array("type" => "text"),
1089                                         "plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1090                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1091                                         "event-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1092                                         "tag" => array("type" => "mediumtext"),
1093                                         "attach" => array("type" => "mediumtext"),
1094                                         "inform" => array("type" => "mediumtext"),
1095                                         "file" => array("type" => "mediumtext"),
1096                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1097                                         "coord" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1098                                         "allow_cid" => array("type" => "mediumtext"),
1099                                         "allow_gid" => array("type" => "mediumtext"),
1100                                         "deny_cid" => array("type" => "mediumtext"),
1101                                         "deny_gid" => array("type" => "mediumtext"),
1102                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1103                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1104                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1105                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1106                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1107                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1108                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1109                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
1110                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1111                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1112                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1113                                         "last-child" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "1"),
1114                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1115                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1116                                         "rendered-hash" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1117                                         "rendered-html" => array("type" => "mediumtext"),
1118                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1119                                         ),
1120                         "indexes" => array(
1121                                         "PRIMARY" => array("id"),
1122                                         "guid" => array("guid"),
1123                                         "uri" => array("uri"),
1124                                         "parent" => array("parent"),
1125                                         "parent-uri" => array("parent-uri"),
1126                                         "extid" => array("extid"),
1127                                         "uid_id" => array("uid","id"),
1128                                         "uid_contactid_id" => array("uid","contact-id","id"),
1129                                         "uid_created" => array("uid","created"),
1130                                         "uid_unseen_contactid" => array("uid","unseen","contact-id"),
1131                                         "uid_network_received" => array("uid","network(4)","received"),
1132                                         "uid_network_commented" => array("uid","network(4)","commented"),
1133                                         "uid_thrparent" => array("uid","thr-parent(190)"),
1134                                         "uid_parenturi" => array("uid","parent-uri(190)"),
1135                                         "uid_contactid_created" => array("uid","contact-id","created"),
1136                                         "authorid_created" => array("author-id","created"),
1137                                         "uid_uri" => array("uid", "uri(190)"),
1138                                         "resource-id" => array("resource-id"),
1139                                         "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), //
1140                                         "uid_type_changed" => array("uid","type(190)","changed"),
1141                                         "contactid_verb" => array("contact-id","verb(190)"),
1142                                         "deleted_changed" => array("deleted","changed"),
1143                                         "uid_wall_changed" => array("uid","wall","changed"),
1144                                         "uid_eventid" => array("uid","event-id"),
1145                                         "uid_authorlink" => array("uid","author-link(190)"),
1146                                         "uid_ownerlink" => array("uid","owner-link(190)"),
1147                                         )
1148                         );
1149         $database["item_id"] = array(
1150                         "fields" => array(
1151                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1152                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1153                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1154                                         "sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1155                                         "service" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1156                                         ),
1157                         "indexes" => array(
1158                                         "PRIMARY" => array("id"),
1159                                         "uid" => array("uid"),
1160                                         "sid" => array("sid"),
1161                                         "service" => array("service(32)"),
1162                                         "iid" => array("iid"),
1163                                         )
1164                         );
1165         $database["locks"] = array(
1166                         "fields" => array(
1167                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1168                                         "name" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
1169                                         "locked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1170                                         "created" => array("type" => "datetime", "default" => NULL_DATE),
1171                                         ),
1172                         "indexes" => array(
1173                                         "PRIMARY" => array("id"),
1174                                         )
1175                         );
1176         $database["mail"] = array(
1177                         "fields" => array(
1178                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1179                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1180                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1181                                         "from-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1182                                         "from-photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1183                                         "from-url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1184                                         "contact-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1185                                         "convid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1186                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1187                                         "body" => array("type" => "mediumtext"),
1188                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1189                                         "reply" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1190                                         "replied" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1191                                         "unknown" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1192                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1193                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1194                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1195                                         ),
1196                         "indexes" => array(
1197                                         "PRIMARY" => array("id"),
1198                                         "uid_seen" => array("uid", "seen"),
1199                                         "convid" => array("convid"),
1200                                         "uri" => array("uri(64)"),
1201                                         "parent-uri" => array("parent-uri(64)"),
1202                                         )
1203                         );
1204         $database["mailacct"] = array(
1205                         "fields" => array(
1206                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1207                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1208                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1209                                         "port" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1210                                         "ssltype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1211                                         "mailbox" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1212                                         "user" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1213                                         "pass" => array("type" => "text"),
1214                                         "reply_to" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1215                                         "action" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1216                                         "movetofolder" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1217                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1218                                         "last_check" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1219                                         ),
1220                         "indexes" => array(
1221                                         "PRIMARY" => array("id"),
1222                                         )
1223                         );
1224         $database["manage"] = array(
1225                         "fields" => array(
1226                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1227                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1228                                         "mid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1229                                         ),
1230                         "indexes" => array(
1231                                         "PRIMARY" => array("id"),
1232                                         "uid_mid" => array("UNIQUE", "uid","mid"),
1233                                         )
1234                         );
1235         $database["notify"] = array(
1236                         "fields" => array(
1237                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1238                                         "hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1239                                         "type" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1240                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1241                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1242                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1243                                         "date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1244                                         "msg" => array("type" => "mediumtext"),
1245                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1246                                         "link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1247                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1248                                         "parent" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1249                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1250                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1251                                         "otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1252                                         "name_cache" => array("type" => "tinytext"),
1253                                         "msg_cache" => array("type" => "mediumtext")
1254                                         ),
1255                         "indexes" => array(
1256                                         "PRIMARY" => array("id"),
1257                                         "hash_uid" => array("hash", "uid"),
1258                                         "seen_uid_date" => array("seen", "uid", "date"),
1259                                         "uid_date" => array("uid", "date"),
1260                                         "uid_type_link" => array("uid", "type", "link(190)"),
1261                                         )
1262                         );
1263         $database["notify-threads"] = array(
1264                         "fields" => array(
1265                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1266                                         "notify-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1267                                         "master-parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1268                                         "parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1269                                         "receiver-uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1270                                         ),
1271                         "indexes" => array(
1272                                         "PRIMARY" => array("id"),
1273                                         )
1274                         );
1275         $database["oembed"] = array(
1276                         "fields" => array(
1277                                         "url" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
1278                                         "content" => array("type" => "mediumtext"),
1279                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1280                                         ),
1281                         "indexes" => array(
1282                                         "PRIMARY" => array("url"),
1283                                         "created" => array("created"),
1284                                         )
1285                         );
1286         $database["parsed_url"] = array(
1287                         "fields" => array(
1288                                         "url" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
1289                                         "guessing" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
1290                                         "oembed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
1291                                         "content" => array("type" => "mediumtext"),
1292                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1293                                         ),
1294                         "indexes" => array(
1295                                         "PRIMARY" => array("url", "guessing", "oembed"),
1296                                         "created" => array("created"),
1297                                         )
1298                         );
1299         $database["pconfig"] = array(
1300                         "fields" => array(
1301                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1302                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1303                                         "cat" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
1304                                         "k" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
1305                                         "v" => array("type" => "mediumtext"),
1306                                         ),
1307                         "indexes" => array(
1308                                         "PRIMARY" => array("id"),
1309                                         "uid_cat_k" => array("UNIQUE", "uid", "cat", "k"),
1310                                         )
1311                         );
1312         $database["photo"] = array(
1313                         "fields" => array(
1314                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1315                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1316                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1317                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1318                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1319                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1320                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1321                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1322                                         "desc" => array("type" => "text"),
1323                                         "album" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1324                                         "filename" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1325                                         "type" => array("type" => "varchar(128)", "not null" => "1", "default" => "image/jpeg"),
1326                                         "height" => array("type" => "smallint(6)", "not null" => "1", "default" => "0"),
1327                                         "width" => array("type" => "smallint(6)", "not null" => "1", "default" => "0"),
1328                                         "datasize" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1329                                         "data" => array("type" => "mediumblob", "not null" => "1"),
1330                                         "scale" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
1331                                         "profile" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1332                                         "allow_cid" => array("type" => "mediumtext"),
1333                                         "allow_gid" => array("type" => "mediumtext"),
1334                                         "deny_cid" => array("type" => "mediumtext"),
1335                                         "deny_gid" => array("type" => "mediumtext"),
1336                                         ),
1337                         "indexes" => array(
1338                                         "PRIMARY" => array("id"),
1339                                         "uid_contactid" => array("uid", "contact-id"),
1340                                         "uid_profile" => array("uid", "profile"),
1341                                         "uid_album_scale_created" => array("uid", "album(32)", "scale", "created"),
1342                                         "uid_album_resource-id_created" => array("uid", "album(32)", "resource-id(64)", "created"),
1343                                         "resource-id" => array("resource-id(64)"),
1344                                         )
1345                         );
1346         $database["poll"] = array(
1347                         "fields" => array(
1348                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1349                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1350                                         "q0" => array("type" => "text"),
1351                                         "q1" => array("type" => "text"),
1352                                         "q2" => array("type" => "text"),
1353                                         "q3" => array("type" => "text"),
1354                                         "q4" => array("type" => "text"),
1355                                         "q5" => array("type" => "text"),
1356                                         "q6" => array("type" => "text"),
1357                                         "q7" => array("type" => "text"),
1358                                         "q8" => array("type" => "text"),
1359                                         "q9" => array("type" => "text"),
1360                                         ),
1361                         "indexes" => array(
1362                                         "PRIMARY" => array("id"),
1363                                         "uid" => array("uid"),
1364                                         )
1365                         );
1366         $database["poll_result"] = array(
1367                         "fields" => array(
1368                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1369                                         "poll_id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1370                                         "choice" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1371                                         ),
1372                         "indexes" => array(
1373                                         "PRIMARY" => array("id"),
1374                                         "poll_id" => array("poll_id"),
1375                                         "choice" => array("choice"),
1376                                         )
1377                         );
1378         $database["process"] = array(
1379                         "fields" => array(
1380                                         "pid" => array("type" => "int(10) unsigned", "not null" => "1", "primary" => "1"),
1381                                         "command" => array("type" => "varbinary(32)", "not null" => "1", "default" => ""),
1382                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1383                                         ),
1384                         "indexes" => array(
1385                                         "PRIMARY" => array("pid"),
1386                                         "command" => array("command"),
1387                                         )
1388                         );
1389         $database["profile"] = array(
1390                         "fields" => array(
1391                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1392                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1393                                         "profile-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1394                                         "is-default" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1395                                         "hide-friends" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1396                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1397                                         "pdesc" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1398                                         "dob" => array("type" => "varchar(32)", "not null" => "1", "default" => "0001-01-01"),
1399                                         "address" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1400                                         "locality" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1401                                         "region" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1402                                         "postal-code" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1403                                         "country-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1404                                         "hometown" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1405                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1406                                         "marital" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1407                                         "with" => array("type" => "text"),
1408                                         "howlong" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1409                                         "sexual" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1410                                         "politic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1411                                         "religion" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1412                                         "pub_keywords" => array("type" => "text"),
1413                                         "prv_keywords" => array("type" => "text"),
1414                                         "likes" => array("type" => "text"),
1415                                         "dislikes" => array("type" => "text"),
1416                                         "about" => array("type" => "text"),
1417                                         "summary" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1418                                         "music" => array("type" => "text"),
1419                                         "book" => array("type" => "text"),
1420                                         "tv" => array("type" => "text"),
1421                                         "film" => array("type" => "text"),
1422                                         "interest" => array("type" => "text"),
1423                                         "romance" => array("type" => "text"),
1424                                         "work" => array("type" => "text"),
1425                                         "education" => array("type" => "text"),
1426                                         "contact" => array("type" => "text"),
1427                                         "homepage" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1428                                         "xmpp" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1429                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1430                                         "thumb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1431                                         "publish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1432                                         "net-publish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1433                                         ),
1434                         "indexes" => array(
1435                                         "PRIMARY" => array("id"),
1436                                         "uid_is-default" => array("uid", "is-default"),
1437                                         )
1438                         );
1439         $database["profile_check"] = array(
1440                         "fields" => array(
1441                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1442                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1443                                         "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1444                                         "dfrn_id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1445                                         "sec" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1446                                         "expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1447                                         ),
1448                         "indexes" => array(
1449                                         "PRIMARY" => array("id"),
1450                                         )
1451                         );
1452         $database["push_subscriber"] = array(
1453                         "fields" => array(
1454                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1455                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1456                                         "callback_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1457                                         "topic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1458                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1459                                         "push" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1460                                         "last_update" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1461                                         "secret" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1462                                         ),
1463                         "indexes" => array(
1464                                         "PRIMARY" => array("id"),
1465                                         )
1466                         );
1467         $database["queue"] = array(
1468                         "fields" => array(
1469                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1470                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1471                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1472                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1473                                         "last" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1474                                         "content" => array("type" => "mediumtext"),
1475                                         "batch" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1476                                         ),
1477                         "indexes" => array(
1478                                         "PRIMARY" => array("id"),
1479                                         "cid" => array("cid"),
1480                                         "created" => array("created"),
1481                                         "last" => array("last"),
1482                                         "network" => array("network"),
1483                                         "batch" => array("batch"),
1484                                         )
1485                         );
1486         $database["register"] = array(
1487                         "fields" => array(
1488                                         "id" => array("type" => "int(11) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1489                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1490                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1491                                         "uid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1492                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1493                                         "language" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1494                                         "note" => array("type" => "text"),
1495                                         ),
1496                         "indexes" => array(
1497                                         "PRIMARY" => array("id"),
1498                                         )
1499                         );
1500         $database["search"] = array(
1501                         "fields" => array(
1502                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1503                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1504                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1505                                         ),
1506                         "indexes" => array(
1507                                         "PRIMARY" => array("id"),
1508                                         "uid" => array("uid"),
1509                                         )
1510                         );
1511         $database["session"] = array(
1512                         "fields" => array(
1513                                         "id" => array("type" => "bigint(20) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1514                                         "sid" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
1515                                         "data" => array("type" => "text"),
1516                                         "expire" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1517                                         ),
1518                         "indexes" => array(
1519                                         "PRIMARY" => array("id"),
1520                                         "sid" => array("sid(64)"),
1521                                         "expire" => array("expire"),
1522                                         )
1523                         );
1524         $database["sign"] = array(
1525                         "fields" => array(
1526                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1527                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1528                                         "signed_text" => array("type" => "mediumtext"),
1529                                         "signature" => array("type" => "text"),
1530                                         "signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1531                                         ),
1532                         "indexes" => array(
1533                                         "PRIMARY" => array("id"),
1534                                         "iid" => array("iid"),
1535                                         )
1536                         );
1537         $database["spam"] = array(
1538                         "fields" => array(
1539                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1540                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1541                                         "spam" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1542                                         "ham" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1543                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1544                                         "date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1545                                         ),
1546                         "indexes" => array(
1547                                         "PRIMARY" => array("id"),
1548                                         "uid" => array("uid"),
1549                                         "spam" => array("spam"),
1550                                         "ham" => array("ham"),
1551                                         "term" => array("term"),
1552                                         )
1553                         );
1554         $database["term"] = array(
1555                         "fields" => array(
1556                                         "tid" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1557                                         "oid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1558                                         "otype" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1559                                         "type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1560                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1561                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1562                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1563                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1564                                         "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1565                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1566                                         "aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1567                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1568                                         ),
1569                         "indexes" => array(
1570                                         "PRIMARY" => array("tid"),
1571                                         "oid_otype_type_term" => array("oid","otype","type","term(32)"),
1572                                         "uid_otype_type_term_global_created" => array("uid","otype","type","term(32)","global","created"),
1573                                         "uid_otype_type_url" => array("uid","otype","type","url(64)"),
1574                                         "guid" => array("guid(64)"),
1575                                         )
1576                         );
1577         $database["thread"] = array(
1578                         "fields" => array(
1579                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1"),
1580                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1581                                         "contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1582                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1583                                         "owner-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1584                                         "author-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1585                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1586                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1587                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1588                                         "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1589                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1590                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1591                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1592                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1593                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1594                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1595                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1596                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1597                                         "ignored" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1598                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1599                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
1600                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1601                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1602                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1603                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1604                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1605                                         ),
1606                         "indexes" => array(
1607                                         "PRIMARY" => array("iid"),
1608                                         "uid_network_commented" => array("uid","network","commented"),
1609                                         "uid_network_created" => array("uid","network","created"),
1610                                         "uid_contactid_commented" => array("uid","contact-id","commented"),
1611                                         "uid_contactid_created" => array("uid","contact-id","created"),
1612                                         "uid_created" => array("uid","created"),
1613                                         "uid_commented" => array("uid","commented"),
1614                                         "uid_wall_created" => array("uid","wall","created"),
1615                                         )
1616                         );
1617         $database["tokens"] = array(
1618                         "fields" => array(
1619                                         "id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
1620                                         "secret" => array("type" => "text"),
1621                                         "client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
1622                                         "expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1623                                         "scope" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
1624                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1625                                         ),
1626                         "indexes" => array(
1627                                         "PRIMARY" => array("id"),
1628                                         )
1629                         );
1630         $database["user"] = array(
1631                         "fields" => array(
1632                                         "uid" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1633                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1634                                         "username" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1635                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1636                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1637                                         "email" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1638                                         "openid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1639                                         "timezone" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
1640                                         "language" => array("type" => "varchar(32)", "not null" => "1", "default" => "en"),
1641                                         "register_date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1642                                         "login_date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1643                                         "default-location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1644                                         "allow_location" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1645                                         "theme" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1646                                         "pubkey" => array("type" => "text"),
1647                                         "prvkey" => array("type" => "text"),
1648                                         "spubkey" => array("type" => "text"),
1649                                         "sprvkey" => array("type" => "text"),
1650                                         "verified" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1651                                         "blocked" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1652                                         "blockwall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1653                                         "hidewall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1654                                         "blocktags" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1655                                         "unkmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1656                                         "cntunkmail" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1657                                         "notify-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "65535"),
1658                                         "page-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1659                                         "account-type" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1660                                         "prvnets" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1661                                         "pwdreset" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1662                                         "maxreq" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1663                                         "expire" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1664                                         "account_removed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1665                                         "account_expired" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1666                                         "account_expires_on" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1667                                         "expire_notification_sent" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1668                                         "service_class" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1669                                         "def_gid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1670                                         "allow_cid" => array("type" => "mediumtext"),
1671                                         "allow_gid" => array("type" => "mediumtext"),
1672                                         "deny_cid" => array("type" => "mediumtext"),
1673                                         "deny_gid" => array("type" => "mediumtext"),
1674                                         "openidserver" => array("type" => "text"),
1675                                         ),
1676                         "indexes" => array(
1677                                         "PRIMARY" => array("uid"),
1678                                         "nickname" => array("nickname(32)"),
1679                                         )
1680                         );
1681         $database["userd"] = array(
1682                         "fields" => array(
1683                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1684                                         "username" => array("type" => "varchar(255)", "not null" => "1"),
1685                                         ),
1686                         "indexes" => array(
1687                                         "PRIMARY" => array("id"),
1688                                         "username" => array("username(32)"),
1689                                         )
1690                         );
1691         $database["workerqueue"] = array(
1692                         "fields" => array(
1693                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1694                                         "parameter" => array("type" => "text"),
1695                                         "priority" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1696                                         "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1697                                         "pid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1698                                         "executed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
1699                                         ),
1700                         "indexes" => array(
1701                                         "PRIMARY" => array("id"),
1702                                         )
1703                         );
1704
1705         return($database);
1706 }
1707
1708
1709 /*
1710  * run from command line
1711  */
1712 function dbstructure_run(&$argv, &$argc) {
1713         global $a, $db;
1714
1715         if (is_null($a)) {
1716                 $a = new App;
1717         }
1718
1719         if (is_null($db)) {
1720                 @include(".htconfig.php");
1721                 require_once("include/dba.php");
1722                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
1723                         unset($db_host, $db_user, $db_pass, $db_data);
1724         }
1725
1726         if ($argc==2) {
1727                 switch ($argv[1]) {
1728                         case "dryrun":
1729                                 update_structure(true, false);
1730                                 return;
1731                         case "update":
1732                                 update_structure(true, true);
1733
1734                                 $build = get_config('system','build');
1735                                 if (!x($build)) {
1736                                         set_config('system','build',DB_UPDATE_VERSION);
1737                                         $build = DB_UPDATE_VERSION;
1738                                 }
1739
1740                                 $stored = intval($build);
1741                                 $current = intval(DB_UPDATE_VERSION);
1742
1743                                 // run any left update_nnnn functions in update.php
1744                                 for ($x = $stored; $x < $current; $x ++) {
1745                                         $r = run_update_function($x);
1746                                         if (!$r) break;
1747                                 }
1748
1749                                 set_config('system','build',DB_UPDATE_VERSION);
1750                                 return;
1751                         case "dumpsql":
1752                                 print_structure(db_definition());
1753                                 return;
1754                         case "toinnodb":
1755                                 convert_to_innodb();
1756                                 return;
1757                 }
1758         }
1759
1760
1761         // print help
1762         echo $argv[0]." <command>\n";
1763         echo "\n";
1764         echo "Commands:\n";
1765         echo "dryrun            show database update schema queries without running them\n";
1766         echo "update            update database schema\n";
1767         echo "dumpsql           dump database schema\n";
1768         echo "toinnodb          convert all tables from MyISAM to InnoDB\n";
1769         return;
1770
1771 }
1772
1773 if (array_search(__file__,get_included_files())===0) {
1774         dbstructure_run($_SERVER["argv"],$_SERVER["argc"]);
1775         killme();
1776 }