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