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