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