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