about summary refs log tree commit diff
path: root/db/migrate/20161202132159_add_in_reply_to_account_id_to_statuses.rb
blob: 3a559ccd6da2da644d458d2bf399fe17caf34b9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class AddInReplyToAccountIdToStatuses < ActiveRecord::Migration[5.0]
  def up
    add_column :statuses, :in_reply_to_account_id, :integer, null: true, default: nil

    ActiveRecord::Base.transaction do
      Status.unscoped.where.not(in_reply_to_id: nil).includes(:thread).find_each do |status|
        next if status.thread.nil?

        status.in_reply_to_account_id = status.thread.account_id
        status.save(validate: false)
      end
    end
  end

  def down
    remove_column :statuses, :in_reply_to_account_id
  end
end