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