diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2017-09-15 00:37:45 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2017-09-18 04:24:52 +0300 |
commit | 655fe2a9129a70d6add9462f816fb55c274b31db (patch) | |
tree | 0475326f86d2fa03dac37dfad20300837c75f74b /db | |
parent | 00296ffda51aee1d572219a40fe59f64c521f562 (diff) |
Cleanup invalid polls without status message
closes #7614
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20170914212336_cleanup_invalid_polls.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/db/migrate/20170914212336_cleanup_invalid_polls.rb b/db/migrate/20170914212336_cleanup_invalid_polls.rb new file mode 100644 index 000000000..7d7cda97f --- /dev/null +++ b/db/migrate/20170914212336_cleanup_invalid_polls.rb @@ -0,0 +1,19 @@ +class CleanupInvalidPolls < ActiveRecord::Migration[5.1] + class Poll < ApplicationRecord + has_many :poll_answers, dependent: :destroy + has_many :poll_participations, dependent: :destroy + end + class PollAnswer < ApplicationRecord + belongs_to :poll + has_many :poll_participations + end + class PollParticipation < ApplicationRecord + belongs_to :poll + belongs_to :poll_answer + end + + def up + Poll.joins("LEFT OUTER JOIN posts ON posts.id = polls.status_message_id") + .where("posts.id IS NULL").destroy_all + end +end |