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