Files
danbooru/script/fixes/060_fix_favgroup_posts.rb
evazion b03173d61e favgroups: fix favgroups with invalid post ids.
Fix favgroups containing post ids that don't exist. Most of these are from
typos or from old expunged posts that weren't properly removed from favgroups.
2020-01-15 23:32:51 -06:00

13 lines
388 B
Ruby
Executable File

#!/usr/bin/env ruby
require_relative "../../config/environment"
favgroups = FavoriteGroup.select("*, unnest(string_to_array(post_ids, ' '))::bigint AS post_id")
favgroups = FavoriteGroup.select("*").from(favgroups).where("NOT EXISTS (SELECT 1 FROM posts WHERE id = post_id)")
FavoriteGroup.transaction do
favgroups.each do |favgroup|
favgroup.remove!(favgroup.post_id)
end
end