[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:
parent
49ddc725a3
commit
f7d781258b
2 changed files with 30 additions and 0 deletions
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue