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