]> git.mxchange.org Git - friendica.git/blob - include/dbstructure.php
DE update to the translation
[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                                         "hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
690                                         "nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
691                                         "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
692                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
693                                         "notify" => array("type" => "text"),
694                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
695                                         "generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
696                                         "server_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
697                                         ),
698                         "indexes" => array(
699                                         "PRIMARY" => array("id"),
700                                         "nurl" => array("nurl"),
701                                         "name" => array("name"),
702                                         "nick" => array("nick"),
703                                         "addr" => array("addr"),
704                                         "updated" => array("updated"),
705                                         )
706                         );
707         $database["glink"] = array(
708                         "fields" => array(
709                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
710                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
711                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
712                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
713                                         "zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
714                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
715                                         ),
716                         "indexes" => array(
717                                         "PRIMARY" => array("id"),
718                                         "cid_uid_gcid_zcid" => array("cid","uid","gcid","zcid"),
719                                         "gcid" => array("gcid"),
720                                         "zcid" => array("zcid"),
721                                         )
722                         );
723         $database["group"] = array(
724                         "fields" => array(
725                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
726                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
727                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
728                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
729                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
730                                         ),
731                         "indexes" => array(
732                                         "PRIMARY" => array("id"),
733                                         "uid" => array("uid"),
734                                         )
735                         );
736         $database["group_member"] = array(
737                         "fields" => array(
738                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
739                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
740                                         "gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
741                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
742                                         ),
743                         "indexes" => array(
744                                         "PRIMARY" => array("id"),
745                                         "uid_gid_contactid" => array("uid","gid","contact-id"),
746                                         )
747                         );
748         $database["gserver"] = array(
749                         "fields" => array(
750                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
751                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
752                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
753                                         "version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
754                                         "site_name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
755                                         "info" => array("type" => "text"),
756                                         "register_policy" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
757                                         "poco" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
758                                         "noscrape" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
759                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
760                                         "platform" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
761                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
762                                         "last_poco_query" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
763                                         "last_contact" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
764                                         "last_failure" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
765                                         ),
766                         "indexes" => array(
767                                         "PRIMARY" => array("id"),
768                                         "nurl" => array("nurl"),
769                                         )
770                         );
771         $database["hook"] = array(
772                         "fields" => array(
773                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
774                                         "hook" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
775                                         "file" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
776                                         "function" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
777                                         "priority" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
778                                         ),
779                         "indexes" => array(
780                                         "PRIMARY" => array("id"),
781                                         "hook_file_function" => array("hook(30)","file(60)","function(30)"),
782                                         )
783                         );
784         $database["intro"] = array(
785                         "fields" => array(
786                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
787                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
788                                         "fid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
789                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
790                                         "knowyou" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
791                                         "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
792                                         "note" => array("type" => "text"),
793                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
794                                         "datetime" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
795                                         "blocked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
796                                         "ignore" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
797                                         ),
798                         "indexes" => array(
799                                         "PRIMARY" => array("id"),
800                                         )
801                         );
802         $database["item"] = array(
803                         "fields" => array(
804                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
805                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
806                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
807                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
808                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
809                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
810                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
811                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
812                                         "gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
813                                         "parent" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
814                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
815                                         "extid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
816                                         "thr-parent" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
817                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
818                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
819                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
820                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
821                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
822                                         "owner-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
823                                         "owner-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
824                                         "owner-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
825                                         "owner-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
826                                         "author-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
827                                         "author-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
828                                         "author-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
829                                         "author-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
830                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
831                                         "body" => array("type" => "mediumtext"),
832                                         "app" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
833                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
834                                         "object-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
835                                         "object" => array("type" => "text"),
836                                         "target-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
837                                         "target" => array("type" => "text"),
838                                         "postopts" => array("type" => "text"),
839                                         "plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
840                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
841                                         "event-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
842                                         "tag" => array("type" => "mediumtext"),
843                                         "attach" => array("type" => "mediumtext"),
844                                         "inform" => array("type" => "mediumtext"),
845                                         "file" => array("type" => "mediumtext"),
846                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
847                                         "coord" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
848                                         "allow_cid" => array("type" => "mediumtext"),
849                                         "allow_gid" => array("type" => "mediumtext"),
850                                         "deny_cid" => array("type" => "mediumtext"),
851                                         "deny_gid" => array("type" => "mediumtext"),
852                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
853                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
854                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
855                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
856                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
857                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
858                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
859                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
860                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
861                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
862                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
863                                         "last-child" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "1"),
864                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
865                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
866                                         "rendered-hash" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
867                                         "rendered-html" => array("type" => "mediumtext"),
868                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
869                                         ),
870                         "indexes" => array(
871                                         "PRIMARY" => array("id"),
872                                         "guid" => array("guid"),
873                                         "uri" => array("uri"),
874                                         "parent" => array("parent"),
875                                         "parent-uri" => array("parent-uri"),
876                                         "extid" => array("extid"),
877                                         "uid_id" => array("uid","id"),
878                                         "uid_created" => array("uid","created"),
879                                         "uid_unseen_contactid" => array("uid","unseen","contact-id"),
880                                         "uid_network_received" => array("uid","network","received"),
881                                         "uid_received" => array("uid","received"),
882                                         "uid_network_commented" => array("uid","network","commented"),
883                                         "uid_commented" => array("uid","commented"),
884                                         "uid_title" => array("uid","title"),
885                                         "uid_thrparent" => array("uid","thr-parent"),
886                                         "uid_parenturi" => array("uid","parent-uri"),
887                                         "uid_contactid_id" => array("uid","contact-id","id"),
888                                         "uid_contactid_created" => array("uid","contact-id","created"),
889                                         "gcontactid_uid_created" => array("gcontact-id","uid","created"),
890                                         "authorid_created" => array("author-id","created"),
891                                         "ownerid_created" => array("owner-id","created"),
892                                         "wall_body" => array("wall","body(6)"),
893                                         "uid_visible_moderated_created" => array("uid","visible","moderated","created"),
894                                         "uid_uri" => array("uid","uri"),
895                                         "uid_wall_created" => array("uid","wall","created"),
896                                         "resource-id" => array("resource-id"),
897                                         "uid_type" => array("uid","type"),
898                                         "uid_starred_id" => array("uid","starred", "id"),
899                                         "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"),
900                                         "uid_wall_parent_created" => array("uid","wall","parent","created"),
901                                         "uid_type_changed" => array("uid","type","changed"),
902                                         "contactid_verb" => array("contact-id","verb"),
903                                         "deleted_changed" => array("deleted","changed"),
904                                         "uid_wall_changed" => array("uid","wall","changed"),
905                                         "uid_eventid" => array("uid","event-id"),
906                                         "uid_authorlink" => array("uid","author-link"),
907                                         "uid_ownerlink" => array("uid","owner-link"),
908                                         )
909                         );
910         $database["item_id"] = array(
911                         "fields" => array(
912                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
913                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
914                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
915                                         "sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
916                                         "service" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
917                                         ),
918                         "indexes" => array(
919                                         "PRIMARY" => array("id"),
920                                         "uid" => array("uid"),
921                                         "sid" => array("sid"),
922                                         "service" => array("service"),
923                                         "iid" => array("iid"),
924                                         )
925                         );
926         $database["locks"] = array(
927                         "fields" => array(
928                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
929                                         "name" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
930                                         "locked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
931                                         "created" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
932                                         ),
933                         "indexes" => array(
934                                         "PRIMARY" => array("id"),
935                                         )
936                         );
937         $database["mail"] = array(
938                         "fields" => array(
939                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
940                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
941                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
942                                         "from-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
943                                         "from-photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
944                                         "from-url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
945                                         "contact-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
946                                         "convid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
947                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
948                                         "body" => array("type" => "mediumtext"),
949                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
950                                         "reply" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
951                                         "replied" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
952                                         "unknown" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
953                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
954                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
955                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
956                                         ),
957                         "indexes" => array(
958                                         "PRIMARY" => array("id"),
959                                         "uid" => array("uid"),
960                                         "guid" => array("guid"),
961                                         "convid" => array("convid"),
962                                         "reply" => array("reply"),
963                                         "uri" => array("uri"),
964                                         "parent-uri" => array("parent-uri"),
965                                         )
966                         );
967         $database["mailacct"] = array(
968                         "fields" => array(
969                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
970                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
971                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
972                                         "port" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
973                                         "ssltype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
974                                         "mailbox" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
975                                         "user" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
976                                         "pass" => array("type" => "text"),
977                                         "reply_to" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
978                                         "action" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
979                                         "movetofolder" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
980                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
981                                         "last_check" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
982                                         ),
983                         "indexes" => array(
984                                         "PRIMARY" => array("id"),
985                                         )
986                         );
987         $database["manage"] = array(
988                         "fields" => array(
989                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
990                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
991                                         "mid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
992                                         ),
993                         "indexes" => array(
994                                         "PRIMARY" => array("id"),
995                                         "uid_mid" => array("uid","mid"),
996                                         )
997                         );
998         $database["notify"] = array(
999                         "fields" => array(
1000                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1001                                         "hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1002                                         "type" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1003                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1004                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1005                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1006                                         "date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1007                                         "msg" => array("type" => "mediumtext"),
1008                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1009                                         "link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1010                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1011                                         "parent" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1012                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1013                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1014                                         "otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1015                                         ),
1016                         "indexes" => array(
1017                                         "PRIMARY" => array("id"),
1018                                         "uid" => array("uid"),
1019                                         )
1020                         );
1021         $database["notify-threads"] = array(
1022                         "fields" => array(
1023                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1024                                         "notify-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1025                                         "master-parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1026                                         "parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1027                                         "receiver-uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1028                                         ),
1029                         "indexes" => array(
1030                                         "PRIMARY" => array("id"),
1031                                         "master-parent-item" => array("master-parent-item"),
1032                                         "receiver-uid" => array("receiver-uid"),
1033                                         )
1034                         );
1035         $database["oembed"] = array(
1036                         "fields" => array(
1037                                         "url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
1038                                         "content" => array("type" => "text"),
1039                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1040                                         ),
1041                         "indexes" => array(
1042                                         "PRIMARY" => array("url".db_index_suffix($charset)),
1043                                         "created" => array("created"),
1044                                         )
1045                         );
1046         $database["parsed_url"] = array(
1047                         "fields" => array(
1048                                         "url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
1049                                         "guessing" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
1050                                         "oembed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
1051                                         "content" => array("type" => "text"),
1052                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1053                                         ),
1054                         "indexes" => array(
1055                                         "PRIMARY" => array("url".db_index_suffix($charset), "guessing", "oembed"),
1056                                         "created" => array("created"),
1057                                         )
1058                         );
1059         $database["pconfig"] = array(
1060                         "fields" => array(
1061                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1062                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1063                                         "cat" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1064                                         "k" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1065                                         "v" => array("type" => "mediumtext"),
1066                                         ),
1067                         "indexes" => array(
1068                                         "PRIMARY" => array("id"),
1069                                         "uid_cat_k" => array("uid","cat(30)","k(30)"),
1070                                         )
1071                         );
1072         $database["photo"] = array(
1073                         "fields" => array(
1074                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1075                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1076                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1077                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1078                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1079                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1080                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1081                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1082                                         "desc" => array("type" => "text"),
1083                                         "album" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1084                                         "filename" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1085                                         "type" => array("type" => "varchar(128)", "not null" => "1", "default" => "image/jpeg"),
1086                                         "height" => array("type" => "smallint(6)", "not null" => "1", "default" => "0"),
1087                                         "width" => array("type" => "smallint(6)", "not null" => "1", "default" => "0"),
1088                                         "datasize" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1089                                         "data" => array("type" => "mediumblob", "not null" => "1"),
1090                                         "scale" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
1091                                         "profile" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1092                                         "allow_cid" => array("type" => "mediumtext"),
1093                                         "allow_gid" => array("type" => "mediumtext"),
1094                                         "deny_cid" => array("type" => "mediumtext"),
1095                                         "deny_gid" => array("type" => "mediumtext"),
1096                                         ),
1097                         "indexes" => array(
1098                                         "PRIMARY" => array("id"),
1099                                         "uid" => array("uid"),
1100                                         "resource-id" => array("resource-id"),
1101                                         "guid" => array("guid"),
1102                                         )
1103                         );
1104         $database["poll"] = array(
1105                         "fields" => array(
1106                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1107                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1108                                         "q0" => array("type" => "mediumtext"),
1109                                         "q1" => array("type" => "mediumtext"),
1110                                         "q2" => array("type" => "mediumtext"),
1111                                         "q3" => array("type" => "mediumtext"),
1112                                         "q4" => array("type" => "mediumtext"),
1113                                         "q5" => array("type" => "mediumtext"),
1114                                         "q6" => array("type" => "mediumtext"),
1115                                         "q7" => array("type" => "mediumtext"),
1116                                         "q8" => array("type" => "mediumtext"),
1117                                         "q9" => array("type" => "mediumtext"),
1118                                         ),
1119                         "indexes" => array(
1120                                         "PRIMARY" => array("id"),
1121                                         "uid" => array("uid"),
1122                                         )
1123                         );
1124         $database["poll_result"] = array(
1125                         "fields" => array(
1126                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1127                                         "poll_id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1128                                         "choice" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1129                                         ),
1130                         "indexes" => array(
1131                                         "PRIMARY" => array("id"),
1132                                         "poll_id" => array("poll_id"),
1133                                         "choice" => array("choice"),
1134                                         )
1135                         );
1136         $database["process"] = array(
1137                         "fields" => array(
1138                                         "pid" => array("type" => "int(10) unsigned", "not null" => "1", "primary" => "1"),
1139                                         "command" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1140                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1141                                         ),
1142                         "indexes" => array(
1143                                         "PRIMARY" => array("pid"),
1144                                         "command" => array("command"),
1145                                         )
1146                         );
1147         $database["profile"] = array(
1148                         "fields" => array(
1149                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1150                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1151                                         "profile-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1152                                         "is-default" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1153                                         "hide-friends" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1154                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1155                                         "pdesc" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1156                                         "dob" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"),
1157                                         "address" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1158                                         "locality" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1159                                         "region" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1160                                         "postal-code" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1161                                         "country-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1162                                         "hometown" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1163                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1164                                         "marital" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1165                                         "with" => array("type" => "text"),
1166                                         "howlong" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1167                                         "sexual" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1168                                         "politic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1169                                         "religion" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1170                                         "pub_keywords" => array("type" => "text"),
1171                                         "prv_keywords" => array("type" => "text"),
1172                                         "likes" => array("type" => "text"),
1173                                         "dislikes" => array("type" => "text"),
1174                                         "about" => array("type" => "text"),
1175                                         "summary" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1176                                         "music" => array("type" => "text"),
1177                                         "book" => array("type" => "text"),
1178                                         "tv" => array("type" => "text"),
1179                                         "film" => array("type" => "text"),
1180                                         "interest" => array("type" => "text"),
1181                                         "romance" => array("type" => "text"),
1182                                         "work" => array("type" => "text"),
1183                                         "education" => array("type" => "text"),
1184                                         "contact" => array("type" => "text"),
1185                                         "homepage" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1186                                         "xmpp" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1187                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1188                                         "thumb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1189                                         "publish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1190                                         "net-publish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1191                                         ),
1192                         "indexes" => array(
1193                                         "PRIMARY" => array("id"),
1194                                         "hometown" => array("hometown"),
1195                                         )
1196                         );
1197         $database["profile_check"] = array(
1198                         "fields" => array(
1199                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1200                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1201                                         "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1202                                         "dfrn_id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1203                                         "sec" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1204                                         "expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1205                                         ),
1206                         "indexes" => array(
1207                                         "PRIMARY" => array("id"),
1208                                         )
1209                         );
1210         $database["push_subscriber"] = array(
1211                         "fields" => array(
1212                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1213                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1214                                         "callback_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1215                                         "topic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1216                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1217                                         "push" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1218                                         "last_update" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1219                                         "secret" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1220                                         ),
1221                         "indexes" => array(
1222                                         "PRIMARY" => array("id"),
1223                                         )
1224                         );
1225         $database["queue"] = array(
1226                         "fields" => array(
1227                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1228                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1229                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1230                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1231                                         "last" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1232                                         "content" => array("type" => "mediumtext"),
1233                                         "batch" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1234                                         ),
1235                         "indexes" => array(
1236                                         "PRIMARY" => array("id"),
1237                                         "cid" => array("cid"),
1238                                         "created" => array("created"),
1239                                         "last" => array("last"),
1240                                         "network" => array("network"),
1241                                         "batch" => array("batch"),
1242                                         )
1243                         );
1244         $database["register"] = array(
1245                         "fields" => array(
1246                                         "id" => array("type" => "int(11) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1247                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1248                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1249                                         "uid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1250                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1251                                         "language" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1252                                         ),
1253                         "indexes" => array(
1254                                         "PRIMARY" => array("id"),
1255                                         )
1256                         );
1257         $database["search"] = array(
1258                         "fields" => array(
1259                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1260                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1261                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1262                                         ),
1263                         "indexes" => array(
1264                                         "PRIMARY" => array("id"),
1265                                         "uid" => array("uid"),
1266                                         "term" => array("term"),
1267                                         )
1268                         );
1269         $database["session"] = array(
1270                         "fields" => array(
1271                                         "id" => array("type" => "bigint(20) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1272                                         "sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1273                                         "data" => array("type" => "text"),
1274                                         "expire" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1275                                         ),
1276                         "indexes" => array(
1277                                         "PRIMARY" => array("id"),
1278                                         "sid" => array("sid"),
1279                                         "expire" => array("expire"),
1280                                         )
1281                         );
1282         $database["sign"] = array(
1283                         "fields" => array(
1284                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1285                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1286                                         "signed_text" => array("type" => "mediumtext"),
1287                                         "signature" => array("type" => "text"),
1288                                         "signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1289                                         ),
1290                         "indexes" => array(
1291                                         "PRIMARY" => array("id"),
1292                                         "iid" => array("iid"),
1293                                         )
1294                         );
1295         $database["spam"] = array(
1296                         "fields" => array(
1297                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1298                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1299                                         "spam" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1300                                         "ham" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1301                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1302                                         "date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1303                                         ),
1304                         "indexes" => array(
1305                                         "PRIMARY" => array("id"),
1306                                         "uid" => array("uid"),
1307                                         "spam" => array("spam"),
1308                                         "ham" => array("ham"),
1309                                         "term" => array("term"),
1310                                         )
1311                         );
1312         $database["term"] = array(
1313                         "fields" => array(
1314                                         "tid" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1315                                         "oid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1316                                         "otype" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1317                                         "type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1318                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1319                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1320                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1321                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1322                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1323                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1324                                         "aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1325                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1326                                         ),
1327                         "indexes" => array(
1328                                         "PRIMARY" => array("tid"),
1329                                         "oid_otype_type_term" => array("oid","otype","type","term"),
1330                                         "uid_term_tid" => array("uid","term","tid"),
1331                                         "type_term" => array("type","term"),
1332                                         "uid_otype_type_term_global_created" => array("uid","otype","type","term","global","created"),
1333                                         "otype_type_term_tid" => array("otype","type","term","tid"),
1334                                         "guid" => array("guid"),
1335                                         )
1336                         );
1337         $database["thread"] = array(
1338                         "fields" => array(
1339                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1"),
1340                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1341                                         "contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1342                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1343                                         "owner-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1344                                         "author-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1345                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1346                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1347                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1348                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1349                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1350                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1351                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1352                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1353                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1354                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1355                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1356                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1357                                         "ignored" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1358                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1359                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
1360                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1361                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1362                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1363                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1364                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1365                                         ),
1366                         "indexes" => array(
1367                                         "PRIMARY" => array("iid"),
1368                                         "created" => array("created"),
1369                                         "commented" => array("commented"),
1370                                         "uid_network_commented" => array("uid","network","commented"),
1371                                         "uid_network_created" => array("uid","network","created"),
1372                                         "uid_contactid_commented" => array("uid","contact-id","commented"),
1373                                         "uid_contactid_created" => array("uid","contact-id","created"),
1374                                         "uid_gcontactid_commented" => array("uid","gcontact-id","commented"),
1375                                         "uid_gcontactid_created" => array("uid","gcontact-id","created"),
1376                                         "wall_private_received" => array("wall","private","received"),
1377                                         "uid_created" => array("uid","created"),
1378                                         "uid_commented" => array("uid","commented"),
1379                                         )
1380                         );
1381         $database["tokens"] = array(
1382                         "fields" => array(
1383                                         "id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
1384                                         "secret" => array("type" => "text"),
1385                                         "client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
1386                                         "expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1387                                         "scope" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
1388                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1389                                         ),
1390                         "indexes" => array(
1391                                         "PRIMARY" => array("id"),
1392                                         )
1393                         );
1394         $database["user"] = array(
1395                         "fields" => array(
1396                                         "uid" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1397                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1398                                         "username" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1399                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1400                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1401                                         "email" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1402                                         "openid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1403                                         "timezone" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
1404                                         "language" => array("type" => "varchar(32)", "not null" => "1", "default" => "en"),
1405                                         "register_date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1406                                         "login_date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1407                                         "default-location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1408                                         "allow_location" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1409                                         "theme" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1410                                         "pubkey" => array("type" => "text"),
1411                                         "prvkey" => array("type" => "text"),
1412                                         "spubkey" => array("type" => "text"),
1413                                         "sprvkey" => array("type" => "text"),
1414                                         "verified" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1415                                         "blocked" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1416                                         "blockwall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1417                                         "hidewall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1418                                         "blocktags" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1419                                         "unkmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1420                                         "cntunkmail" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1421                                         "notify-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "65535"),
1422                                         "page-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1423                                         "account-type" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1424                                         "prvnets" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1425                                         "pwdreset" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1426                                         "maxreq" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1427                                         "expire" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1428                                         "account_removed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1429                                         "account_expired" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1430                                         "account_expires_on" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1431                                         "expire_notification_sent" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1432                                         "service_class" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1433                                         "def_gid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1434                                         "allow_cid" => array("type" => "mediumtext"),
1435                                         "allow_gid" => array("type" => "mediumtext"),
1436                                         "deny_cid" => array("type" => "mediumtext"),
1437                                         "deny_gid" => array("type" => "mediumtext"),
1438                                         "openidserver" => array("type" => "text"),
1439                                         ),
1440                         "indexes" => array(
1441                                         "PRIMARY" => array("uid"),
1442                                         "nickname" => array("nickname"),
1443                                         )
1444                         );
1445         $database["userd"] = array(
1446                         "fields" => array(
1447                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1448                                         "username" => array("type" => "varchar(255)", "not null" => "1"),
1449                                         ),
1450                         "indexes" => array(
1451                                         "PRIMARY" => array("id"),
1452                                         "username" => array("username"),
1453                                         )
1454                         );
1455         $database["workerqueue"] = array(
1456                         "fields" => array(
1457                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1458                                         "parameter" => array("type" => "text"),
1459                                         "priority" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1460                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1461                                         "pid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1462                                         "executed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1463                                         ),
1464                         "indexes" => array(
1465                                         "PRIMARY" => array("id"),
1466                                         "created" => array("created"),
1467                                         )
1468                         );
1469
1470         return($database);
1471 }
1472
1473
1474 /*
1475  * run from command line
1476  */
1477 function dbstructure_run(&$argv, &$argc) {
1478         global $a, $db;
1479
1480         if(is_null($a)){
1481                 $a = new App;
1482         }
1483
1484         if(is_null($db)) {
1485                 @include(".htconfig.php");
1486                 require_once("include/dba.php");
1487                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
1488                         unset($db_host, $db_user, $db_pass, $db_data);
1489         }
1490
1491         if ($argc==2) {
1492                 switch ($argv[1]) {
1493                         case "update":
1494                                 update_structure(true, true);
1495                                 set_config('system','build',DB_UPDATE_VERSION);
1496                                 return;
1497                         case "dumpsql":
1498                                 // For the dump that is used to create the database.sql we always assume utfmb4
1499                                 $charset = "utf8mb4";
1500                                 print_structure(db_definition($charset), $charset);
1501                                 return;
1502                 }
1503         }
1504
1505
1506         // print help
1507         echo $argv[0]." <command>\n";
1508         echo "\n";
1509         echo "commands:\n";
1510         echo "update            update database schema\n";
1511         echo "dumpsql           dump database schema\n";
1512         return;
1513
1514
1515
1516
1517 }
1518
1519 if (array_search(__file__,get_included_files())===0){
1520         dbstructure_run($_SERVER["argv"],$_SERVER["argc"]);
1521         killme();
1522 }