Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1800 lines
83KB

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