mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Promote historic post_deploy migrations (#16288)
This commit promotes all post_deploy migrations which existed in Discourse v2.7.13 (timestamp <= 20210328233843) This reduces the likelihood of issues relating to migration run order Also fixes a couple of typos in `script/promote_migrations`
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MigrateSearchDataAfterDefaultLocaleRename < ActiveRecord::Migration[6.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
%w{category tag topic user}.each { |model| fix_search_data(model) }
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fix_search_data(model)
|
||||
key = "#{model}_id"
|
||||
table = "#{model}_search_data"
|
||||
|
||||
puts "Migrating #{table} to new locale."
|
||||
|
||||
sql = <<~SQL
|
||||
UPDATE #{table}
|
||||
SET locale = 'en'
|
||||
WHERE #{key} IN (
|
||||
SELECT #{key}
|
||||
FROM #{table}
|
||||
WHERE locale = 'en_US'
|
||||
LIMIT 100000
|
||||
)
|
||||
SQL
|
||||
|
||||
loop do
|
||||
count = execute(sql).cmd_tuples
|
||||
break if count == 0
|
||||
puts "Migrated #{count} rows of #{table} to new locale."
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
class UndoAddProcessedToNotifications < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
execute "ALTER TABLE notifications DROP COLUMN IF EXISTS processed"
|
||||
end
|
||||
end
|
||||
@@ -1,14 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
class FixTopicTimerDurationMinutes < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
DB.exec("DELETE FROM topic_timers WHERE status_type = 7 AND duration > 20 * 365")
|
||||
DB.exec("DELETE FROM topic_timers WHERE status_type != 7 AND duration > 20 * 365 * 24")
|
||||
|
||||
DB.exec("UPDATE topic_timers SET duration_minutes = (duration * 60 * 24) WHERE duration_minutes IS NULL AND status_type = 7 AND duration IS NOT NULL")
|
||||
DB.exec("UPDATE topic_timers SET duration_minutes = (duration * 60) WHERE duration_minutes IS NULL AND status_type != 7 AND duration IS NOT NULL")
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -1,34 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class FixGroupFlairAvatarUploadSecurityAndAcls < ActiveRecord::Migration[6.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
upload_ids = DB.query_single(<<~SQL
|
||||
SELECT flair_upload_id
|
||||
FROM groups
|
||||
WHERE flair_upload_id IS NOT NULL
|
||||
SQL
|
||||
)
|
||||
|
||||
if upload_ids.any?
|
||||
reason = "group_flair fixup migration"
|
||||
DB.exec(<<~SQL, upload_ids: upload_ids, reason: reason, now: Time.zone.now)
|
||||
UPDATE uploads SET secure = false, security_last_changed_at = :now, updated_at = :now, security_last_changed_reason = :reason
|
||||
WHERE id IN (:upload_ids) AND uploads.secure
|
||||
SQL
|
||||
|
||||
if Discourse.store.external?
|
||||
uploads = Upload.where(id: upload_ids, secure: false).where("updated_at = security_last_changed_at")
|
||||
uploads.each do |upload|
|
||||
Discourse.store.update_upload_ACL(upload)
|
||||
upload.touch
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -1,69 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MoveNewSinceToNewTableAgain < ActiveRecord::Migration[6.0]
|
||||
disable_ddl_transaction!
|
||||
BATCH_SIZE = 30_000
|
||||
|
||||
def up
|
||||
offset = 0
|
||||
loop do
|
||||
min_id, max_id = DB.query_single(<<~SQL, offset: offset, batch_size: BATCH_SIZE)
|
||||
SELECT min(user_id), max(user_id)
|
||||
FROM (
|
||||
SELECT user_id
|
||||
FROM user_stats
|
||||
ORDER BY user_id
|
||||
LIMIT :batch_size
|
||||
OFFSET :offset
|
||||
) X
|
||||
SQL
|
||||
|
||||
# will return nil
|
||||
break if !min_id
|
||||
|
||||
sql = <<~SQL
|
||||
INSERT INTO dismissed_topic_users (user_id, topic_id, created_at)
|
||||
SELECT users.id, topics.id, user_stats.new_since
|
||||
FROM user_stats
|
||||
JOIN users ON users.id = user_stats.user_id
|
||||
JOIN user_options ON user_options.user_id = users.id
|
||||
LEFT JOIN topics ON topics.created_at <= user_stats.new_since
|
||||
AND topics.archetype <> :private_message
|
||||
AND topics.created_at >= GREATEST(CASE
|
||||
WHEN COALESCE(user_options.new_topic_duration_minutes, :default_duration) = :always THEN users.created_at
|
||||
WHEN COALESCE(user_options.new_topic_duration_minutes, :default_duration) = :last_visit THEN COALESCE(users.previous_visit_at,users.created_at)
|
||||
ELSE (:now::timestamp - INTERVAL '1 MINUTE' * COALESCE(user_options.new_topic_duration_minutes, :default_duration))
|
||||
END, :min_date)
|
||||
AND topics.id IN(SELECT id FROM topics ORDER BY created_at DESC LIMIT :max_new_topics)
|
||||
LEFT JOIN topic_users ON topics.id = topic_users.topic_id AND users.id = topic_users.user_id
|
||||
LEFT JOIN dismissed_topic_users ON dismissed_topic_users.topic_id = topics.id AND users.id = dismissed_topic_users.user_id
|
||||
WHERE user_stats.new_since IS NOT NULL
|
||||
AND user_stats.user_id >= :min_id
|
||||
AND user_stats.user_id <= :max_id
|
||||
AND topic_users.last_read_post_number IS NULL
|
||||
AND topics.id IS NOT NULL
|
||||
AND dismissed_topic_users.id IS NULL
|
||||
ORDER BY topics.created_at DESC
|
||||
ON CONFLICT DO NOTHING
|
||||
SQL
|
||||
|
||||
DB.exec(sql,
|
||||
now: DateTime.now,
|
||||
last_visit: User::NewTopicDuration::LAST_VISIT,
|
||||
always: User::NewTopicDuration::ALWAYS,
|
||||
default_duration: SiteSetting.default_other_new_topic_duration_minutes,
|
||||
min_date: Time.at(SiteSetting.min_new_topics_time).to_datetime,
|
||||
private_message: Archetype.private_message,
|
||||
min_id: min_id,
|
||||
max_id: max_id,
|
||||
max_new_topics: SiteSetting.max_new_topics)
|
||||
|
||||
offset += BATCH_SIZE
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -1,35 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class DropOldSsoSiteSettings < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
# These were copied to their new names in migrate/20210204135429_rename_sso_site_settings
|
||||
execute <<~SQL
|
||||
DELETE FROM site_settings
|
||||
WHERE name IN (
|
||||
'enable_sso',
|
||||
'sso_allows_all_return_paths',
|
||||
'enable_sso_provider',
|
||||
'verbose_sso_logging',
|
||||
'sso_url',
|
||||
'sso_secret',
|
||||
'sso_provider_secrets',
|
||||
'sso_overrides_groups',
|
||||
'sso_overrides_bio',
|
||||
'sso_overrides_email',
|
||||
'sso_overrides_username',
|
||||
'sso_overrides_name',
|
||||
'sso_overrides_avatar',
|
||||
'sso_overrides_profile_background',
|
||||
'sso_overrides_location',
|
||||
'sso_overrides_website',
|
||||
'sso_overrides_card_background',
|
||||
'external_auth_skip_create_confirm',
|
||||
'external_auth_immediately'
|
||||
)
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -1,14 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class DropFlashOneboxSiteSetting < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
execute <<~SQL
|
||||
DELETE FROM site_settings
|
||||
WHERE name = 'enable_flash_video_onebox'
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class DeleteOrphanPostRevisions < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
sql = <<~SQL
|
||||
DELETE FROM post_revisions
|
||||
USING post_revisions pr
|
||||
LEFT JOIN posts ON posts.id = pr.post_id
|
||||
WHERE posts.id IS NULL
|
||||
AND post_revisions.id = pr.id
|
||||
SQL
|
||||
|
||||
execute(sql)
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class FixBookmarksWithIncorrectTopicId < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
result = DB.exec(<<~SQL)
|
||||
UPDATE bookmarks bm
|
||||
SET topic_id = subquery.correct_topic_id, updated_at = NOW()
|
||||
FROM (
|
||||
SELECT bookmarks.id AS bookmark_id, bookmarks.post_id, bookmarks.topic_id,
|
||||
posts.topic_id AS correct_topic_id
|
||||
FROM bookmarks
|
||||
INNER JOIN posts ON posts.id = bookmarks.post_id
|
||||
WHERE posts.topic_id != bookmarks.topic_id
|
||||
) AS subquery
|
||||
WHERE bm.id = subquery.bookmark_id;
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user