2017-11-23 12:56:51 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
# rubocop:disable Style/Documentation
|
|
|
|
|
2017-06-28 09:29:04 +00:00
|
|
|
module Gitlab
|
|
|
|
module BackgroundMigration
|
|
|
|
class MigrateBuildStageIdReference
|
2017-07-07 07:35:28 +00:00
|
|
|
def perform(start_id, stop_id)
|
2017-06-28 10:01:52 +00:00
|
|
|
sql = <<-SQL.strip_heredoc
|
2017-07-07 13:52:45 +00:00
|
|
|
UPDATE ci_builds
|
|
|
|
SET stage_id =
|
2017-06-29 13:26:47 +00:00
|
|
|
(SELECT id FROM ci_stages
|
|
|
|
WHERE ci_stages.pipeline_id = ci_builds.commit_id
|
|
|
|
AND ci_stages.name = ci_builds.stage)
|
2017-07-07 13:52:45 +00:00
|
|
|
WHERE ci_builds.id BETWEEN #{start_id.to_i} AND #{stop_id.to_i}
|
|
|
|
AND ci_builds.stage_id IS NULL
|
2017-06-28 10:01:52 +00:00
|
|
|
SQL
|
2017-06-28 09:29:04 +00:00
|
|
|
|
2017-06-28 10:01:52 +00:00
|
|
|
ActiveRecord::Base.connection.execute(sql)
|
2017-06-28 09:29:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|