迁移数据

dev_course
daiao 5 years ago
parent fbcf9b77f5
commit 6f1d84eecc

@ -1,5 +1,5 @@
class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2]
def change
#add_column :challenges, :praises_count, :integer, :default => 0
add_column :challenges, :praises_count, :integer, :default => 0
end
end

@ -1,7 +1,7 @@
class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2]
def change
challenges = Challenge.where(nil)
challenges.each do |c|
challenges = Challenge.where(nil).unscope
challenges.find_each do |c|
praises_count = c.praise_tread.where(praise_or_tread: 1).count
c.update_column(:praises_count, praises_count)
end

Loading…
Cancel
Save