[deploy] Remove orphaned polls related rows (#9855)

This commit is contained in:
rhymes 2020-08-20 10:40:01 +02:00 committed by GitHub
parent eff28766fc
commit 03ed8aedb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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