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