mirror of
https://github.com/discourse/discourse.git
synced 2024-12-20 01:33:53 +08:00
25138db433
This commit promotes all post_deploy migrations which existed in Discourse v3.0.0 (timestamp <= 20221212234948)
26 lines
762 B
Ruby
26 lines
762 B
Ruby
# frozen_string_literal: true
|
|
|
|
class BackfillOutboundMessageId < ActiveRecord::Migration[7.0]
|
|
def up
|
|
# best effort backfill, we don't care about years worth of message_id
|
|
# preservation
|
|
#
|
|
# we also don't need to backfill outbound_message_id for posts that
|
|
# do _not_ have an incoming email linked, since that will be backfilled
|
|
# at runtime if it is missing
|
|
sql_query = <<~SQL
|
|
UPDATE posts
|
|
SET outbound_message_id = ie.message_id
|
|
FROM incoming_emails AS ie
|
|
WHERE ie.post_id = posts.id
|
|
AND posts.created_at >= :one_year_ago
|
|
AND posts.outbound_message_id IS NULL
|
|
SQL
|
|
DB.exec(sql_query, one_year_ago: 1.year.ago)
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|