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