upgrade_2-1_postgresql.sql 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. ---# Moving the cookie name to the database...
  21. ---{
  22. if (!isset($modSettings['cookie_name']))
  23. {
  24. if (empty($cookiename))
  25. $cookiename = 'SMFCookie11';
  26. upgrade_query("
  27. INSERT INTO {$db_prefix}settings
  28. (variable, value)
  29. VALUES
  30. ('cookie_name', '$cookiename')");
  31. }
  32. ---}
  33. ---#
  34. ---# Copying the current package backup setting...
  35. ---{
  36. if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['package_make_backups']))
  37. upgrade_query("
  38. INSERT INTO {$db_prefix}settings
  39. (variable, value)
  40. VALUES
  41. ('package_make_full_backups', '" . $modSettings['package_make_backups'] . "')");
  42. ---}
  43. ---#
  44. /******************************************************************************/
  45. --- Updating legacy attachments...
  46. /******************************************************************************/
  47. ---# Converting legacy attachments.
  48. ---{
  49. $request = upgrade_query("
  50. SELECT MAX(id_attach)
  51. FROM {$db_prefix}attachments");
  52. list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
  53. $smcFunc['db_free_result']($request);
  54. $_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
  55. $step_progress['name'] = 'Converting legacy attachments';
  56. $step_progress['current'] = $_GET['a'];
  57. // We may be using multiple attachment directories.
  58. if (!empty($modSettings['currentAttachmentUploadDir']) && !is_array($modSettings['attachmentUploadDir']))
  59. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  60. $is_done = false;
  61. while (!$is_done)
  62. {
  63. nextSubStep($substep);
  64. $request = upgrade_query("
  65. SELECT id_attach, id_folder, filename, file_hash
  66. FROM {$db_prefix}attachments
  67. WHERE file_hash = ''
  68. LIMIT $_GET[a], 100");
  69. // Finished?
  70. if ($smcFunc['db_num_rows']($request) == 0)
  71. $is_done = true;
  72. while ($row = $smcFunc['db_fetch_assoc']($request))
  73. {
  74. // The current folder.
  75. $current_folder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
  76. // The old location of the file.
  77. $old_location = getLegacyAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder']);
  78. // The new file name.
  79. $file_hash = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], true);
  80. // And we try to move it.
  81. rename($old_location, $current_folder . '/' . $row['id_attach'] . '_' . $file_hash);
  82. // Only update thif if it was successful.
  83. if (file_exists($current_folder . '/' . $row['id_attach'] . '_' . $file_hash) && !file_exists($old_location))
  84. upgrade_query("
  85. UPDATE {$db_prefix}attachments
  86. SET file_hash = '$file_hash'
  87. WHERE id_attach = $row[id_attach]");
  88. }
  89. $smcFunc['db_free_result']($request);
  90. $_GET['a'] += 100;
  91. $step_progress['current'] = $_GET['a'];
  92. }
  93. unset($_GET['a']);
  94. ---}
  95. ---#
  96. /******************************************************************************/
  97. --- Adding support for IPv6...
  98. /******************************************************************************/
  99. ---# Adding new columns to ban items...
  100. ALTER TABLE {$db_prefix}ban_items
  101. ADD COLUMN ip_low5 smallint(255) unsigned NOT NULL DEFAULT '0',
  102. ADD COLUMN ip_high5 smallint(255) unsigned NOT NULL DEFAULT '0',
  103. ADD COLUMN ip_low6 smallint(255) unsigned NOT NULL DEFAULT '0',
  104. ADD COLUMN ip_high6 smallint(255) unsigned NOT NULL DEFAULT '0',
  105. ADD COLUMN ip_low7 smallint(255) unsigned NOT NULL DEFAULT '0',
  106. ADD COLUMN ip_high7 smallint(255) unsigned NOT NULL DEFAULT '0',
  107. ADD COLUMN ip_low8 smallint(255) unsigned NOT NULL DEFAULT '0',
  108. ADD COLUMN ip_high8 smallint(255) unsigned NOT NULL DEFAULT '0';
  109. ---#
  110. ---# Changing existing columns to ban items...
  111. ALTER TABLE {$db_prefix}ban_items
  112. CHANGE ip_low1 ip_low1 tinyint(3) unsigned NOT NULL DEFAULT '0',
  113. CHANGE ip_high1 ip_high1 tinyint(3) unsigned NOT NULL DEFAULT '0',
  114. CHANGE ip_low2 ip_low2 tinyint(3) unsigned NOT NULL DEFAULT '0',
  115. CHANGE ip_high2 ip_high2 tinyint(3) unsigned NOT NULL DEFAULT '0',
  116. CHANGE ip_low3 ip_low3 tinyint(3) unsigned NOT NULL DEFAULT '0',
  117. CHANGE ip_high3 ip_high3 tinyint(3) unsigned NOT NULL DEFAULT '0',
  118. CHANGE ip_low4 ip_low4 tinyint(3) unsigned NOT NULL DEFAULT '0',
  119. CHANGE ip_high4 ip_high4 tinyint(3) unsigned NOT NULL DEFAULT '0';
  120. ---#