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