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