[deploy] Remove orphaned polls related rows (#9855)
This commit is contained in:
parent
eff28766fc
commit
03ed8aedb1
4 changed files with 84 additions and 0 deletions
|
|
@ -0,0 +1,29 @@
|
|||
module DataUpdateScripts
|
||||
class RemoveOrphanedPollVotes
|
||||
def run
|
||||
# Delete all PollVotes belonging to Polls that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM poll_votes
|
||||
WHERE poll_id NOT IN (SELECT id FROM polls);
|
||||
SQL
|
||||
)
|
||||
|
||||
# Delete all PollVotes belonging to PollOptions that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM poll_votes
|
||||
WHERE poll_option_id NOT IN (SELECT id FROM poll_options);
|
||||
SQL
|
||||
)
|
||||
|
||||
# Delete all PollVotes belonging to Users that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM poll_votes
|
||||
WHERE user_id NOT IN (SELECT id FROM users);
|
||||
SQL
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
module DataUpdateScripts
|
||||
class RemoveOrphanedPollSkips
|
||||
def run
|
||||
# Delete all PollSkips belonging to Polls that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM poll_skips
|
||||
WHERE poll_id NOT IN (SELECT id FROM polls);
|
||||
SQL
|
||||
)
|
||||
|
||||
# Delete all PollSkips belonging to Users that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM poll_skips
|
||||
WHERE user_id NOT IN (SELECT id FROM users);
|
||||
SQL
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
module DataUpdateScripts
|
||||
class RemoveOrphanedPollOptions
|
||||
def run
|
||||
# Delete all PollOptions belonging to Polls that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM poll_options
|
||||
WHERE poll_id NOT IN (SELECT id FROM polls);
|
||||
SQL
|
||||
)
|
||||
|
||||
# Delete all PollOptions belonging to Polls that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM poll_options
|
||||
WHERE poll_id NOT IN (SELECT id FROM polls);
|
||||
SQL
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module DataUpdateScripts
|
||||
class RemoveOrphanedPolls
|
||||
def run
|
||||
# Delete all Polls belonging to Articles that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM polls
|
||||
WHERE article_id NOT IN (SELECT id FROM articles);
|
||||
SQL
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue