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