ADD a column closed_issues_count to table projects

This commit is contained in:
Jasder 2020-05-21 18:35:56 +08:00
parent 56ce2e1461
commit becca7d1ae
1 changed files with 11 additions and 0 deletions

View File

@ -0,0 +1,11 @@
class AddClosedIssuesCountToProjects < ActiveRecord::Migration[5.2]
def change
add_column :projects, :closed_issues_count, :integer, default: 0
projects = Project.joins(:issues).where('status_id = 5').select("projects.id, count('issues.id') as closed_issues_count").group("projects.id")
projects.each do |pro|
project = Project.find pro.id
project.update_column(:closed_issues_count, pro.closed_issues_count) if project.closed_issues_count == 0
end
end
end