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