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