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