Cleanup invalid likes without target
This commit is contained in:
parent
028199a6f3
commit
00296ffda5
1 changed files with 13 additions and 0 deletions
13
db/migrate/20170914202650_cleanup_invalid_likes.rb
Normal file
13
db/migrate/20170914202650_cleanup_invalid_likes.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CleanupInvalidLikes < ActiveRecord::Migration[5.1]
|
||||
class Like < ApplicationRecord
|
||||
end
|
||||
|
||||
def up
|
||||
Like.where(target_type: "Post").joins("LEFT OUTER JOIN posts ON posts.id = likes.target_id")
|
||||
.where("posts.id IS NULL").delete_all
|
||||
Like.where(target_type: "Comment").joins("LEFT OUTER JOIN comments ON comments.id = likes.target_id")
|
||||
.where("comments.id IS NULL").delete_all
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue