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