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