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