2019-02-11 12:48:37 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
# rubocop:disable Style/Documentation
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module BackgroundMigration
|
|
|
|
class SyncIssuablesStateId
|
2019-02-12 11:40:37 -05:00
|
|
|
def perform(start_id, end_id, table_name)
|
|
|
|
populate_new_state_id(start_id, end_id, table_name)
|
2019-02-11 12:48:37 -05:00
|
|
|
end
|
|
|
|
|
2019-02-12 11:40:37 -05:00
|
|
|
def populate_new_state_id(start_id, end_id, table_name)
|
|
|
|
Rails.logger.info("#{table_name} - Populating state_id: #{start_id} - #{end_id}")
|
2019-02-11 12:48:37 -05:00
|
|
|
|
|
|
|
ActiveRecord::Base.connection.execute <<~SQL
|
2019-02-12 11:40:37 -05:00
|
|
|
UPDATE #{table_name}
|
2019-02-11 12:48:37 -05:00
|
|
|
SET state_id =
|
|
|
|
CASE state
|
|
|
|
WHEN 'opened' THEN 1
|
|
|
|
WHEN 'closed' THEN 2
|
|
|
|
WHEN 'merged' THEN 3
|
|
|
|
WHEN 'locked' THEN 4
|
|
|
|
END
|
|
|
|
WHERE state_id IS NULL
|
|
|
|
AND id BETWEEN #{start_id} AND #{end_id}
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|