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