From fbcf9b77f53245d163aec43c78076422308d443f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:32:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190705011739_add_praises_count_for_challenges.rb | 9 +-------- ...20190705013203_modify_praises_count_for_challenges.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20190705013203_modify_praises_count_for_challenges.rb diff --git a/db/migrate/20190705011739_add_praises_count_for_challenges.rb b/db/migrate/20190705011739_add_praises_count_for_challenges.rb index 6455f1f10..2bf246277 100644 --- a/db/migrate/20190705011739_add_praises_count_for_challenges.rb +++ b/db/migrate/20190705011739_add_praises_count_for_challenges.rb @@ -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 diff --git a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb new file mode 100644 index 000000000..d2441d948 --- /dev/null +++ b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb @@ -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