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