summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/sync_issues_state_id.rb
blob: 053d154cef84b6fc7f7258138ab64829ccb9096e (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
# frozen_string_literal: true
# rubocop:disable Style/Documentation

module Gitlab
  module BackgroundMigration
    class SyncIssuesStateId
      include Reschedulable

      def perform(start_id, end_id)
        Rails.logger.info("Issues - Populating state_id: #{start_id} - #{end_id}")

        reschedule_if_needed(start_id, end_id) do
          execute_statement <<~SQL
            UPDATE issues
            SET state_id =
              CASE state
              WHEN 'opened' THEN 1
              WHEN 'closed' THEN 2
              END
            WHERE state_id IS NULL
            AND id BETWEEN #{start_id} AND #{end_id}
          SQL
        end
      end

      private

      def should_reschedule?
        wait_for_deadtuple_vacuum?('issues')
      end
    end
  end
end