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