migrate project watchers_count

This commit is contained in:
sylor_huang@126.com 2020-05-18 17:31:45 +08:00
parent 6256bc68b9
commit aa508f713c
1 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,12 @@
class ChangeProjectWatchersCount < ActiveRecord::Migration[5.2]
def change
watcher_ids = Watcher.where(watchable_type: "Project").pluck(:watchable_id).uniq
watcher_ids.each do |i|
puts "#######____update_project_watchers_id____##############{i}"
p = Project.includes(:watchers).select(:id, :watchers_count).find_by(i)
if p.present?
p.update_attribute(:watchers_count, p.watchers.size)
end
end
end
end