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