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