[deploy] Cleanup orphan data from tags and feedback_messages (#10367)

* Cleanup orphan data from tags and feedback_messages

* Fix comment in script
This commit is contained in:
rhymes 2020-09-29 16:12:40 +02:00 committed by GitHub
parent 49ddc725a3
commit f7d781258b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,15 @@
module DataUpdateScripts
class NullifyOrphanedTagsByModChatChannelId
def run
# Nullify all Tags mod_chat_channel_id belonging to ChatChannels that don't exist anymore
ActiveRecord::Base.connection.execute(
<<~SQL.squish,
UPDATE tags
SET mod_chat_channel_id = NULL
WHERE mod_chat_channel_id IS NOT NULL
AND mod_chat_channel_id NOT IN (SELECT id FROM chat_channels);
SQL
)
end
end
end

View file

@ -0,0 +1,15 @@
module DataUpdateScripts
class NullifyOrphanedFeedbackMessagesByReporterId
def run
# Nullify all FeedbackMessages reporter_id belonging to Users that don't exist anymore
ActiveRecord::Base.connection.execute(
<<~SQL.squish,
UPDATE feedback_messages
SET reporter_id = NULL
WHERE reporter_id IS NOT NULL
AND reporter_id NOT IN (SELECT id FROM users);
SQL
)
end
end
end