summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/sync_issues_state_id.rb
blob: 2a0751928b82a598b9f74e3963c2538f04ead885 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true
# rubocop:disable Style/Documentation

module Gitlab
  module BackgroundMigration
    class SyncIssuesStateId
      def perform(start_id, end_id)
        ActiveRecord::Base.connection.execute <<~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
  end
end