修改sync_version_issues并添加verison.id_index

This commit is contained in:
sylor_huang@126.com 2020-04-22 16:34:03 +08:00
parent 87f329d34d
commit 0736d93b95
2 changed files with 12 additions and 3 deletions

View File

@ -0,0 +1,5 @@
class AddVersionIdIndex < ActiveRecord::Migration[5.2]
def change
execute "ALTER TABLE versions ADD PRIMARY KEY (id);"
end
end

View File

@ -5,10 +5,9 @@ namespace :sync_version_issues do
desc "update version issues_count"
task update_issues: :environment do
versions = Version.all
puts "____________sync start________________"
versions.find_each do |q|
Version.all.each do |q|
issues = Issue.select(:id, :fixed_version_id,:status_id).where(fixed_version_id: q.id)
issues_count = issues.size
puts "____________issues_count____________#{issues_count}____"
@ -17,7 +16,12 @@ namespace :sync_version_issues do
q.issues_count = issues_count
q.closed_issues_count = closed_issues_count
q.percent = percent
q.save!(:validate=>false)
begin
q.save!
rescue Exception => e
puts "#####_______save_error______######{e}"
end
# q.update_attributes(issues_count: issues_count, closed_issues_count: closed_issues_count, percent: percent)
puts "____________sync success________________"
end