summaryrefslogtreecommitdiff
path: root/db/post_migrate/20200713071042_confirm_project_bot_users.rb
blob: 0578fc42ef25a547ee5eea4c4e1b3f34954e5ed8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class ConfirmProjectBotUsers < ActiveRecord::Migration[6.0]
  DOWNTIME = false

  disable_ddl_transaction!

  class User < ApplicationRecord
    self.table_name = 'users'

    include ::EachBatch

    USER_TYPE_PROJECT_BOT = 6

    scope :project_bots, -> { where(user_type: USER_TYPE_PROJECT_BOT) }
    scope :unconfirmed, -> { where(confirmed_at: nil) }
  end

  def up
    User.reset_column_information

    User.project_bots.unconfirmed.each_batch do |relation|
      relation.update_all('confirmed_at = created_at')
    end
  end

  def down
    # no-op
  end
end