]> git.mxchange.org Git - friendica.git/blob - include/dbstructure.php
551f254a536beec833e3b9e0c15ec05663a226fb
[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" => "text"),
445                                         "allow_gid" => array("type" => "text"),
446                                         "deny_cid" => array("type" => "text"),
447                                         "deny_gid" => array("type" => "text"),
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" => "varbinary(255)", "not null" => "1", "primary" => "1"),
468                                         "v" => array("type" => "mediumtext"),
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"),
474                                         "expire_mode_updated" => array("expire_mode", "updated"),
475                                         )
476                         );
477         $database["challenge"] = array(
478                         "fields" => array(
479                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
480                                         "challenge" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
481                                         "dfrn-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
482                                         "expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
483                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
484                                         "last_update" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
485                                         ),
486                         "indexes" => array(
487                                         "PRIMARY" => array("id"),
488                                         )
489                         );
490         $database["clients"] = array(
491                         "fields" => array(
492                                         "client_id" => array("type" => "varchar(20)", "not null" => "1", "primary" => "1"),
493                                         "pw" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
494                                         "redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
495                                         "name" => array("type" => "text"),
496                                         "icon" => array("type" => "text"),
497                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
498                                         ),
499                         "indexes" => array(
500                                         "PRIMARY" => array("client_id"),
501                                         )
502                         );
503         $database["config"] = array(
504                         "fields" => array(
505                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
506                                         "cat" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
507                                         "k" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
508                                         "v" => array("type" => "mediumtext"),
509                                         ),
510                         "indexes" => array(
511                                         "PRIMARY" => array("id"),
512                                         "cat_k" => array("UNIQUE", "cat", "k"),
513                                         )
514                         );
515         $database["contact"] = array(
516                         "fields" => array(
517                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
518                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
519                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
520                                         "self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
521                                         "remote_self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
522                                         "rel" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
523                                         "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
524                                         "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
525                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
526                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
527                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
528                                         "about" => array("type" => "text"),
529                                         "keywords" => array("type" => "text"),
530                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
531                                         "xmpp" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
532                                         "attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
533                                         "avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
534                                         "photo" => array("type" => "text"),
535                                         "thumb" => array("type" => "text"),
536                                         "micro" => array("type" => "text"),
537                                         "site-pubkey" => array("type" => "text"),
538                                         "issued-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
539                                         "dfrn-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
540                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
541                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
542                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
543                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
544                                         "pubkey" => array("type" => "text"),
545                                         "prvkey" => array("type" => "text"),
546                                         "batch" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
547                                         "request" => array("type" => "text"),
548                                         "notify" => array("type" => "text"),
549                                         "poll" => array("type" => "text"),
550                                         "confirm" => array("type" => "text"),
551                                         "poco" => array("type" => "text"),
552                                         "aes_allow" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
553                                         "ret-aes" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
554                                         "usehub" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
555                                         "subhub" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
556                                         "hub-verify" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
557                                         "last-update" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
558                                         "success_update" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
559                                         "failure_update" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
560                                         "name-date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
561                                         "uri-date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
562                                         "avatar-date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
563                                         "term-date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
564                                         "last-item" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
565                                         "priority" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
566                                         "blocked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
567                                         "readonly" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
568                                         "writable" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
569                                         "forum" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
570                                         "prv" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
571                                         "contact-type" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
572                                         "hidden" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
573                                         "archive" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
574                                         "pending" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
575                                         "rating" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
576                                         "reason" => array("type" => "text"),
577                                         "closeness" => array("type" => "tinyint(2)", "not null" => "1", "default" => "99"),
578                                         "info" => array("type" => "mediumtext"),
579                                         "profile-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
580                                         "bdyear" => array("type" => "varchar(4)", "not null" => "1", "default" => ""),
581                                         "bd" => array("type" => "date", "not null" => "1", "default" => "0000-00-00"),
582                                         "notify_new_posts" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
583                                         "fetch_further_information" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
584                                         "ffi_keyword_blacklist" => array("type" => "text"),
585                                         ),
586                         "indexes" => array(
587                                         "PRIMARY" => array("id"),
588                                         "uid_name" => array("uid", "name"),
589                                         "self_uid" => array("self", "uid"),
590                                         "alias_uid" => array("alias(32)", "uid"),
591                                         "pending_uid" => array("pending", "uid"),
592                                         "blocked_uid" => array("blocked", "uid"),
593                                         "uid_rel_network_poll" => array("uid", "rel", "network", "poll(64)", "archive"),
594                                         "uid_network_batch" => array("uid", "network", "batch(64)"),
595                                         "addr_uid" => array("addr(32)", "uid"),
596                                         "nurl_uid" => array("nurl(32)", "uid"),
597                                         "nick_uid" => array("nick(32)", "uid"),
598                                         "dfrn-id" => array("dfrn-id"),
599                                         "issued-id" => array("issued-id"),
600                                         )
601                         );
602         $database["conv"] = array(
603                         "fields" => array(
604                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
605                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
606                                         "recips" => array("type" => "text"),
607                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
608                                         "creator" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
609                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
610                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
611                                         "subject" => array("type" => "text"),
612                                         ),
613                         "indexes" => array(
614                                         "PRIMARY" => array("id"),
615                                         "uid" => array("uid"),
616                                         )
617                         );
618         $database["deliverq"] = array(
619                         "fields" => array(
620                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
621                                         "cmd" => array("type" => "varbinary(32)", "not null" => "1", "default" => ""),
622                                         "item" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
623                                         "contact" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
624                                         ),
625                         "indexes" => array(
626                                         "PRIMARY" => array("id"),
627                                         "cmd_item_contact" => array("UNIQUE", "cmd", "item", "contact"),
628                                         )
629                         );
630         $database["event"] = array(
631                         "fields" => array(
632                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
633                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
634                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
635                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
636                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
637                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
638                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
639                                         "start" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
640                                         "finish" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
641                                         "summary" => array("type" => "text"),
642                                         "desc" => array("type" => "text"),
643                                         "location" => array("type" => "text"),
644                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
645                                         "nofinish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
646                                         "adjust" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
647                                         "ignore" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
648                                         "allow_cid" => array("type" => "text"),
649                                         "allow_gid" => array("type" => "text"),
650                                         "deny_cid" => array("type" => "text"),
651                                         "deny_gid" => array("type" => "text"),
652                                         ),
653                         "indexes" => array(
654                                         "PRIMARY" => array("id"),
655                                         "uid_start" => array("uid", "start"),
656                                         )
657                         );
658         $database["fcontact"] = array(
659                         "fields" => array(
660                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
661                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
662                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
663                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
664                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
665                                         "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
666                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
667                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
668                                         "batch" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
669                                         "notify" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
670                                         "poll" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
671                                         "confirm" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
672                                         "priority" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
673                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
674                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
675                                         "pubkey" => array("type" => "text"),
676                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
677                                         ),
678                         "indexes" => array(
679                                         "PRIMARY" => array("id"),
680                                         "addr" => array("addr(32)"),
681                                         "url" => array("url"),
682                                         )
683                         );
684         $database["ffinder"] = array(
685                         "fields" => array(
686                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
687                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
688                                         "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
689                                         "fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
690                                         ),
691                         "indexes" => array(
692                                         "PRIMARY" => array("id"),
693                                         )
694                         );
695         $database["fserver"] = array(
696                         "fields" => array(
697                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
698                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
699                                         "posturl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
700                                         "key" => array("type" => "text"),
701                                         ),
702                         "indexes" => array(
703                                         "PRIMARY" => array("id"),
704                                         "server" => array("server(32)"),
705                                         )
706                         );
707         $database["fsuggest"] = array(
708                         "fields" => array(
709                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
710                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
711                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
712                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
713                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
714                                         "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
715                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
716                                         "note" => array("type" => "text"),
717                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
718                                         ),
719                         "indexes" => array(
720                                         "PRIMARY" => array("id"),
721                                         )
722                         );
723         $database["gcign"] = array(
724                         "fields" => array(
725                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
726                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
727                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
728                                         ),
729                         "indexes" => array(
730                                         "PRIMARY" => array("id"),
731                                         "uid" => array("uid"),
732                                         "gcid" => array("gcid"),
733                                         )
734                         );
735         $database["gcontact"] = array(
736                         "fields" => array(
737                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
738                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
739                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
740                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
741                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
742                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
743                                         "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
744                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
745                                         "updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
746                                         "last_contact" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
747                                         "last_failure" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
748                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
749                                         "about" => array("type" => "text"),
750                                         "keywords" => array("type" => "text"),
751                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
752                                         "birthday" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"),
753                                         "community" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
754                                         "contact-type" => array("type" => "tinyint(1)", "not null" => "1", "default" => "-1"),
755                                         "hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
756                                         "nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
757                                         "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
758                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
759                                         "notify" => array("type" => "text"),
760                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
761                                         "generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
762                                         "server_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
763                                         ),
764                         "indexes" => array(
765                                         "PRIMARY" => array("id"),
766                                         "nurl" => array("nurl(32)"),
767                                         "name" => array("name(32)"),
768                                         "nick" => array("nick(32)"),
769                                         "addr" => array("addr(32)"),
770                                         "hide_network_updated" => array("hide", "network", "updated"),
771                                         "updated" => array("updated"),
772                                         )
773                         );
774         $database["glink"] = array(
775                         "fields" => array(
776                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
777                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
778                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
779                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
780                                         "zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
781                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
782                                         ),
783                         "indexes" => array(
784                                         "PRIMARY" => array("id"),
785                                         "cid_uid_gcid_zcid" => array("UNIQUE", "cid","uid","gcid","zcid"),
786                                         "gcid" => array("gcid"),
787                                         )
788                         );
789         $database["group"] = array(
790                         "fields" => array(
791                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
792                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
793                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
794                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
795                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
796                                         ),
797                         "indexes" => array(
798                                         "PRIMARY" => array("id"),
799                                         "uid" => array("uid"),
800                                         )
801                         );
802         $database["group_member"] = array(
803                         "fields" => array(
804                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
805                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
806                                         "gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
807                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
808                                         ),
809                         "indexes" => array(
810                                         "PRIMARY" => array("id"),
811                                         "contactid" => array("contact-id"),
812                                         "gid_contactid" => array("gid", "contact-id"),
813                                         "uid_gid_contactid" => array("UNIQUE", "uid", "gid", "contact-id"),
814                                         )
815                         );
816         $database["gserver"] = array(
817                         "fields" => array(
818                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
819                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
820                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
821                                         "version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
822                                         "site_name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
823                                         "info" => array("type" => "text"),
824                                         "register_policy" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
825                                         "poco" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
826                                         "noscrape" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
827                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
828                                         "platform" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
829                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
830                                         "last_poco_query" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
831                                         "last_contact" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
832                                         "last_failure" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
833                                         ),
834                         "indexes" => array(
835                                         "PRIMARY" => array("id"),
836                                         "nurl" => array("nurl(32)"),
837                                         )
838                         );
839         $database["hook"] = array(
840                         "fields" => array(
841                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
842                                         "hook" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
843                                         "file" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
844                                         "function" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
845                                         "priority" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
846                                         ),
847                         "indexes" => array(
848                                         "PRIMARY" => array("id"),
849                                         "hook_file_function" => array("hook(30)","file(60)","function(30)"),
850                                         )
851                         );
852         $database["intro"] = array(
853                         "fields" => array(
854                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
855                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
856                                         "fid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
857                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
858                                         "knowyou" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
859                                         "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
860                                         "note" => array("type" => "text"),
861                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
862                                         "datetime" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
863                                         "blocked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
864                                         "ignore" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
865                                         ),
866                         "indexes" => array(
867                                         "PRIMARY" => array("id"),
868                                         )
869                         );
870         $database["item"] = array(
871                         "fields" => array(
872                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
873                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
874                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
875                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
876                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
877                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
878                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
879                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
880                                         "gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
881                                         "parent" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
882                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
883                                         "extid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
884                                         "thr-parent" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
885                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
886                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
887                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
888                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
889                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
890                                         "owner-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
891                                         "owner-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
892                                         "owner-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
893                                         "owner-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
894                                         "author-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
895                                         "author-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
896                                         "author-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
897                                         "author-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
898                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
899                                         "body" => array("type" => "mediumtext"),
900                                         "app" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
901                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
902                                         "object-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
903                                         "object" => array("type" => "text"),
904                                         "target-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
905                                         "target" => array("type" => "text"),
906                                         "postopts" => array("type" => "text"),
907                                         "plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
908                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
909                                         "event-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
910                                         "tag" => array("type" => "mediumtext"),
911                                         "attach" => array("type" => "mediumtext"),
912                                         "inform" => array("type" => "mediumtext"),
913                                         "file" => array("type" => "mediumtext"),
914                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
915                                         "coord" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
916                                         "allow_cid" => array("type" => "mediumtext"),
917                                         "allow_gid" => array("type" => "mediumtext"),
918                                         "deny_cid" => array("type" => "mediumtext"),
919                                         "deny_gid" => array("type" => "mediumtext"),
920                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
921                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
922                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
923                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
924                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
925                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
926                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
927                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
928                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
929                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
930                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
931                                         "last-child" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "1"),
932                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
933                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
934                                         "rendered-hash" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
935                                         "rendered-html" => array("type" => "mediumtext"),
936                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
937                                         ),
938                         "indexes" => array(
939                                         "PRIMARY" => array("id"),
940                                         "guid" => array("guid"),
941                                         "uri" => array("uri"),
942                                         "parent" => array("parent"),
943                                         "parent-uri" => array("parent-uri"),
944                                         "extid" => array("extid"),
945                                         "uid_id" => array("uid","id"),
946                                         "uid_created" => array("uid","created"),
947                                         "uid_unseen_contactid" => array("uid","unseen","contact-id"),
948                                         "uid_network_received" => array("uid","network","received"),
949                                         "uid_network_commented" => array("uid","network","commented"),
950                                         "uid_thrparent" => array("uid","thr-parent"),
951                                         "uid_parenturi" => array("uid","parent-uri"),
952                                         "uid_contactid_created" => array("uid","contact-id","created"),
953                                         "authorid_created" => array("author-id","created"),
954                                         "uid_uri" => array("uid", "uri"),
955                                         "resource-id" => array("resource-id"),
956                                         "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), //
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                                         "wall_uid_changed" => array("wall","uid","changed"),
962                                         "uid_eventid" => array("uid","event-id"),
963                                         "uid_authorlink" => array("uid","author-link"),
964                                         "uid_ownerlink" => array("uid","owner-link"),
965                                         )
966                         );
967         $database["item_id"] = array(
968                         "fields" => array(
969                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
970                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
971                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
972                                         "sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
973                                         "service" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
974                                         ),
975                         "indexes" => array(
976                                         "PRIMARY" => array("id"),
977                                         "uid" => array("uid"),
978                                         "sid" => array("sid"),
979                                         "service" => array("service(32)"),
980                                         "iid" => array("iid"),
981                                         )
982                         );
983         $database["locks"] = array(
984                         "fields" => array(
985                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
986                                         "name" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
987                                         "locked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
988                                         "created" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
989                                         ),
990                         "indexes" => array(
991                                         "PRIMARY" => array("id"),
992                                         )
993                         );
994         $database["mail"] = array(
995                         "fields" => array(
996                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
997                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
998                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
999                                         "from-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1000                                         "from-photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1001                                         "from-url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1002                                         "contact-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1003                                         "convid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1004                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1005                                         "body" => array("type" => "mediumtext"),
1006                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1007                                         "reply" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1008                                         "replied" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1009                                         "unknown" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1010                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1011                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1012                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1013                                         ),
1014                         "indexes" => array(
1015                                         "PRIMARY" => array("id"),
1016                                         "uid_seen" => array("uid", "seen"),
1017                                         "convid" => array("convid"),
1018                                         "uri" => array("uri(64)"),
1019                                         "parent-uri" => array("parent-uri(64)"),
1020                                         )
1021                         );
1022         $database["mailacct"] = array(
1023                         "fields" => array(
1024                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1025                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1026                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1027                                         "port" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1028                                         "ssltype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1029                                         "mailbox" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1030                                         "user" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1031                                         "pass" => array("type" => "text"),
1032                                         "reply_to" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1033                                         "action" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1034                                         "movetofolder" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1035                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1036                                         "last_check" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1037                                         ),
1038                         "indexes" => array(
1039                                         "PRIMARY" => array("id"),
1040                                         )
1041                         );
1042         $database["manage"] = array(
1043                         "fields" => array(
1044                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1045                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1046                                         "mid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1047                                         ),
1048                         "indexes" => array(
1049                                         "PRIMARY" => array("id"),
1050                                         "uid_mid" => array("UNIQUE", "uid","mid"),
1051                                         )
1052                         );
1053         $database["notify"] = array(
1054                         "fields" => array(
1055                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1056                                         "hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1057                                         "type" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1058                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1059                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1060                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1061                                         "date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1062                                         "msg" => array("type" => "mediumtext"),
1063                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1064                                         "link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1065                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1066                                         "parent" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1067                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1068                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1069                                         "otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1070                                         "name_cache" => array("type" => "tinytext"),
1071                                         "msg_cache" => array("type" => "mediumtext")
1072                                         ),
1073                         "indexes" => array(
1074                                         "PRIMARY" => array("id"),
1075                                         "hash_uid" => array("hash", "uid"),
1076                                         "seen_uid_date" => array("seen", "uid", "date"),
1077                                         "uid_date" => array("uid", "date"),
1078                                         "uid_type_link" => array("uid", "type", "link"),
1079                                         )
1080                         );
1081         $database["notify-threads"] = array(
1082                         "fields" => array(
1083                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1084                                         "notify-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1085                                         "master-parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1086                                         "parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1087                                         "receiver-uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1088                                         ),
1089                         "indexes" => array(
1090                                         "PRIMARY" => array("id"),
1091                                         )
1092                         );
1093         $database["oembed"] = array(
1094                         "fields" => array(
1095                                         "url" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
1096                                         "content" => array("type" => "mediumtext"),
1097                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1098                                         ),
1099                         "indexes" => array(
1100                                         "PRIMARY" => array("url"),
1101                                         "created" => array("created"),
1102                                         )
1103                         );
1104         $database["parsed_url"] = array(
1105                         "fields" => array(
1106                                         "url" => array("type" => "varbinary(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" => "mediumtext"),
1110                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1111                                         ),
1112                         "indexes" => array(
1113                                         "PRIMARY" => array("url", "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" => "varbinary(255)", "not null" => "1", "default" => ""),
1122                                         "k" => array("type" => "varbinary(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", "k"),
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_scale_created" => array("uid", "album(32)", "scale", "created"),
1160                                         "uid_album_resource-id_created" => array("uid", "album(32)", "resource-id(64)", "created"),
1161                                         "resource-id" => array("resource-id(64)"),
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" => "text"),
1169                                         "q1" => array("type" => "text"),
1170                                         "q2" => array("type" => "text"),
1171                                         "q3" => array("type" => "text"),
1172                                         "q4" => array("type" => "text"),
1173                                         "q5" => array("type" => "text"),
1174                                         "q6" => array("type" => "text"),
1175                                         "q7" => array("type" => "text"),
1176                                         "q8" => array("type" => "text"),
1177                                         "q9" => array("type" => "text"),
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" => "varbinary(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                                         "uid_is-default" => array("uid", "is-default"),
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                                         )
1328                         );
1329         $database["session"] = array(
1330                         "fields" => array(
1331                                         "id" => array("type" => "bigint(20) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1332                                         "sid" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
1333                                         "data" => array("type" => "text"),
1334                                         "expire" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1335                                         ),
1336                         "indexes" => array(
1337                                         "PRIMARY" => array("id"),
1338                                         "sid" => array("sid(64)"),
1339                                         "expire" => array("expire"),
1340                                         )
1341                         );
1342         $database["sign"] = array(
1343                         "fields" => array(
1344                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1345                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1346                                         "signed_text" => array("type" => "mediumtext"),
1347                                         "signature" => array("type" => "text"),
1348                                         "signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1349                                         ),
1350                         "indexes" => array(
1351                                         "PRIMARY" => array("id"),
1352                                         "iid" => array("iid"),
1353                                         )
1354                         );
1355         $database["spam"] = array(
1356                         "fields" => array(
1357                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1358                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1359                                         "spam" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1360                                         "ham" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1361                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1362                                         "date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1363                                         ),
1364                         "indexes" => array(
1365                                         "PRIMARY" => array("id"),
1366                                         "uid" => array("uid"),
1367                                         "spam" => array("spam"),
1368                                         "ham" => array("ham"),
1369                                         "term" => array("term"),
1370                                         )
1371                         );
1372         $database["term"] = array(
1373                         "fields" => array(
1374                                         "tid" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1375                                         "oid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1376                                         "otype" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1377                                         "type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1378                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1379                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1380                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1381                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1382                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1383                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1384                                         "aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1385                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1386                                         ),
1387                         "indexes" => array(
1388                                         "PRIMARY" => array("tid"),
1389                                         "oid_otype_type_term" => array("oid","otype","type","term"),
1390                                         "uid_otype_type_term_global_created" => array("uid","otype","type","term(32)","global","created"),
1391                                         "uid_otype_type_url" => array("uid","otype","type","url(64)"),
1392                                         "guid" => array("guid(64)"),
1393                                         )
1394                         );
1395         $database["thread"] = array(
1396                         "fields" => array(
1397                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1"),
1398                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1399                                         "contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1400                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1401                                         "owner-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1402                                         "author-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1403                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1404                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1405                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1406                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1407                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1408                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1409                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1410                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1411                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1412                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1413                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1414                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1415                                         "ignored" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1416                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1417                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
1418                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1419                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1420                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1421                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1422                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1423                                         ),
1424                         "indexes" => array(
1425                                         "PRIMARY" => array("iid"),
1426                                         "uid_network_commented" => array("uid","network","commented"),
1427                                         "uid_network_created" => array("uid","network","created"),
1428                                         "uid_contactid_commented" => array("uid","contact-id","commented"),
1429                                         "uid_contactid_created" => array("uid","contact-id","created"),
1430                                         "uid_created" => array("uid","created"),
1431                                         "uid_commented" => array("uid","commented"),
1432                                         )
1433                         );
1434         $database["tokens"] = array(
1435                         "fields" => array(
1436                                         "id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
1437                                         "secret" => array("type" => "text"),
1438                                         "client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
1439                                         "expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1440                                         "scope" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
1441                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1442                                         ),
1443                         "indexes" => array(
1444                                         "PRIMARY" => array("id"),
1445                                         )
1446                         );
1447         $database["user"] = array(
1448                         "fields" => array(
1449                                         "uid" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1450                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1451                                         "username" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1452                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1453                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1454                                         "email" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1455                                         "openid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1456                                         "timezone" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
1457                                         "language" => array("type" => "varchar(32)", "not null" => "1", "default" => "en"),
1458                                         "register_date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1459                                         "login_date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1460                                         "default-location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1461                                         "allow_location" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1462                                         "theme" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1463                                         "pubkey" => array("type" => "text"),
1464                                         "prvkey" => array("type" => "text"),
1465                                         "spubkey" => array("type" => "text"),
1466                                         "sprvkey" => array("type" => "text"),
1467                                         "verified" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1468                                         "blocked" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1469                                         "blockwall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1470                                         "hidewall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1471                                         "blocktags" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1472                                         "unkmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1473                                         "cntunkmail" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1474                                         "notify-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "65535"),
1475                                         "page-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1476                                         "account-type" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1477                                         "prvnets" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1478                                         "pwdreset" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1479                                         "maxreq" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1480                                         "expire" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1481                                         "account_removed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1482                                         "account_expired" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1483                                         "account_expires_on" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1484                                         "expire_notification_sent" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1485                                         "service_class" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1486                                         "def_gid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1487                                         "allow_cid" => array("type" => "text"),
1488                                         "allow_gid" => array("type" => "text"),
1489                                         "deny_cid" => array("type" => "text"),
1490                                         "deny_gid" => array("type" => "text"),
1491                                         "openidserver" => array("type" => "text"),
1492                                         ),
1493                         "indexes" => array(
1494                                         "PRIMARY" => array("uid"),
1495                                         "nickname" => array("nickname(32)"),
1496                                         )
1497                         );
1498         $database["userd"] = array(
1499                         "fields" => array(
1500                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1501                                         "username" => array("type" => "varchar(255)", "not null" => "1"),
1502                                         ),
1503                         "indexes" => array(
1504                                         "PRIMARY" => array("id"),
1505                                         "username" => array("username(32)"),
1506                                         )
1507                         );
1508         $database["workerqueue"] = array(
1509                         "fields" => array(
1510                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1511                                         "parameter" => array("type" => "text"),
1512                                         "priority" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1513                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1514                                         "pid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1515                                         "executed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1516                                         ),
1517                         "indexes" => array(
1518                                         "PRIMARY" => array("id"),
1519                                         )
1520                         );
1521
1522         return($database);
1523 }
1524
1525
1526 /*
1527  * run from command line
1528  */
1529 function dbstructure_run(&$argv, &$argc) {
1530         global $a, $db;
1531
1532         if(is_null($a)){
1533                 $a = new App;
1534         }
1535
1536         if(is_null($db)) {
1537                 @include(".htconfig.php");
1538                 require_once("include/dba.php");
1539                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
1540                         unset($db_host, $db_user, $db_pass, $db_data);
1541         }
1542
1543         if ($argc==2) {
1544                 switch ($argv[1]) {
1545                         case "dryrun":
1546                                 update_structure(true, false);
1547                                 return;
1548                         case "update":
1549                                 update_structure(true, true);
1550
1551                                 $build = get_config('system','build');
1552                                 if (!x($build)) {
1553                                         set_config('system','build',DB_UPDATE_VERSION);
1554                                         $build = DB_UPDATE_VERSION;
1555                                 }
1556
1557                                 $stored = intval($build);
1558                                 $current = intval(DB_UPDATE_VERSION);
1559
1560                                 // run any left update_nnnn functions in update.php
1561                                 for($x = $stored; $x < $current; $x ++) {
1562                                         $r = run_update_function($x);
1563                                         if (!$r) break;
1564                                 }
1565
1566                                 set_config('system','build',DB_UPDATE_VERSION);
1567                                 return;
1568                         case "dumpsql":
1569                                 // For the dump that is used to create the database.sql we always assume utfmb4
1570                                 $charset = "utf8mb4";
1571                                 print_structure(db_definition($charset), $charset);
1572                                 return;
1573                 }
1574         }
1575
1576
1577         // print help
1578         echo $argv[0]." <command>\n";
1579         echo "\n";
1580         echo "Commands:\n";
1581         echo "dryrun            show database update schema queries without running them\n";
1582         echo "update            update database schema\n";
1583         echo "dumpsql           dump database schema\n";
1584         return;
1585
1586 }
1587
1588 if (array_search(__file__,get_included_files())===0){
1589         dbstructure_run($_SERVER["argv"],$_SERVER["argc"]);
1590         killme();
1591 }