Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20190211131150_add_state_id_to_issuables.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: af02aa84afdb2d24fe7de2bf04fe64ee7045f3ba (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
31
32
33
34
35
36
37
class AddStateIdToIssuables < ActiveRecord::Migration[5.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  MIGRATION = 'SyncIssuablesStateId'.freeze

  # TODO - find out how many issues and merge requests in production
  # to adapt the batch size and delay interval
  # Keep in mind that the migration will be scheduled for issues and merge requests.
  BATCH_SIZE = 5000
  DELAY_INTERVAL = 5.minutes.to_i

  class Issue < ActiveRecord::Base
    include EachBatch

    self.table_name = 'issues'
  end

  class MergeRequest < ActiveRecord::Base
    include EachBatch

    self.table_name = 'merge_requests'
  end

  def up
    add_column :issues, :state_id, :integer, limit: 1
    add_column :merge_requests, :state_id, :integer, limit: 1

    queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE)
    queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE)
  end

  def down
    remove_column :issues, :state_id
    remove_column :merge_requests, :state_id
  end
end