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