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