mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-13 08:15:55 +08:00
migrate project watchers_count
This commit is contained in:
12
db/migrate/20200518092612_change_project_watchers_count.rb
Normal file
12
db/migrate/20200518092612_change_project_watchers_count.rb
Normal 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
|
||||
Reference in New Issue
Block a user