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