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