Cleanup invalid likes without target

This commit is contained in:
Benjamin Neff 2017-09-14 22:32:46 +02:00
parent 028199a6f3
commit 00296ffda5
No known key found for this signature in database
GPG key ID: 971464C3F1A90194

View 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