迁移数据

dev_course
daiao 5 years ago
parent 234cdbeab9
commit fbcf9b77f5

@ -1,12 +1,5 @@
class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2]
def change
add_column :challenges, :praises_count, :integer, :default => 0
challenges = Challenge.where(nil)
challenges.each do |c|
praises_count = c.praise_tread.where(praise_or_tread: 1).count
c.update_column(:praises_count, praises_count)
end
#add_column :challenges, :praises_count, :integer, :default => 0
end
end

@ -0,0 +1,9 @@
class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2]
def change
challenges = Challenge.where(nil)
challenges.each do |c|
praises_count = c.praise_tread.where(praise_or_tread: 1).count
c.update_column(:praises_count, praises_count)
end
end
end
Loading…
Cancel
Save