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