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