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