upgrade_2-1_postgresql.sql 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */
  2. /******************************************************************************/
  3. --- Adding new settings...
  4. /******************************************************************************/
  5. ---# Creating login history sequence.
  6. CREATE SEQUENCE {$db_prefix}member_logins_seq;
  7. ---#
  8. ---# Creating login history table.
  9. CREATE TABLE {$db_prefix}member_logins (
  10. id_login int NOT NULL default nextval('{$db_prefix}member_logins_seq'),
  11. id_member mediumint NOT NULL,
  12. time int NOT NULL,
  13. ip varchar(255) NOT NULL default '',
  14. ip2 varchar(255) NOT NULL default '',
  15. PRIMARY KEY (id_login)
  16. );
  17. ---#
  18. ---# Copying the current package backup setting...
  19. ---{
  20. if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['package_make_backups']))
  21. upgrade_query("
  22. INSERT INTO {$db_prefix}settings
  23. (variable, value)
  24. VALUES
  25. ('package_make_full_backups', '" . $modSettings['package_make_backups'] . "')");
  26. ---}
  27. ---#
  28. ---# Adding back proper support for UTF8
  29. ---{
  30. global $sourcedir;
  31. require_once($sourcedir . '/Subs-Admin.php');
  32. updateSettingsFile(array('db_character_set' => 'utf8'));
  33. upgrade_query("
  34. INSERT INTO {$db_prefix}settings
  35. (variable, value)
  36. VALUES
  37. ('global_character_set', 'UTF-8')");
  38. ---}
  39. ---#
  40. /******************************************************************************/
  41. --- Updating legacy attachments...
  42. /******************************************************************************/
  43. ---# Converting legacy attachments.
  44. ---{
  45. $request = upgrade_query("
  46. SELECT MAX(id_attach)
  47. FROM {$db_prefix}attachments");
  48. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  49. $smcFunc['db_free_result']($request);
  50. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  51. $step_progress['name'] = 'Converting legacy attachments';
  52. $step_progress['current'] = $_GET['a'];
  53. // We may be using multiple attachment directories.
  54. if (!empty($modSettings['currentAttachmentUploadDir']) && !is_array($modSettings['attachmentUploadDir']))
  55. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  56. $is_done = false;
  57. while (!$is_done)
  58. {
  59. nextSubStep($substep);
  60. $request = upgrade_query("
  61. SELECT id_attach, id_folder, filename, file_hash
  62. FROM {$db_prefix}attachments
  63. WHERE file_hash = ''
  64. LIMIT $_GET[a], 100");
  65. // Finished?
  66. if ($smcFunc['db_num_rows']($request) == 0)
  67. $is_done = true;
  68. while ($row = $smcFunc['db_fetch_assoc']($request))
  69. {
  70. // The current folder.
  71. $current_folder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
  72. // The old location of the file.
  73. $old_location = getLegacyAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder']);
  74. // The new file name.
  75. $file_hash = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], true);
  76. // And we try to move it.
  77. rename($old_location, $current_folder . '/' . $row['id_attach'] . '_' . $file_hash);
  78. // Only update thif if it was successful.
  79. if (file_exists($current_folder . '/' . $row['id_attach'] . '_' . $file_hash) && !file_exists($old_location))
  80. upgrade_query("
  81. UPDATE {$db_prefix}attachments
  82. SET file_hash = '$file_hash'
  83. WHERE id_attach = $row[id_attach]");
  84. }
  85. $smcFunc['db_free_result']($request);
  86. $_GET['a'] += 100;
  87. $step_progress['current'] = $_GET['a'];
  88. }
  89. unset($_GET['a']);
  90. ---}
  91. ---#
  92. /******************************************************************************/
  93. --- Adding support for IPv6...
  94. /******************************************************************************/
  95. ---# Adding new columns to ban items...
  96. ALTER TABLE {$db_prefix}ban_items
  97. ADD COLUMN ip_low5 smallint NOT NULL DEFAULT '0',
  98. ADD COLUMN ip_high5 smallint NOT NULL DEFAULT '0',
  99. ADD COLUMN ip_low6 smallint NOT NULL DEFAULT '0',
  100. ADD COLUMN ip_high6 smallint NOT NULL DEFAULT '0',
  101. ADD COLUMN ip_low7 smallint NOT NULL DEFAULT '0',
  102. ADD COLUMN ip_high7 smallint NOT NULL DEFAULT '0',
  103. ADD COLUMN ip_low8 smallint NOT NULL DEFAULT '0',
  104. ADD COLUMN ip_high8 smallint NOT NULL DEFAULT '0';
  105. ---#
  106. ---# Changing existing columns to ban items...
  107. ---{
  108. upgrade_query("
  109. ALTER TABLE {$db_prefix}ban_items
  110. ALTER COLUMN ip_low1 type smallint,
  111. ALTER COLUMN ip_high1 type smallint,
  112. ALTER COLUMN ip_low2 type smallint,
  113. ALTER COLUMN ip_high2 type smallint,
  114. ALTER COLUMN ip_low3 type smallint,
  115. ALTER COLUMN ip_high3 type smallint,
  116. ALTER COLUMN ip_low4 type smallint,
  117. ALTER COLUMN ip_high4 type smallint;"
  118. );
  119. upgrade_query("
  120. ALTER TABLE {$db_prefix}ban_items
  121. ALTER COLUMN ip_low1 SET DEFAULT '0',
  122. ALTER COLUMN ip_high1 SET DEFAULT '0',
  123. ALTER COLUMN ip_low2 SET DEFAULT '0',
  124. ALTER COLUMN ip_high2 SET DEFAULT '0',
  125. ALTER COLUMN ip_low3 SET DEFAULT '0',
  126. ALTER COLUMN ip_high3 SET DEFAULT '0',
  127. ALTER COLUMN ip_low4 SET DEFAULT '0',
  128. ALTER COLUMN ip_high4 SET DEFAULT '0';"
  129. );
  130. upgrade_query("
  131. ALTER TABLE {$db_prefix}ban_items
  132. ALTER COLUMN ip_low1 SET NOT NULL,
  133. ALTER COLUMN ip_high1 SET NOT NULL,
  134. ALTER COLUMN ip_low2 SET NOT NULL,
  135. ALTER COLUMN ip_high2 SET NOT NULL,
  136. ALTER COLUMN ip_low3 SET NOT NULL,
  137. ALTER COLUMN ip_high3 SET NOT NULL,
  138. ALTER COLUMN ip_low4 SET NOT NULL,
  139. ALTER COLUMN ip_high4 SET NOT NULL;"
  140. );
  141. ---}
  142. ---#
  143. /******************************************************************************/
  144. --- Adding support for <credits> tag in package manager
  145. /******************************************************************************/
  146. ---# Adding new columns to log_packages ..
  147. ALTER TABLE {$db_prefix}log_packages
  148. ADD COLUMN credits varchar(255) NOT NULL DEFAULT '';
  149. ---#
  150. /******************************************************************************/
  151. --- Adding more space for session ids
  152. /******************************************************************************/
  153. ---# Altering the session_id columns...
  154. ---{
  155. upgrade_query("
  156. ALTER TABLE {$db_prefix}log_online
  157. ALTER COLUMN session type varchar(64);
  158. ALTER TABLE {$db_prefix}log_errors
  159. ALTER COLUMN session type char(64);
  160. ALTER TABLE {$db_prefix}sessions
  161. ALTER COLUMN session_id type char(64);");
  162. upgrade_query("
  163. ALTER TABLE {$db_prefix}log_online
  164. ALTER COLUMN session SET DEFAULT '';
  165. ALTER TABLE {$db_prefix}log_errors
  166. ALTER COLUMN session SET default ' ';");
  167. upgrade_query("
  168. ALTER TABLE {$db_prefix}log_online
  169. ALTER COLUMN session SET NOT NULL;
  170. ALTER TABLE {$db_prefix}log_errors
  171. ALTER COLUMN session SET NOT NULL;
  172. ALTER TABLE {$db_prefix}sessions
  173. ALTER COLUMN session_id SET NOT NULL;");
  174. ---}
  175. ---#
  176. /******************************************************************************/
  177. --- Adding support for MOVED topics enhancements
  178. /******************************************************************************/
  179. ---# Adding new columns to topics table
  180. ---{
  181. upgrade_query("
  182. ALTER TABLE {$db_prefix}topics
  183. ADD COLUMN redirect_expires int NOT NULL DEFAULT '0'");
  184. upgrade_query("
  185. ALTER TABLE {$db_prefix}topics
  186. ADD COLUMN id_redirect_topic int NOT NULL DEFAULT '0'");
  187. ---}
  188. ---#
  189. /******************************************************************************/
  190. --- Adding new scheduled tasks
  191. /******************************************************************************/
  192. ---# Adding new scheduled tasks
  193. INSERT INTO {$db_prefix}scheduled_tasks
  194. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  195. VALUES
  196. (0, 120, 1, 'd', 0, 'remove_temp_attachments');
  197. INSERT INTO {$db_prefix}scheduled_tasks
  198. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  199. VALUES
  200. (0, 180, 1, 'd', 0, 'remove_topic_redirect');
  201. INSERT INTO {$db_prefix}scheduled_tasks
  202. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  203. VALUES
  204. (0, 240, 1, 'd', 0, 'remove_old_drafts');
  205. ---#
  206. /******************************************************************************/
  207. --- Adding support for deny boards access
  208. /******************************************************************************/
  209. ---# Adding new columns to boards...
  210. ---{
  211. upgrade_query("
  212. ALTER TABLE {$db_prefix}boards
  213. ADD COLUMN deny_member_groups varchar(255) NOT NULL DEFAULT ''");
  214. ---}
  215. ---#
  216. /******************************************************************************/
  217. --- Name changes
  218. /******************************************************************************/
  219. ---# Altering the membergroup stars to icons
  220. ---{
  221. upgrade_query("
  222. ALTER TABLE {$db_prefix}membergroups
  223. CHANGE `stars` `icons` varchar(255) NOT NULL DEFAULT ''");
  224. ---}
  225. ---#
  226. /******************************************************************************/
  227. --- Adding support for drafts
  228. /******************************************************************************/
  229. ---# Creating drafts table.
  230. CREATE TABLE {$db_prefix}user_drafts (
  231. id_draft int unsigned NOT NULL auto_increment,
  232. id_topic int unsigned NOT NULL default '0',
  233. id_board smallint unsigned NOT NULL default '0',
  234. id_reply int unsigned NOT NULL default '0',
  235. type smallint NOT NULL default '0',
  236. poster_time int unsigned NOT NULL default '0',
  237. id_member int unsigned NOT NULL default '0',
  238. subject varchar(255) NOT NULL default '',
  239. smileys_enabled smallint NOT NULL default '1',
  240. body text NOT NULL,
  241. icon varchar(16) NOT NULL default 'xx',
  242. locked smallint NOT NULL default '0',
  243. is_sticky smallint NOT NULL default '0',
  244. to_list varchar(255) NOT NULL default '',
  245. outbox smallint NOT NULL default '0',
  246. PRIMARY KEY (id_draft)
  247. );
  248. ---#
  249. ---# Adding draft permissions...
  250. ---{
  251. // We cannot do this twice
  252. if (@$modSettings['smfVersion'] < '2.1')
  253. {
  254. // Anyone who can currently post unapproved topics we assume can create drafts as well ...
  255. $request = upgrade_query("
  256. SELECT id_group, id_board, add_deny, permission
  257. FROM {$db_prefix}board_permissions
  258. WHERE permission = 'post_unapproved_topics'");
  259. $inserts = array();
  260. while ($row = mysql_fetch_assoc($request))
  261. {
  262. $inserts[] = "($row[id_group], $row[id_board], 'post_draft', $row[add_deny])";
  263. $inserts[] = "($row[id_group], $row[id_board], 'post_autosave_draft', $row[add_deny])";
  264. }
  265. mysql_free_result($request);
  266. if (!empty($inserts))
  267. upgrade_query("
  268. INSERT IGNORE INTO {$db_prefix}board_permissions
  269. (id_group, id_board, permission, add_deny)
  270. VALUES
  271. " . implode(',', $inserts));
  272. // Next we find people who can send PM's, and assume they can save pm_drafts as well
  273. $request = upgrade_query("
  274. SELECT id_group, add_deny, permission
  275. FROM {$db_prefix}permissions
  276. WHERE permission = 'pm_send'");
  277. $inserts = array();
  278. while ($row = mysql_fetch_assoc($request))
  279. {
  280. $inserts[] = "($row[id_group], 'pm_draft', $row[add_deny])";
  281. $inserts[] = "($row[id_group], 'pm_autosave_draft', $row[add_deny])";
  282. }
  283. mysql_free_result($request);
  284. if (!empty($inserts))
  285. upgrade_query("
  286. INSERT IGNORE INTO {$db_prefix}permissions
  287. (id_group, permission, add_deny)
  288. VALUES
  289. " . implode(',', $inserts));
  290. }
  291. ---}
  292. ---#