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.
 
 
 
 
 
 

1777 lines
79 KiB

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