gitlab-org--gitlab-foss/lib/gitlab/background_migration/sync_issues_state_id.rb

34 lines
782 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# rubocop:disable Style/Documentation
module Gitlab
module BackgroundMigration
class SyncIssuesStateId
2019-02-19 17:00:53 +00:00
include Reschedulable
2019-02-18 20:43:16 +00:00
def perform(start_id, end_id)
Rails.logger.info("Issues - Populating state_id: #{start_id} - #{end_id}")
2019-02-19 14:33:30 +00:00
reschedule_if_needed(start_id, end_id) do
execute_statement <<~SQL
2019-02-18 20:43:16 +00:00
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
2019-02-19 14:33:30 +00:00
def should_reschedule?
2019-02-18 20:43:16 +00:00
wait_for_deadtuple_vacuum?('issues')
end
end
end
end