Cleanup invalid likes without target

parent 028199a6
# 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment