]> git.mxchange.org Git - friendica.git/blob - include/dbstructure.php
DB Version was forgotten ...
[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                                         )
512                         );
513         $database["conv"] = array(
514                         "fields" => array(
515                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
516                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
517                                         "recips" => array("type" => "mediumtext", "not null" => "1"),
518                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
519                                         "creator" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
520                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
521                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
522                                         "subject" => array("type" => "mediumtext", "not null" => "1"),
523                                         ),
524                         "indexes" => array(
525                                         "PRIMARY" => array("id"),
526                                         "uid" => array("uid"),
527                                         )
528                         );
529         $database["deliverq"] = array(
530                         "fields" => array(
531                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
532                                         "cmd" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
533                                         "item" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
534                                         "contact" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
535                                         ),
536                         "indexes" => array(
537                                         "PRIMARY" => array("id"),
538                                         )
539                         );
540         $database["dsprphotoq"] = array(
541                         "fields" => array(
542                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
543                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
544                                         "msg" => array("type" => "mediumtext", "not null" => "1"),
545                                         "attempt" => array("type" => "tinyint(4)", "not null" => "1", "default" => "0"),
546                                         ),
547                         "indexes" => array(
548                                         "PRIMARY" => array("id"),
549                                         )
550                         );
551         $database["event"] = array(
552                         "fields" => array(
553                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
554                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
555                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
556                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
557                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
558                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
559                                         "start" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
560                                         "finish" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
561                                         "summary" => array("type" => "text", "not null" => "1"),
562                                         "desc" => array("type" => "text", "not null" => "1"),
563                                         "location" => array("type" => "text", "not null" => "1"),
564                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
565                                         "nofinish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
566                                         "adjust" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
567                                         "ignore" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
568                                         "allow_cid" => array("type" => "mediumtext", "not null" => "1"),
569                                         "allow_gid" => array("type" => "mediumtext", "not null" => "1"),
570                                         "deny_cid" => array("type" => "mediumtext", "not null" => "1"),
571                                         "deny_gid" => array("type" => "mediumtext", "not null" => "1"),
572                                         ),
573                         "indexes" => array(
574                                         "PRIMARY" => array("id"),
575                                         "uid" => array("uid"),
576                                         )
577                         );
578         $database["fcontact"] = array(
579                         "fields" => array(
580                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
581                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
582                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
583                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
584                                         "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
585                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
586                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
587                                         "batch" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
588                                         "notify" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
589                                         "poll" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
590                                         "confirm" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
591                                         "priority" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
592                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
593                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
594                                         "pubkey" => array("type" => "text", "not null" => "1"),
595                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
596                                         ),
597                         "indexes" => array(
598                                         "PRIMARY" => array("id"),
599                                         "addr" => array("addr"),
600                                         )
601                         );
602         $database["ffinder"] = array(
603                         "fields" => array(
604                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
605                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
606                                         "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
607                                         "fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
608                                         ),
609                         "indexes" => array(
610                                         "PRIMARY" => array("id"),
611                                         )
612                         );
613         $database["fserver"] = array(
614                         "fields" => array(
615                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
616                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
617                                         "posturl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
618                                         "key" => array("type" => "text", "not null" => "1"),
619                                         ),
620                         "indexes" => array(
621                                         "PRIMARY" => array("id"),
622                                         "server" => array("server"),
623                                         )
624                         );
625         $database["fsuggest"] = array(
626                         "fields" => array(
627                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
628                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
629                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
630                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
631                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
632                                         "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
633                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
634                                         "note" => array("type" => "text", "not null" => "1"),
635                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
636                                         ),
637                         "indexes" => array(
638                                         "PRIMARY" => array("id"),
639                                         )
640                         );
641         $database["gcign"] = array(
642                         "fields" => array(
643                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
644                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
645                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
646                                         ),
647                         "indexes" => array(
648                                         "PRIMARY" => array("id"),
649                                         "uid" => array("uid"),
650                                         "gcid" => array("gcid"),
651                                         )
652                         );
653         $database["gcontact"] = array(
654                         "fields" => array(
655                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
656                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
657                                         "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
658                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
659                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
660                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
661                                         "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
662                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
663                                         "updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
664                                         "last_contact" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
665                                         "last_failure" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
666                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
667                                         "about" => array("type" => "text", "not null" => "1"),
668                                         "keywords" => array("type" => "text", "not null" => "1"),
669                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
670                                         "birthday" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"),
671                                         "community" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
672                                         "hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
673                                         "nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
674                                         "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
675                                         "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
676                                         "notify" => array("type" => "text", "not null" => "1"),
677                                         "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
678                                         "generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
679                                         "server_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
680                                         ),
681                         "indexes" => array(
682                                         "PRIMARY" => array("id"),
683                                         "nurl" => array("nurl"),
684                                         "updated" => array("updated"),
685                                         )
686                         );
687         $database["glink"] = array(
688                         "fields" => array(
689                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
690                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
691                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
692                                         "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
693                                         "zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
694                                         "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
695                                         ),
696                         "indexes" => array(
697                                         "PRIMARY" => array("id"),
698                                         "cid_uid_gcid_zcid" => array("cid","uid","gcid","zcid"),
699                                         "gcid" => array("gcid"),
700                                         "zcid" => array("zcid"),
701                                         )
702                         );
703         $database["group"] = array(
704                         "fields" => array(
705                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
706                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
707                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
708                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
709                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
710                                         ),
711                         "indexes" => array(
712                                         "PRIMARY" => array("id"),
713                                         "uid" => array("uid"),
714                                         )
715                         );
716         $database["group_member"] = array(
717                         "fields" => array(
718                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
719                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
720                                         "gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
721                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
722                                         ),
723                         "indexes" => array(
724                                         "PRIMARY" => array("id"),
725                                         "uid_gid_contactid" => array("uid","gid","contact-id"),
726                                         )
727                         );
728         $database["gserver"] = array(
729                         "fields" => array(
730                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
731                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
732                                         "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
733                                         "version" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
734                                         "site_name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
735                                         "info" => array("type" => "text", "not null" => "1"),
736                                         "register_policy" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
737                                         "poco" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
738                                         "noscrape" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
739                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
740                                         "platform" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
741                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
742                                         "last_poco_query" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
743                                         "last_contact" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
744                                         "last_failure" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
745                                         ),
746                         "indexes" => array(
747                                         "PRIMARY" => array("id"),
748                                         "nurl" => array("nurl"),
749                                         )
750                         );
751         $database["guid"] = array(
752                         "fields" => array(
753                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
754                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
755                                         "plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
756                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
757                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
758                                         ),
759                         "indexes" => array(
760                                         "PRIMARY" => array("id"),
761                                         "guid" => array("guid"),
762                                         "plink" => array("plink"),
763                                         "uri" => array("uri"),
764                                         )
765                         );
766         $database["hook"] = array(
767                         "fields" => array(
768                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
769                                         "hook" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
770                                         "file" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
771                                         "function" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
772                                         "priority" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
773                                         ),
774                         "indexes" => array(
775                                         "PRIMARY" => array("id"),
776                                         "hook_file_function" => array("hook(30)","file(60)","function(30)"),
777                                         )
778                         );
779         $database["intro"] = array(
780                         "fields" => array(
781                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
782                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
783                                         "fid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
784                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
785                                         "knowyou" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
786                                         "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
787                                         "note" => array("type" => "text", "not null" => "1"),
788                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
789                                         "datetime" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
790                                         "blocked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
791                                         "ignore" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
792                                         ),
793                         "indexes" => array(
794                                         "PRIMARY" => array("id"),
795                                         )
796                         );
797         $database["item"] = array(
798                         "fields" => array(
799                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
800                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
801                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
802                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
803                                         "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
804                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
805                                         "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
806                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
807                                         "gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
808                                         "parent" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
809                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
810                                         "extid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
811                                         "thr-parent" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
812                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
813                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
814                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
815                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
816                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
817                                         "owner-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
818                                         "owner-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
819                                         "owner-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
820                                         "author-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
821                                         "author-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
822                                         "author-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
823                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
824                                         "body" => array("type" => "mediumtext", "not null" => "1"),
825                                         "app" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
826                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
827                                         "object-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
828                                         "object" => array("type" => "text", "not null" => "1"),
829                                         "target-type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
830                                         "target" => array("type" => "text", "not null" => "1"),
831                                         "postopts" => array("type" => "text", "not null" => "1"),
832                                         "plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
833                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
834                                         "event-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
835                                         "tag" => array("type" => "mediumtext", "not null" => "1"),
836                                         "attach" => array("type" => "mediumtext", "not null" => "1"),
837                                         "inform" => array("type" => "mediumtext", "not null" => "1"),
838                                         "file" => array("type" => "mediumtext", "not null" => "1"),
839                                         "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
840                                         "coord" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
841                                         "allow_cid" => array("type" => "mediumtext", "not null" => "1"),
842                                         "allow_gid" => array("type" => "mediumtext", "not null" => "1"),
843                                         "deny_cid" => array("type" => "mediumtext", "not null" => "1"),
844                                         "deny_gid" => array("type" => "mediumtext", "not null" => "1"),
845                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
846                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
847                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
848                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
849                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
850                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
851                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
852                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
853                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
854                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
855                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
856                                         "last-child" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "1"),
857                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
858                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
859                                         "rendered-hash" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
860                                         "rendered-html" => array("type" => "mediumtext", "not null" => "1"),
861                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
862                                         ),
863                         "indexes" => array(
864                                         "PRIMARY" => array("id"),
865                                         "guid" => array("guid"),
866                                         "uri" => array("uri"),
867                                         "parent" => array("parent"),
868                                         "parent-uri" => array("parent-uri"),
869                                         "extid" => array("extid"),
870                                         "uid_id" => array("uid","id"),
871                                         "uid_created" => array("uid","created"),
872                                         "uid_unseen" => array("uid","unseen"),
873                                         "uid_network_received" => array("uid","network","received"),
874                                         "uid_received" => array("uid","received"),
875                                         "uid_network_commented" => array("uid","network","commented"),
876                                         "uid_commented" => array("uid","commented"),
877                                         "uid_title" => array("uid","title"),
878                                         "uid_thrparent" => array("uid","thr-parent"),
879                                         "uid_parenturi" => array("uid","parent-uri"),
880                                         "uid_contactid_created" => array("uid","contact-id","created"),
881                                         "gcontactid_uid_created" => array("gcontact-id","uid","created"),
882                                         "wall_body" => array("wall","body(6)"),
883                                         "uid_visible_moderated_created" => array("uid","visible","moderated","created"),
884                                         "uid_uri" => array("uid","uri"),
885                                         "uid_wall_created" => array("uid","wall","created"),
886                                         "resource-id" => array("resource-id"),
887                                         "uid_type" => array("uid","type"),
888                                         "uid_starred" => array("uid","starred"),
889                                         "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"),
890                                         "uid_wall_parent_created" => array("uid","wall","parent","created"),
891                                         "uid_type_changed" => array("uid","type","changed"),
892                                         "contactid_verb" => array("contact-id","verb"),
893                                         "deleted_changed" => array("deleted","changed"),
894                                         "uid_wall_changed" => array("uid","wall","changed"),
895                                         "uid_eventid" => array("uid","event-id"),
896                                         "uid_authorlink" => array("uid","author-link"),
897                                         "uid_ownerlink" => array("uid","owner-link"),
898                                         )
899                         );
900         $database["item_id"] = array(
901                         "fields" => array(
902                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
903                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
904                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
905                                         "sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
906                                         "service" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
907                                         ),
908                         "indexes" => array(
909                                         "PRIMARY" => array("id"),
910                                         "uid" => array("uid"),
911                                         "sid" => array("sid"),
912                                         "service" => array("service"),
913                                         "iid" => array("iid"),
914                                         )
915                         );
916         $database["locks"] = array(
917                         "fields" => array(
918                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
919                                         "name" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
920                                         "locked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
921                                         "created" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
922                                         ),
923                         "indexes" => array(
924                                         "PRIMARY" => array("id"),
925                                         )
926                         );
927         $database["mail"] = array(
928                         "fields" => array(
929                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
930                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
931                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
932                                         "from-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
933                                         "from-photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
934                                         "from-url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
935                                         "contact-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
936                                         "convid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
937                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
938                                         "body" => array("type" => "mediumtext", "not null" => "1"),
939                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
940                                         "reply" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
941                                         "replied" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
942                                         "unknown" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
943                                         "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
944                                         "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
945                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
946                                         ),
947                         "indexes" => array(
948                                         "PRIMARY" => array("id"),
949                                         "uid" => array("uid"),
950                                         "guid" => array("guid"),
951                                         "convid" => array("convid"),
952                                         "reply" => array("reply"),
953                                         "uri" => array("uri"),
954                                         "parent-uri" => array("parent-uri"),
955                                         )
956                         );
957         $database["mailacct"] = array(
958                         "fields" => array(
959                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
960                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
961                                         "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
962                                         "port" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
963                                         "ssltype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
964                                         "mailbox" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
965                                         "user" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
966                                         "pass" => array("type" => "text", "not null" => "1"),
967                                         "reply_to" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
968                                         "action" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
969                                         "movetofolder" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
970                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
971                                         "last_check" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
972                                         ),
973                         "indexes" => array(
974                                         "PRIMARY" => array("id"),
975                                         )
976                         );
977         $database["manage"] = array(
978                         "fields" => array(
979                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
980                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
981                                         "mid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
982                                         ),
983                         "indexes" => array(
984                                         "PRIMARY" => array("id"),
985                                         "uid_mid" => array("uid","mid"),
986                                         )
987                         );
988         $database["notify"] = array(
989                         "fields" => array(
990                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
991                                         "hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
992                                         "type" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
993                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
994                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
995                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
996                                         "date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
997                                         "msg" => array("type" => "mediumtext", "not null" => "1"),
998                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
999                                         "link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1000                                         "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1001                                         "parent" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1002                                         "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1003                                         "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1004                                         "otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1005                                         ),
1006                         "indexes" => array(
1007                                         "PRIMARY" => array("id"),
1008                                         "uid" => array("uid"),
1009                                         )
1010                         );
1011         $database["notify-threads"] = array(
1012                         "fields" => array(
1013                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1014                                         "notify-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1015                                         "master-parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1016                                         "parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1017                                         "receiver-uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1018                                         ),
1019                         "indexes" => array(
1020                                         "PRIMARY" => array("id"),
1021                                         "master-parent-item" => array("master-parent-item"),
1022                                         "receiver-uid" => array("receiver-uid"),
1023                                         )
1024                         );
1025         $database["oembed"] = array(
1026                         "fields" => array(
1027                                         "url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
1028                                         "content" => array("type" => "text", "not null" => "1"),
1029                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1030                                         ),
1031                         "indexes" => array(
1032                                         "PRIMARY" => array("url"),
1033                                         "created" => array("created"),
1034                                         )
1035                         );
1036         $database["parsed_url"] = array(
1037                         "fields" => array(
1038                                         "url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
1039                                         "guessing" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
1040                                         "oembed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
1041                                         "content" => array("type" => "text", "not null" => "1"),
1042                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1043                                         ),
1044                         "indexes" => array(
1045                                         "PRIMARY" => array("url", "guessing", "oembed"),
1046                                         "created" => array("created"),
1047                                         )
1048                         );
1049         $database["pconfig"] = array(
1050                         "fields" => array(
1051                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1052                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1053                                         "cat" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1054                                         "k" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1055                                         "v" => array("type" => "mediumtext", "not null" => "1"),
1056                                         ),
1057                         "indexes" => array(
1058                                         "PRIMARY" => array("id"),
1059                                         "uid_cat_k" => array("uid","cat(30)","k(30)"),
1060                                         )
1061                         );
1062         $database["photo"] = array(
1063                         "fields" => array(
1064                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1065                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1066                                         "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1067                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1068                                         "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1069                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1070                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1071                                         "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1072                                         "desc" => array("type" => "text", "not null" => "1"),
1073                                         "album" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1074                                         "filename" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1075                                         "type" => array("type" => "varchar(128)", "not null" => "1", "default" => "image/jpeg"),
1076                                         "height" => array("type" => "smallint(6)", "not null" => "1", "default" => "0"),
1077                                         "width" => array("type" => "smallint(6)", "not null" => "1", "default" => "0"),
1078                                         "datasize" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1079                                         "data" => array("type" => "mediumblob", "not null" => "1"),
1080                                         "scale" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
1081                                         "profile" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1082                                         "allow_cid" => array("type" => "mediumtext", "not null" => "1"),
1083                                         "allow_gid" => array("type" => "mediumtext", "not null" => "1"),
1084                                         "deny_cid" => array("type" => "mediumtext", "not null" => "1"),
1085                                         "deny_gid" => array("type" => "mediumtext", "not null" => "1"),
1086                                         ),
1087                         "indexes" => array(
1088                                         "PRIMARY" => array("id"),
1089                                         "uid" => array("uid"),
1090                                         "resource-id" => array("resource-id"),
1091                                         "guid" => array("guid"),
1092                                         )
1093                         );
1094         $database["poll"] = array(
1095                         "fields" => array(
1096                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1097                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1098                                         "q0" => array("type" => "mediumtext", "not null" => "1"),
1099                                         "q1" => array("type" => "mediumtext", "not null" => "1"),
1100                                         "q2" => array("type" => "mediumtext", "not null" => "1"),
1101                                         "q3" => array("type" => "mediumtext", "not null" => "1"),
1102                                         "q4" => array("type" => "mediumtext", "not null" => "1"),
1103                                         "q5" => array("type" => "mediumtext", "not null" => "1"),
1104                                         "q6" => array("type" => "mediumtext", "not null" => "1"),
1105                                         "q7" => array("type" => "mediumtext", "not null" => "1"),
1106                                         "q8" => array("type" => "mediumtext", "not null" => "1"),
1107                                         "q9" => array("type" => "mediumtext", "not null" => "1"),
1108                                         ),
1109                         "indexes" => array(
1110                                         "PRIMARY" => array("id"),
1111                                         "uid" => array("uid"),
1112                                         )
1113                         );
1114         $database["poll_result"] = array(
1115                         "fields" => array(
1116                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1117                                         "poll_id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1118                                         "choice" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1119                                         ),
1120                         "indexes" => array(
1121                                         "PRIMARY" => array("id"),
1122                                         "poll_id" => array("poll_id"),
1123                                         "choice" => array("choice"),
1124                                         )
1125                         );
1126         $database["profile"] = array(
1127                         "fields" => array(
1128                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1129                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1130                                         "profile-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1131                                         "is-default" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1132                                         "hide-friends" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1133                                         "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1134                                         "pdesc" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1135                                         "dob" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"),
1136                                         "address" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1137                                         "locality" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1138                                         "region" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1139                                         "postal-code" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1140                                         "country-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1141                                         "hometown" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1142                                         "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1143                                         "marital" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1144                                         "with" => array("type" => "text", "not null" => "1"),
1145                                         "howlong" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1146                                         "sexual" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1147                                         "politic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1148                                         "religion" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1149                                         "pub_keywords" => array("type" => "text", "not null" => "1"),
1150                                         "prv_keywords" => array("type" => "text", "not null" => "1"),
1151                                         "likes" => array("type" => "text", "not null" => "1"),
1152                                         "dislikes" => array("type" => "text", "not null" => "1"),
1153                                         "about" => array("type" => "text", "not null" => "1"),
1154                                         "summary" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1155                                         "music" => array("type" => "text", "not null" => "1"),
1156                                         "book" => array("type" => "text", "not null" => "1"),
1157                                         "tv" => array("type" => "text", "not null" => "1"),
1158                                         "film" => array("type" => "text", "not null" => "1"),
1159                                         "interest" => array("type" => "text", "not null" => "1"),
1160                                         "romance" => array("type" => "text", "not null" => "1"),
1161                                         "work" => array("type" => "text", "not null" => "1"),
1162                                         "education" => array("type" => "text", "not null" => "1"),
1163                                         "contact" => array("type" => "text", "not null" => "1"),
1164                                         "homepage" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1165                                         "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1166                                         "thumb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1167                                         "publish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1168                                         "net-publish" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1169                                         ),
1170                         "indexes" => array(
1171                                         "PRIMARY" => array("id"),
1172                                         "hometown" => array("hometown"),
1173                                         )
1174                         );
1175         $database["profile_check"] = array(
1176                         "fields" => array(
1177                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1178                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1179                                         "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1180                                         "dfrn_id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1181                                         "sec" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1182                                         "expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1183                                         ),
1184                         "indexes" => array(
1185                                         "PRIMARY" => array("id"),
1186                                         )
1187                         );
1188         $database["push_subscriber"] = array(
1189                         "fields" => array(
1190                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1191                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1192                                         "callback_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1193                                         "topic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1194                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1195                                         "push" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1196                                         "last_update" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1197                                         "secret" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1198                                         ),
1199                         "indexes" => array(
1200                                         "PRIMARY" => array("id"),
1201                                         )
1202                         );
1203         $database["queue"] = array(
1204                         "fields" => array(
1205                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1206                                         "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1207                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1208                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1209                                         "last" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1210                                         "content" => array("type" => "mediumtext", "not null" => "1"),
1211                                         "batch" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1212                                         ),
1213                         "indexes" => array(
1214                                         "PRIMARY" => array("id"),
1215                                         "cid" => array("cid"),
1216                                         "created" => array("created"),
1217                                         "last" => array("last"),
1218                                         "network" => array("network"),
1219                                         "batch" => array("batch"),
1220                                         )
1221                         );
1222         $database["register"] = array(
1223                         "fields" => array(
1224                                         "id" => array("type" => "int(11) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1225                                         "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1226                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1227                                         "uid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1228                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1229                                         "language" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
1230                                         ),
1231                         "indexes" => array(
1232                                         "PRIMARY" => array("id"),
1233                                         )
1234                         );
1235         $database["search"] = array(
1236                         "fields" => array(
1237                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1238                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1239                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1240                                         ),
1241                         "indexes" => array(
1242                                         "PRIMARY" => array("id"),
1243                                         "uid" => array("uid"),
1244                                         "term" => array("term"),
1245                                         )
1246                         );
1247         $database["session"] = array(
1248                         "fields" => array(
1249                                         "id" => array("type" => "bigint(20) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1250                                         "sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1251                                         "data" => array("type" => "text", "not null" => "1"),
1252                                         "expire" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1253                                         ),
1254                         "indexes" => array(
1255                                         "PRIMARY" => array("id"),
1256                                         "sid" => array("sid"),
1257                                         "expire" => array("expire"),
1258                                         )
1259                         );
1260         $database["sign"] = array(
1261                         "fields" => array(
1262                                         "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1263                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1264                                         "retract_iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1265                                         "signed_text" => array("type" => "mediumtext", "not null" => "1"),
1266                                         "signature" => array("type" => "text", "not null" => "1"),
1267                                         "signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1268                                         ),
1269                         "indexes" => array(
1270                                         "PRIMARY" => array("id"),
1271                                         "iid" => array("iid"),
1272                                         "retract_iid" => array("retract_iid"),
1273                                         )
1274                         );
1275         $database["spam"] = array(
1276                         "fields" => array(
1277                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1278                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1279                                         "spam" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1280                                         "ham" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1281                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1282                                         "date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1283                                         ),
1284                         "indexes" => array(
1285                                         "PRIMARY" => array("id"),
1286                                         "uid" => array("uid"),
1287                                         "spam" => array("spam"),
1288                                         "ham" => array("ham"),
1289                                         "term" => array("term"),
1290                                         )
1291                         );
1292         $database["term"] = array(
1293                         "fields" => array(
1294                                         "tid" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1295                                         "oid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1296                                         "otype" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1297                                         "type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1298                                         "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1299                                         "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1300                                         "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1301                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1302                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1303                                         "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1304                                         "aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1305                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1306                                         ),
1307                         "indexes" => array(
1308                                         "PRIMARY" => array("tid"),
1309                                         "oid_otype_type_term" => array("oid","otype","type","term"),
1310                                         "uid_term_tid" => array("uid","term","tid"),
1311                                         "type_term" => array("type","term"),
1312                                         "uid_otype_type_term_global_created" => array("uid","otype","type","term","global","created"),
1313                                         "otype_type_term_tid" => array("otype","type","term","tid"),
1314                                         "guid" => array("guid"),
1315                                         )
1316                         );
1317         $database["thread"] = array(
1318                         "fields" => array(
1319                                         "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1"),
1320                                         "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
1321                                         "contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1322                                         "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1323                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1324                                         "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1325                                         "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1326                                         "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1327                                         "changed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1328                                         "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1329                                         "private" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1330                                         "pubmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1331                                         "moderated" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1332                                         "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1333                                         "spam" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1334                                         "starred" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1335                                         "ignored" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1336                                         "bookmark" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1337                                         "unseen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "1"),
1338                                         "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1339                                         "origin" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1340                                         "forum_mode" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1341                                         "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1342                                         "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1343                                         ),
1344                         "indexes" => array(
1345                                         "PRIMARY" => array("iid"),
1346                                         "created" => array("created"),
1347                                         "commented" => array("commented"),
1348                                         "uid_network_commented" => array("uid","network","commented"),
1349                                         "uid_network_created" => array("uid","network","created"),
1350                                         "uid_contactid_commented" => array("uid","contact-id","commented"),
1351                                         "uid_contactid_created" => array("uid","contact-id","created"),
1352                                         "uid_gcontactid_commented" => array("uid","gcontact-id","commented"),
1353                                         "uid_gcontactid_created" => array("uid","gcontact-id","created"),
1354                                         "wall_private_received" => array("wall","private","received"),
1355                                         "uid_created" => array("uid","created"),
1356                                         "uid_commented" => array("uid","commented"),
1357                                         )
1358                         );
1359         $database["tokens"] = array(
1360                         "fields" => array(
1361                                         "id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
1362                                         "secret" => array("type" => "text", "not null" => "1"),
1363                                         "client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
1364                                         "expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1365                                         "scope" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
1366                                         "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1367                                         ),
1368                         "indexes" => array(
1369                                         "PRIMARY" => array("id"),
1370                                         )
1371                         );
1372         $database["user"] = array(
1373                         "fields" => array(
1374                                         "uid" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1375                                         "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
1376                                         "username" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1377                                         "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1378                                         "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1379                                         "email" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1380                                         "openid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1381                                         "timezone" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
1382                                         "language" => array("type" => "varchar(32)", "not null" => "1", "default" => "en"),
1383                                         "register_date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1384                                         "login_date" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1385                                         "default-location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1386                                         "allow_location" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1387                                         "theme" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1388                                         "pubkey" => array("type" => "text", "not null" => "1"),
1389                                         "prvkey" => array("type" => "text", "not null" => "1"),
1390                                         "spubkey" => array("type" => "text", "not null" => "1"),
1391                                         "sprvkey" => array("type" => "text", "not null" => "1"),
1392                                         "verified" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1393                                         "blocked" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1394                                         "blockwall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1395                                         "hidewall" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1396                                         "blocktags" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
1397                                         "unkmail" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1398                                         "cntunkmail" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1399                                         "notify-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "65535"),
1400                                         "page-flags" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1401                                         "prvnets" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1402                                         "pwdreset" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
1403                                         "maxreq" => array("type" => "int(11)", "not null" => "1", "default" => "10"),
1404                                         "expire" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
1405                                         "account_removed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1406                                         "account_expired" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
1407                                         "account_expires_on" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1408                                         "expire_notification_sent" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1409                                         "service_class" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
1410                                         "def_gid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1411                                         "allow_cid" => array("type" => "mediumtext", "not null" => "1"),
1412                                         "allow_gid" => array("type" => "mediumtext", "not null" => "1"),
1413                                         "deny_cid" => array("type" => "mediumtext", "not null" => "1"),
1414                                         "deny_gid" => array("type" => "mediumtext", "not null" => "1"),
1415                                         "openidserver" => array("type" => "text", "not null" => "1"),
1416                                         ),
1417                         "indexes" => array(
1418                                         "PRIMARY" => array("uid"),
1419                                         "nickname" => array("nickname"),
1420                                         )
1421                         );
1422         $database["userd"] = array(
1423                         "fields" => array(
1424                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1425                                         "username" => array("type" => "varchar(255)", "not null" => "1"),
1426                                         ),
1427                         "indexes" => array(
1428                                         "PRIMARY" => array("id"),
1429                                         "username" => array("username"),
1430                                         )
1431                         );
1432         $database["workerqueue"] = array(
1433                         "fields" => array(
1434                                         "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
1435                                         "parameter" => array("type" => "text", "not null" => "1"),
1436                                         "priority" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
1437                                         "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1438                                         "pid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
1439                                         "executed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
1440                                         ),
1441                         "indexes" => array(
1442                                         "PRIMARY" => array("id"),
1443                                         "created" => array("created"),
1444                                         )
1445                         );
1446
1447         return($database);
1448 }
1449
1450
1451 /*
1452  * run from command line
1453  */
1454 function dbstructure_run(&$argv, &$argc) {
1455         global $a, $db;
1456
1457         if(is_null($a)){
1458                 $a = new App;
1459         }
1460
1461         if(is_null($db)) {
1462                 @include(".htconfig.php");
1463                 require_once("include/dba.php");
1464                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
1465                         unset($db_host, $db_user, $db_pass, $db_data);
1466         }
1467
1468         if ($argc==2) {
1469                 switch ($argv[1]) {
1470                         case "update":
1471                                 update_structure(true, true);
1472                                 return;
1473                         case "dumpsql":
1474                                 print_structure(db_definition());
1475                                 return;
1476                 }
1477         }
1478
1479
1480         // print help
1481         echo $argv[0]." <command>\n";
1482         echo "\n";
1483         echo "commands:\n";
1484         echo "update            update database schema\n";
1485         echo "dumpsql           dump database schema\n";
1486         return;
1487
1488
1489
1490
1491 }
1492
1493 if (array_search(__file__,get_included_files())===0){
1494         dbstructure_run($_SERVER["argv"],$_SERVER["argc"]);
1495         killme();
1496 }