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