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