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