upgrade_2-1_postgresql.sql 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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(10) NOT NULL default nextval('{$db_prefix}member_logins_seq'),
  11. id_member mediumint(8) NOT NULL,
  12. time int(10) NOT NULL,
  13. ip varchar(255) NOT NULL default '',
  14. ip2 varchar(255) NOT NULL default '',
  15. PRIMARY KEY id_login(id_login)
  16. KEY id_member (id_member)
  17. KEY time (time)
  18. );
  19. ---#
  20. ---# Copying the current package backup setting...
  21. ---{
  22. if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['package_make_backups']))
  23. upgrade_query("
  24. INSERT INTO {$db_prefix}settings
  25. (variable, value)
  26. VALUES
  27. ('package_make_full_backups', '" . $modSettings['package_make_backups'] . "')");
  28. ---}
  29. ---#
  30. /******************************************************************************/
  31. --- Updating legacy attachments...
  32. /******************************************************************************/
  33. ---# Converting legacy attachments.
  34. ---{
  35. $request = upgrade_query("
  36. SELECT MAX(id_attach)
  37. FROM {$db_prefix}attachments");
  38. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  39. $smcFunc['db_free_result']($request);
  40. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  41. $step_progress['name'] = 'Converting legacy attachments';
  42. $step_progress['current'] = $_GET['a'];
  43. // We may be using multiple attachment directories.
  44. if (!empty($modSettings['currentAttachmentUploadDir']) && !is_array($modSettings['attachmentUploadDir']))
  45. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  46. $is_done = false;
  47. while (!$is_done)
  48. {
  49. nextSubStep($substep);
  50. $request = upgrade_query("
  51. SELECT id_attach, id_folder, filename, file_hash
  52. FROM {$db_prefix}attachments
  53. WHERE file_hash = ''
  54. LIMIT $_GET[a], 100");
  55. // Finished?
  56. if ($smcFunc['db_num_rows']($request) == 0)
  57. $is_done = true;
  58. while ($row = $smcFunc['db_fetch_assoc']($request))
  59. {
  60. // The current folder.
  61. $current_folder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
  62. // The old location of the file.
  63. $old_location = getLegacyAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder']);
  64. // The new file name.
  65. $file_hash = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], true);
  66. // And we try to move it.
  67. rename($old_location, $current_folder . '/' . $row['id_attach'] . '_' . $file_hash);
  68. // Only update thif if it was successful.
  69. if (file_exists($current_folder . '/' . $row['id_attach'] . '_' . $file_hash) && !file_exists($old_location))
  70. upgrade_query("
  71. UPDATE {$db_prefix}attachments
  72. SET file_hash = '$file_hash'
  73. WHERE id_attach = $row[id_attach]");
  74. }
  75. $smcFunc['db_free_result']($request);
  76. $_GET['a'] += 100;
  77. $step_progress['current'] = $_GET['a'];
  78. }
  79. unset($_GET['a']);
  80. ---}
  81. ---#
  82. /******************************************************************************/
  83. --- Adding support for IPv6...
  84. /******************************************************************************/
  85. ---# Adding new columns to ban items...
  86. ALTER TABLE {$db_prefix}ban_items
  87. ADD COLUMN ip_low5 smallint(255) unsigned NOT NULL DEFAULT '0',
  88. ADD COLUMN ip_high5 smallint(255) unsigned NOT NULL DEFAULT '0',
  89. ADD COLUMN ip_low6 smallint(255) unsigned NOT NULL DEFAULT '0',
  90. ADD COLUMN ip_high6 smallint(255) unsigned NOT NULL DEFAULT '0',
  91. ADD COLUMN ip_low7 smallint(255) unsigned NOT NULL DEFAULT '0',
  92. ADD COLUMN ip_high7 smallint(255) unsigned NOT NULL DEFAULT '0',
  93. ADD COLUMN ip_low8 smallint(255) unsigned NOT NULL DEFAULT '0',
  94. ADD COLUMN ip_high8 smallint(255) unsigned NOT NULL DEFAULT '0';
  95. ---#
  96. ---# Changing existing columns to ban items...
  97. ALTER TABLE {$db_prefix}ban_items
  98. CHANGE ip_low1 ip_low1 smallint(255) unsigned NOT NULL DEFAULT '0',
  99. CHANGE ip_high1 ip_high1 smallint(255) unsigned NOT NULL DEFAULT '0',
  100. CHANGE ip_low2 ip_low2 smallint(255) unsigned NOT NULL DEFAULT '0',
  101. CHANGE ip_high2 ip_high2 smallint(255) unsigned NOT NULL DEFAULT '0',
  102. CHANGE ip_low3 ip_low3 smallint(255) unsigned NOT NULL DEFAULT '0',
  103. CHANGE ip_high3 ip_high3 smallint(255) unsigned NOT NULL DEFAULT '0',
  104. CHANGE ip_low4 ip_low4 smallint(255) unsigned NOT NULL DEFAULT '0',
  105. CHANGE ip_high4 ip_high4 smallint(255) unsigned NOT NULL DEFAULT '0';
  106. ---#
  107. /******************************************************************************/
  108. --- Adding support for <credits> tag in package manager
  109. /******************************************************************************/
  110. ---# Adding new columns to log_packages ..
  111. ALTER TABLE {$db_prefix}log_packages
  112. ADD COLUMN credits varchar(255) NOT NULL DEFAULT '';
  113. ---#
  114. /******************************************************************************/
  115. --- Adding more space for session ids
  116. /******************************************************************************/
  117. ---# Altering the session_id columns...
  118. ALTER TABLE {$db_prefix}log_online
  119. CHANGE `session` varchar(64) NOT NULL DEFAULT '';
  120. ALTER TABLE {$db_prefix}log_errors
  121. CHANGE `session` char(64) NOT NULL default ' ';
  122. ALTER TABLE {$db_prefix}sessions
  123. CHANGE `session_id` char(64) NOT NULL default '';
  124. ---#
  125. /******************************************************************************/
  126. --- Adding new scheduled tasts
  127. /******************************************************************************/
  128. ---# Adding new Scheduled Task...
  129. INSERT INTO {$db_prefix}scheduled_tasks
  130. (next_time, time_offset, time_regularity, time_unit, disabled, task)
  131. VALUES
  132. (0, 120, 1, 'd', 0, 'remove_temp_attachments');
  133. ---#