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