Skip to content

Commit

Permalink
既存の提出物にデータを挿入するdata_migrationスクリプトを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
Daichi831 committed Aug 17, 2021
1 parent 8ae0f69 commit ec1f951
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions db/data/20210816082555_add_last_comment_at.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class AddLastCommentAt < ActiveRecord::Migration[6.1]
def up
products = Product.where(self_last_comment_at: nil).where(mentor_last_comment_at: nil)
products.each do |product|
next unless product.comments.size.positive?

product.comments.each do |comment|
if comment.user.mentor
product.mentor_last_comment_at = comment.updated_at
elsif comment.user == product.user
product.self_last_comment_at = comment.updated_at
end
end
product.save!
end
end

def down
raise ActiveRecord::IrreversibleMigration
end
end

0 comments on commit ec1f951

Please sign in to comment.