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