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