]> git.mxchange.org Git - friendica.git/blob - include/dbstructure.php
Setting for the callstack in the database query added
[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                                         )
447                         );
448         $database["challenge"] = array(
449                         "fields" => array(
450                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
451                                         "challenge" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
452                                         "dfrn-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
453                                         "expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
454                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
455                                         "last_update" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
456                                         ),
457                         "indexes" => array(
458                                         "PRIMARY" => array("id"),
459                                         )
460                         );
461         $database["clients"] = array(
462                         "fields" => array(
463                                         "client_id" => array("type" => "varchar(20)", "not null" => "1", "primary" => "1"),
464                                         "pw" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
465                                         "redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
466                                         "name" => array("type" => "text"),
467                                         "icon" => array("type" => "text"),
468                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
469                                         ),
470                         "indexes" => array(
471                                         "PRIMARY" => array("client_id"),
472                                         )
473                         );
474         $database["config"] = array(
475                         "fields" => array(
476                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
477                                         "cat" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
478                                         "k" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
479                                         "v" => array("type" => "text"),
480                                         ),
481                         "indexes" => array(
482                                         "PRIMARY" => array("id"),
483                                         "cat_k" => array("UNIQUE", "cat(30)","k(30)"),
484                                         )
485                         );
486         $database["contact"] = array(
487                         "fields" => array(
488                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
489                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
490                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
491                                         "self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
492                                         "remote_self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
493                                         "rel" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
494                                         "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
495                                         "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
496                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
497                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
498                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
499                                         "about" => array("type" => "text"),
500                                         "keywords" => array("type" => "text"),
501                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
502                                         "xmpp" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
503                                         "attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
504                                         "avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
505                                         "photo" => array("type" => "text"),
506                                         "thumb" => array("type" => "text"),
507                                         "micro" => array("type" => "text"),
508                                         "site-pubkey" => array("type" => "text"),
509                                         "issued-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
510                                         "dfrn-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
511                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
512                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
513                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
514                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
515                                         "pubkey" => array("type" => "text"),
516                                         "prvkey" => array("type" => "text"),
517                                         "batch" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
518                                         "request" => array("type" => "text"),
519                                         "notify" => array("type" => "text"),
520                                         "poll" => array("type" => "text"),
521                                         "confirm" => array("type" => "text"),
522                                         "poco" => array("type" => "text"),
523                                         "aes_allow" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
524                                         "ret-aes" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
525                                         "usehub" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
526                                         "subhub" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
527                                         "hub-verify" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
528                                         "last-update" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
529                                         "success_update" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
530                                         "failure_update" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
531                                         "name-date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
532                                         "uri-date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
533                                         "avatar-date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
534                                         "term-date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
535                                         "last-item" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
536                                         "priority" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
537                                         "blocked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
538                                         "readonly" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
539                                         "writable" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
540                                         "forum" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
541                                         "prv" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
542                                         "contact-type" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
543                                         "hidden" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
544                                         "archive" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
545                                         "pending" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
546                                         "rating" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
547                                         "reason" => array("type" => "text"),
548                                         "closeness" => array("type" => "tinyint(2)", "not null" => "1", "default" => "99"),
549                                         "info" => array("type" => "mediumtext"),
550                                         "profile-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
551                                         "bdyear" => array("type" => "varchar(4)", "not null" => "1", "default" => ""),
552                                         "bd" => array("type" => "date", "not null" => "1", "default" => "0000-00-00"),
553                                         "notify_new_posts" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
554                                         "fetch_further_information" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
555                                         "ffi_keyword_blacklist" => array("type" => "mediumtext"),
556                                         ),
557                         "indexes" => array(
558                                         "PRIMARY" => array("id"),
559                                         "uid" => array("uid"),
560                                         "addr_uid" => array("addr", "uid"),
561                                         "nurl" => array("nurl"),
562                                         )
563                         );
564         $database["conv"] = array(
565                         "fields" => array(
566                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
567                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
568                                         "recips" => array("type" => "mediumtext"),
569                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
570                                         "creator" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
571                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
572                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
573                                         "subject" => array("type" => "mediumtext"),
574                                         ),
575                         "indexes" => array(
576                                         "PRIMARY" => array("id"),
577                                         "uid" => array("uid"),
578                                         )
579                         );
580         $database["deliverq"] = array(
581                         "fields" => array(
582                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
583                                         "cmd" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
584                                         "item" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
585                                         "contact" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
586                                         ),
587                         "indexes" => array(
588                                         "PRIMARY" => array("id"),
589                                         )
590                         );
591         $database["event"] = array(
592                         "fields" => array(
593                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
594                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
595                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
596                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
597                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
598                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
599                                         "start" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
600                                         "finish" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
601                                         "summary" => array("type" => "text"),
602                                         "desc" => array("type" => "text"),
603                                         "location" => array("type" => "text"),
604                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
605                                         "nofinish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
606                                         "adjust" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
607                                         "ignore" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
608                                         "allow_cid" => array("type" => "mediumtext"),
609                                         "allow_gid" => array("type" => "mediumtext"),
610                                         "deny_cid" => array("type" => "mediumtext"),
611                                         "deny_gid" => array("type" => "mediumtext"),
612                                         ),
613                         "indexes" => array(
614                                         "PRIMARY" => array("id"),
615                                         "uid" => array("uid"),
616                                         )
617                         );
618         $database["fcontact"] = array(
619                         "fields" => array(
620                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
621                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
622                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
623                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
624                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
625                                         "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
626                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
627                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
628                                         "batch" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
629                                         "notify" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
630                                         "poll" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
631                                         "confirm" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
632                                         "priority" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
633                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
634                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
635                                         "pubkey" => array("type" => "text"),
636                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
637                                         ),
638                         "indexes" => array(
639                                         "PRIMARY" => array("id"),
640                                         "addr" => array("addr"),
641                                         )
642                         );
643         $database["ffinder"] = array(
644                         "fields" => array(
645                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
646                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
647                                         "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
648                                         "fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
649                                         ),
650                         "indexes" => array(
651                                         "PRIMARY" => array("id"),
652                                         )
653                         );
654         $database["fserver"] = array(
655                         "fields" => array(
656                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
657                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
658                                         "posturl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
659                                         "key" => array("type" => "text"),
660                                         ),
661                         "indexes" => array(
662                                         "PRIMARY" => array("id"),
663                                         "server" => array("server"),
664                                         )
665                         );
666         $database["fsuggest"] = array(
667                         "fields" => array(
668                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
669                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
670                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
671                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
672                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
673                                         "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
674                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
675                                         "note" => array("type" => "text"),
676                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
677                                         ),
678                         "indexes" => array(
679                                         "PRIMARY" => array("id"),
680                                         )
681                         );
682         $database["gcign"] = array(
683                         "fields" => array(
684                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
685                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
686                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
687                                         ),
688                         "indexes" => array(
689                                         "PRIMARY" => array("id"),
690                                         "uid" => array("uid"),
691                                         "gcid" => array("gcid"),
692                                         )
693                         );
694         $database["gcontact"] = array(
695                         "fields" => array(
696                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
697                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
698                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
699                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
700                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
701                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
702                                         "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
703                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
704                                         "updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
705                                         "last_contact" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
706                                         "last_failure" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
707                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
708                                         "about" => array("type" => "text"),
709                                         "keywords" => array("type" => "text"),
710                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
711                                         "birthday" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"),
712                                         "community" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
713                                         "contact-type" => array("type" => "tinyint(1)", "not null" => "1", "default" => "-1"),
714                                         "hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
715                                         "nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
716                                         "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
717                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
718                                         "notify" => array("type" => "text"),
719                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
720                                         "generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
721                                         "server_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
722                                         ),
723                         "indexes" => array(
724                                         "PRIMARY" => array("id"),
725                                         "nurl" => array("nurl"),
726                                         "name" => array("name"),
727                                         "nick" => array("nick"),
728                                         "addr" => array("addr"),
729                                         "updated" => array("updated"),
730                                         )
731                         );
732         $database["glink"] = array(
733                         "fields" => array(
734                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
735                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
736                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
737                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
738                                         "zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
739                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
740                                         ),
741                         "indexes" => array(
742                                         "PRIMARY" => array("id"),
743                                         "cid_uid_gcid_zcid" => array("cid","uid","gcid","zcid"),
744                                         "gcid" => array("gcid"),
745                                         "zcid" => array("zcid"),
746                                         )
747                         );
748         $database["group"] = array(
749                         "fields" => array(
750                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
751                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
752                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
753                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
754                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
755                                         ),
756                         "indexes" => array(
757                                         "PRIMARY" => array("id"),
758                                         "uid" => array("uid"),
759                                         )
760                         );
761         $database["group_member"] = array(
762                         "fields" => array(
763                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
764                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
765                                         "gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
766                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
767                                         ),
768                         "indexes" => array(
769                                         "PRIMARY" => array("id"),
770                                         "uid_gid_contactid" => array("uid","gid","contact-id"),
771                                         )
772                         );
773         $database["gserver"] = array(
774                         "fields" => array(
775                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
776                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
777                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
778                                         "version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
779                                         "site_name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
780                                         "info" => array("type" => "text"),
781                                         "register_policy" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
782                                         "poco" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
783                                         "noscrape" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
784                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
785                                         "platform" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
786                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
787                                         "last_poco_query" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
788                                         "last_contact" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
789                                         "last_failure" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
790                                         ),
791                         "indexes" => array(
792                                         "PRIMARY" => array("id"),
793                                         "nurl" => array("nurl"),
794                                         )
795                         );
796         $database["hook"] = array(
797                         "fields" => array(
798                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
799                                         "hook" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
800                                         "file" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
801                                         "function" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
802                                         "priority" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
803                                         ),
804                         "indexes" => array(
805                                         "PRIMARY" => array("id"),
806                                         "hook_file_function" => array("hook(30)","file(60)","function(30)"),
807                                         )
808                         );
809         $database["intro"] = array(
810                         "fields" => array(
811                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
812                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
813                                         "fid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
814                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
815                                         "knowyou" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
816                                         "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
817                                         "note" => array("type" => "text"),
818                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
819                                         "datetime" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
820                                         "blocked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
821                                         "ignore" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
822                                         ),
823                         "indexes" => array(
824                                         "PRIMARY" => array("id"),
825                                         )
826                         );
827         $database["item"] = array(
828                         "fields" => array(
829                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
830                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
831                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
832                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
833                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
834                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
835                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
836                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
837                                         "gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
838                                         "parent" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
839                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
840                                         "extid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
841                                         "thr-parent" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
842                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
843                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
844                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
845                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
846                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
847                                         "owner-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
848                                         "owner-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
849                                         "owner-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
850                                         "owner-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
851                                         "author-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
852                                         "author-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
853                                         "author-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
854                                         "author-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
855                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
856                                         "body" => array("type" => "mediumtext"),
857                                         "app" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
858                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
859                                         "object-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
860                                         "object" => array("type" => "text"),
861                                         "target-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
862                                         "target" => array("type" => "text"),
863                                         "postopts" => array("type" => "text"),
864                                         "plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
865                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
866                                         "event-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
867                                         "tag" => array("type" => "mediumtext"),
868                                         "attach" => array("type" => "mediumtext"),
869                                         "inform" => array("type" => "mediumtext"),
870                                         "file" => array("type" => "mediumtext"),
871                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
872                                         "coord" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
873                                         "allow_cid" => array("type" => "mediumtext"),
874                                         "allow_gid" => array("type" => "mediumtext"),
875                                         "deny_cid" => array("type" => "mediumtext"),
876                                         "deny_gid" => array("type" => "mediumtext"),
877                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
878                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
879                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
880                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
881                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
882                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
883                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
884                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
885                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
886                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
887                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
888                                         "last-child" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "1"),
889                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
890                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
891                                         "rendered-hash" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
892                                         "rendered-html" => array("type" => "mediumtext"),
893                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
894                                         ),
895                         "indexes" => array(
896                                         "PRIMARY" => array("id"),
897                                         "guid" => array("guid"),
898                                         "uri" => array("uri"),
899                                         "parent" => array("parent"),
900                                         "parent-uri" => array("parent-uri"),
901                                         "extid" => array("extid"),
902                                         "uid_id" => array("uid","id"),
903                                         "uid_created" => array("uid","created"),
904                                         "uid_unseen_contactid" => array("uid","unseen","contact-id"),
905                                         "uid_network_received" => array("uid","network","received"),
906                                         "uid_received" => array("uid","received"),
907                                         "uid_network_commented" => array("uid","network","commented"),
908                                         "uid_commented" => array("uid","commented"),
909                                         "uid_title" => array("uid","title"),
910                                         "uid_thrparent" => array("uid","thr-parent"),
911                                         "uid_parenturi" => array("uid","parent-uri"),
912                                         "uid_contactid_id" => array("uid","contact-id","id"),
913                                         "uid_contactid_created" => array("uid","contact-id","created"),
914                                         "gcontactid_uid_created" => array("gcontact-id","uid","created"),
915                                         "authorid_created" => array("author-id","created"),
916                                         "ownerid_created" => array("owner-id","created"),
917                                         "wall_body" => array("wall","body(6)"),
918                                         "uid_visible_moderated_created" => array("uid","visible","moderated","created"),
919                                         "uid_uri" => array("uid","uri"),
920                                         "uid_wall_created" => array("uid","wall","created"),
921                                         "resource-id" => array("resource-id"),
922                                         "uid_type" => array("uid","type"),
923                                         "uid_starred_id" => array("uid","starred", "id"),
924                                         "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"),
925                                         "uid_wall_parent_created" => array("uid","wall","parent","created"),
926                                         "uid_type_changed" => array("uid","type","changed"),
927                                         "contactid_verb" => array("contact-id","verb"),
928                                         "deleted_changed" => array("deleted","changed"),
929                                         "uid_wall_changed" => array("uid","wall","changed"),
930                                         "uid_eventid" => array("uid","event-id"),
931                                         "uid_authorlink" => array("uid","author-link"),
932                                         "uid_ownerlink" => array("uid","owner-link"),
933                                         )
934                         );
935         $database["item_id"] = array(
936                         "fields" => array(
937                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
938                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
939                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
940                                         "sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
941                                         "service" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
942                                         ),
943                         "indexes" => array(
944                                         "PRIMARY" => array("id"),
945                                         "uid" => array("uid"),
946                                         "sid" => array("sid"),
947                                         "service" => array("service"),
948                                         "iid" => array("iid"),
949                                         )
950                         );
951         $database["locks"] = array(
952                         "fields" => array(
953                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
954                                         "name" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
955                                         "locked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
956                                         "created" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
957                                         ),
958                         "indexes" => array(
959                                         "PRIMARY" => array("id"),
960                                         )
961                         );
962         $database["mail"] = array(
963                         "fields" => array(
964                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
965                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
966                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
967                                         "from-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
968                                         "from-photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
969                                         "from-url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
970                                         "contact-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
971                                         "convid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
972                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
973                                         "body" => array("type" => "mediumtext"),
974                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
975                                         "reply" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
976                                         "replied" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
977                                         "unknown" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
978                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
979                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
980                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
981                                         ),
982                         "indexes" => array(
983                                         "PRIMARY" => array("id"),
984                                         "uid" => array("uid"),
985                                         "guid" => array("guid"),
986                                         "convid" => array("convid"),
987                                         "reply" => array("reply"),
988                                         "uri" => array("uri"),
989                                         "parent-uri" => array("parent-uri"),
990                                         )
991                         );
992         $database["mailacct"] = array(
993                         "fields" => array(
994                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
995                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
996                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
997                                         "port" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
998                                         "ssltype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
999                                         "mailbox" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1000                                         "user" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1001                                         "pass" => array("type" => "text"),
1002                                         "reply_to" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1003                                         "action" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1004                                         "movetofolder" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1005                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1006                                         "last_check" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1007                                         ),
1008                         "indexes" => array(
1009                                         "PRIMARY" => array("id"),
1010                                         )
1011                         );
1012         $database["manage"] = array(
1013                         "fields" => array(
1014                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1015                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1016                                         "mid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1017                                         ),
1018                         "indexes" => array(
1019                                         "PRIMARY" => array("id"),
1020                                         "uid_mid" => array("uid","mid"),
1021                                         )
1022                         );
1023         $database["notify"] = array(
1024                         "fields" => array(
1025                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1026                                         "hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1027                                         "type" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1028                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1029                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1030                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1031                                         "date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1032                                         "msg" => array("type" => "mediumtext"),
1033                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1034                                         "link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1035                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1036                                         "parent" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1037                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1038                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1039                                         "otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1040                                         ),
1041                         "indexes" => array(
1042                                         "PRIMARY" => array("id"),
1043                                         "uid" => array("uid"),
1044                                         )
1045                         );
1046         $database["notify-threads"] = array(
1047                         "fields" => array(
1048                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1049                                         "notify-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1050                                         "master-parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1051                                         "parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1052                                         "receiver-uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1053                                         ),
1054                         "indexes" => array(
1055                                         "PRIMARY" => array("id"),
1056                                         "master-parent-item" => array("master-parent-item"),
1057                                         "receiver-uid" => array("receiver-uid"),
1058                                         )
1059                         );
1060         $database["oembed"] = array(
1061                         "fields" => array(
1062                                         "url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
1063                                         "content" => array("type" => "text"),
1064                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1065                                         ),
1066                         "indexes" => array(
1067                                         "PRIMARY" => array("url".db_index_suffix($charset)),
1068                                         "created" => array("created"),
1069                                         )
1070                         );
1071         $database["parsed_url"] = array(
1072                         "fields" => array(
1073                                         "url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
1074                                         "guessing" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
1075                                         "oembed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
1076                                         "content" => array("type" => "text"),
1077                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1078                                         ),
1079                         "indexes" => array(
1080                                         "PRIMARY" => array("url".db_index_suffix($charset), "guessing", "oembed"),
1081                                         "created" => array("created"),
1082                                         )
1083                         );
1084         $database["pconfig"] = array(
1085                         "fields" => array(
1086                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1087                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1088                                         "cat" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1089                                         "k" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1090                                         "v" => array("type" => "mediumtext"),
1091                                         ),
1092                         "indexes" => array(
1093                                         "PRIMARY" => array("id"),
1094                                         "uid_cat_k" => array("UNIQUE", "uid","cat(30)","k(30)"),
1095                                         )
1096                         );
1097         $database["photo"] = array(
1098                         "fields" => array(
1099                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1100                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1101                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1102                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1103                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1104                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1105                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1106                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1107                                         "desc" => array("type" => "text"),
1108                                         "album" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1109                                         "filename" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1110                                         "type" => array("type" => "varchar(128)", "not null" => "1", "default" => "image/jpeg"),
1111                                         "height" => array("type" => "smallint(6)", "not null" => "1", "default" => "0"),
1112                                         "width" => array("type" => "smallint(6)", "not null" => "1", "default" => "0"),
1113                                         "datasize" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1114                                         "data" => array("type" => "mediumblob", "not null" => "1"),
1115                                         "scale" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
1116                                         "profile" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1117                                         "allow_cid" => array("type" => "mediumtext"),
1118                                         "allow_gid" => array("type" => "mediumtext"),
1119                                         "deny_cid" => array("type" => "mediumtext"),
1120                                         "deny_gid" => array("type" => "mediumtext"),
1121                                         ),
1122                         "indexes" => array(
1123                                         "PRIMARY" => array("id"),
1124                                         "uid_contactid" => array("uid", "contact-id"),
1125                                         "uid_profile" => array("uid", "profile"),
1126                                         "uid_album_created" => array("uid", "album", "created"),
1127                                         "resource-id" => array("resource-id"),
1128                                         "guid" => array("guid"),
1129                                         )
1130                         );
1131         $database["poll"] = array(
1132                         "fields" => array(
1133                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1134                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1135                                         "q0" => array("type" => "mediumtext"),
1136                                         "q1" => array("type" => "mediumtext"),
1137                                         "q2" => array("type" => "mediumtext"),
1138                                         "q3" => array("type" => "mediumtext"),
1139                                         "q4" => array("type" => "mediumtext"),
1140                                         "q5" => array("type" => "mediumtext"),
1141                                         "q6" => array("type" => "mediumtext"),
1142                                         "q7" => array("type" => "mediumtext"),
1143                                         "q8" => array("type" => "mediumtext"),
1144                                         "q9" => array("type" => "mediumtext"),
1145                                         ),
1146                         "indexes" => array(
1147                                         "PRIMARY" => array("id"),
1148                                         "uid" => array("uid"),
1149                                         )
1150                         );
1151         $database["poll_result"] = array(
1152                         "fields" => array(
1153                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1154                                         "poll_id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1155                                         "choice" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1156                                         ),
1157                         "indexes" => array(
1158                                         "PRIMARY" => array("id"),
1159                                         "poll_id" => array("poll_id"),
1160                                         "choice" => array("choice"),
1161                                         )
1162                         );
1163         $database["process"] = array(
1164                         "fields" => array(
1165                                         "pid" => array("type" => "int(10) unsigned", "not null" => "1", "primary" => "1"),
1166                                         "command" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1167                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1168                                         ),
1169                         "indexes" => array(
1170                                         "PRIMARY" => array("pid"),
1171                                         "command" => array("command"),
1172                                         )
1173                         );
1174         $database["profile"] = array(
1175                         "fields" => array(
1176                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1177                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1178                                         "profile-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1179                                         "is-default" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1180                                         "hide-friends" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1181                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1182                                         "pdesc" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1183                                         "dob" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"),
1184                                         "address" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1185                                         "locality" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1186                                         "region" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1187                                         "postal-code" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1188                                         "country-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1189                                         "hometown" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1190                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1191                                         "marital" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1192                                         "with" => array("type" => "text"),
1193                                         "howlong" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1194                                         "sexual" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1195                                         "politic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1196                                         "religion" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1197                                         "pub_keywords" => array("type" => "text"),
1198                                         "prv_keywords" => array("type" => "text"),
1199                                         "likes" => array("type" => "text"),
1200                                         "dislikes" => array("type" => "text"),
1201                                         "about" => array("type" => "text"),
1202                                         "summary" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1203                                         "music" => array("type" => "text"),
1204                                         "book" => array("type" => "text"),
1205                                         "tv" => array("type" => "text"),
1206                                         "film" => array("type" => "text"),
1207                                         "interest" => array("type" => "text"),
1208                                         "romance" => array("type" => "text"),
1209                                         "work" => array("type" => "text"),
1210                                         "education" => array("type" => "text"),
1211                                         "contact" => array("type" => "text"),
1212                                         "homepage" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1213                                         "xmpp" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1214                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1215                                         "thumb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1216                                         "publish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1217                                         "net-publish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1218                                         ),
1219                         "indexes" => array(
1220                                         "PRIMARY" => array("id"),
1221                                         "hometown" => array("hometown"),
1222                                         )
1223                         );
1224         $database["profile_check"] = array(
1225                         "fields" => array(
1226                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1227                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1228                                         "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1229                                         "dfrn_id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1230                                         "sec" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1231                                         "expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1232                                         ),
1233                         "indexes" => array(
1234                                         "PRIMARY" => array("id"),
1235                                         )
1236                         );
1237         $database["push_subscriber"] = array(
1238                         "fields" => array(
1239                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1240                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1241                                         "callback_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1242                                         "topic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1243                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1244                                         "push" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1245                                         "last_update" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1246                                         "secret" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1247                                         ),
1248                         "indexes" => array(
1249                                         "PRIMARY" => array("id"),
1250                                         )
1251                         );
1252         $database["queue"] = array(
1253                         "fields" => array(
1254                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1255                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1256                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1257                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1258                                         "last" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1259                                         "content" => array("type" => "mediumtext"),
1260                                         "batch" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1261                                         ),
1262                         "indexes" => array(
1263                                         "PRIMARY" => array("id"),
1264                                         "cid" => array("cid"),
1265                                         "created" => array("created"),
1266                                         "last" => array("last"),
1267                                         "network" => array("network"),
1268                                         "batch" => array("batch"),
1269                                         )
1270                         );
1271         $database["register"] = array(
1272                         "fields" => array(
1273                                         "id" => array("type" => "int(11) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1274                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1275                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1276                                         "uid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1277                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1278                                         "language" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1279                                         ),
1280                         "indexes" => array(
1281                                         "PRIMARY" => array("id"),
1282                                         )
1283                         );
1284         $database["search"] = array(
1285                         "fields" => array(
1286                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1287                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1288                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1289                                         ),
1290                         "indexes" => array(
1291                                         "PRIMARY" => array("id"),
1292                                         "uid" => array("uid"),
1293                                         "term" => array("term"),
1294                                         )
1295                         );
1296         $database["session"] = array(
1297                         "fields" => array(
1298                                         "id" => array("type" => "bigint(20) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1299                                         "sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1300                                         "data" => array("type" => "text"),
1301                                         "expire" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1302                                         ),
1303                         "indexes" => array(
1304                                         "PRIMARY" => array("id"),
1305                                         "sid" => array("sid"),
1306                                         "expire" => array("expire"),
1307                                         )
1308                         );
1309         $database["sign"] = array(
1310                         "fields" => array(
1311                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1312                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1313                                         "signed_text" => array("type" => "mediumtext"),
1314                                         "signature" => array("type" => "text"),
1315                                         "signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1316                                         ),
1317                         "indexes" => array(
1318                                         "PRIMARY" => array("id"),
1319                                         "iid" => array("iid"),
1320                                         )
1321                         );
1322         $database["spam"] = array(
1323                         "fields" => array(
1324                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1325                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1326                                         "spam" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1327                                         "ham" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1328                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1329                                         "date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1330                                         ),
1331                         "indexes" => array(
1332                                         "PRIMARY" => array("id"),
1333                                         "uid" => array("uid"),
1334                                         "spam" => array("spam"),
1335                                         "ham" => array("ham"),
1336                                         "term" => array("term"),
1337                                         )
1338                         );
1339         $database["term"] = array(
1340                         "fields" => array(
1341                                         "tid" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1342                                         "oid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1343                                         "otype" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1344                                         "type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1345                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1346                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1347                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1348                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1349                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1350                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1351                                         "aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1352                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1353                                         ),
1354                         "indexes" => array(
1355                                         "PRIMARY" => array("tid"),
1356                                         "oid_otype_type_term" => array("oid","otype","type","term"),
1357                                         "uid_term_tid" => array("uid","term","tid"),
1358                                         "type_term" => array("type","term"),
1359                                         "uid_otype_type_term_global_created" => array("uid","otype","type","term","global","created"),
1360                                         "otype_type_term_tid" => array("otype","type","term","tid"),
1361                                         "uid_otype_type_url" => array("uid","otype","type","url"),
1362                                         "guid" => array("guid"),
1363                                         )
1364                         );
1365         $database["thread"] = array(
1366                         "fields" => array(
1367                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1"),
1368                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1369                                         "contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1370                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1371                                         "owner-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1372                                         "author-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1373                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1374                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1375                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1376                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1377                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1378                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1379                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1380                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1381                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1382                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1383                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1384                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1385                                         "ignored" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1386                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1387                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
1388                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1389                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1390                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1391                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1392                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1393                                         ),
1394                         "indexes" => array(
1395                                         "PRIMARY" => array("iid"),
1396                                         "created" => array("created"),
1397                                         "commented" => array("commented"),
1398                                         "uid_network_commented" => array("uid","network","commented"),
1399                                         "uid_network_created" => array("uid","network","created"),
1400                                         "uid_contactid_commented" => array("uid","contact-id","commented"),
1401                                         "uid_contactid_created" => array("uid","contact-id","created"),
1402                                         "uid_gcontactid_commented" => array("uid","gcontact-id","commented"),
1403                                         "uid_gcontactid_created" => array("uid","gcontact-id","created"),
1404                                         "wall_private_received" => array("wall","private","received"),
1405                                         "uid_created" => array("uid","created"),
1406                                         "uid_commented" => array("uid","commented"),
1407                                         )
1408                         );
1409         $database["tokens"] = array(
1410                         "fields" => array(
1411                                         "id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
1412                                         "secret" => array("type" => "text"),
1413                                         "client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
1414                                         "expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1415                                         "scope" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
1416                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1417                                         ),
1418                         "indexes" => array(
1419                                         "PRIMARY" => array("id"),
1420                                         )
1421                         );
1422         $database["user"] = array(
1423                         "fields" => array(
1424                                         "uid" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1425                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1426                                         "username" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1427                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1428                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1429                                         "email" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1430                                         "openid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1431                                         "timezone" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
1432                                         "language" => array("type" => "varchar(32)", "not null" => "1", "default" => "en"),
1433                                         "register_date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1434                                         "login_date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1435                                         "default-location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1436                                         "allow_location" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1437                                         "theme" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1438                                         "pubkey" => array("type" => "text"),
1439                                         "prvkey" => array("type" => "text"),
1440                                         "spubkey" => array("type" => "text"),
1441                                         "sprvkey" => array("type" => "text"),
1442                                         "verified" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1443                                         "blocked" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1444                                         "blockwall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1445                                         "hidewall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1446                                         "blocktags" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1447                                         "unkmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1448                                         "cntunkmail" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1449                                         "notify-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "65535"),
1450                                         "page-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1451                                         "account-type" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1452                                         "prvnets" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1453                                         "pwdreset" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1454                                         "maxreq" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1455                                         "expire" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1456                                         "account_removed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1457                                         "account_expired" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1458                                         "account_expires_on" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1459                                         "expire_notification_sent" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1460                                         "service_class" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1461                                         "def_gid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1462                                         "allow_cid" => array("type" => "mediumtext"),
1463                                         "allow_gid" => array("type" => "mediumtext"),
1464                                         "deny_cid" => array("type" => "mediumtext"),
1465                                         "deny_gid" => array("type" => "mediumtext"),
1466                                         "openidserver" => array("type" => "text"),
1467                                         ),
1468                         "indexes" => array(
1469                                         "PRIMARY" => array("uid"),
1470                                         "nickname" => array("nickname"),
1471                                         )
1472                         );
1473         $database["userd"] = array(
1474                         "fields" => array(
1475                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1476                                         "username" => array("type" => "varchar(255)", "not null" => "1"),
1477                                         ),
1478                         "indexes" => array(
1479                                         "PRIMARY" => array("id"),
1480                                         "username" => array("username"),
1481                                         )
1482                         );
1483         $database["workerqueue"] = array(
1484                         "fields" => array(
1485                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1486                                         "parameter" => array("type" => "text"),
1487                                         "priority" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1488                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1489                                         "pid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1490                                         "executed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1491                                         ),
1492                         "indexes" => array(
1493                                         "PRIMARY" => array("id"),
1494                                         "created" => array("created"),
1495                                         )
1496                         );
1497
1498         return($database);
1499 }
1500
1501
1502 /*
1503  * run from command line
1504  */
1505 function dbstructure_run(&$argv, &$argc) {
1506         global $a, $db;
1507
1508         if(is_null($a)){
1509                 $a = new App;
1510         }
1511
1512         if(is_null($db)) {
1513                 @include(".htconfig.php");
1514                 require_once("include/dba.php");
1515                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
1516                         unset($db_host, $db_user, $db_pass, $db_data);
1517         }
1518
1519         if ($argc==2) {
1520                 switch ($argv[1]) {
1521                         case "dryrun":
1522                                 update_structure(true, false);
1523                                 return;
1524                         case "update":
1525                                 update_structure(true, true);
1526
1527                                 $build = get_config('system','build');
1528                                 if (!x($build)) {
1529                                         set_config('system','build',DB_UPDATE_VERSION);
1530                                         $build = DB_UPDATE_VERSION;
1531                                 }
1532
1533                                 $stored = intval($build);
1534                                 $current = intval(DB_UPDATE_VERSION);
1535
1536                                 // run any left update_nnnn functions in update.php
1537                                 for($x = $stored; $x < $current; $x ++) {
1538                                         $r = run_update_function($x);
1539                                         if (!$r) break;
1540                                 }
1541
1542                                 set_config('system','build',DB_UPDATE_VERSION);
1543                                 return;
1544                         case "dumpsql":
1545                                 // For the dump that is used to create the database.sql we always assume utfmb4
1546                                 $charset = "utf8mb4";
1547                                 print_structure(db_definition($charset), $charset);
1548                                 return;
1549                 }
1550         }
1551
1552
1553         // print help
1554         echo $argv[0]." <command>\n";
1555         echo "\n";
1556         echo "Commands:\n";
1557         echo "dryrun            show database update schema queries without running them\n";
1558         echo "update            update database schema\n";
1559         echo "dumpsql           dump database schema\n";
1560         return;
1561
1562
1563
1564
1565 }
1566
1567 if (array_search(__file__,get_included_files())===0){
1568         dbstructure_run($_SERVER["argv"],$_SERVER["argc"]);
1569         killme();
1570 }