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