Commit 2719b2f0 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Simplify stage_id migration as we now use relations

parent 320229e1
......@@ -2,19 +2,14 @@ module Gitlab
module BackgroundMigration
class MigrateBuildStageIdReference
def perform(start_id, stop_id)
scope = if stop_id.to_i.nonzero?
"ci_builds.id BETWEEN #{start_id.to_i} AND #{stop_id.to_i}"
else
"ci_builds.id >= #{start_id.to_i}"
end
sql = <<-SQL.strip_heredoc
UPDATE "ci_builds"
SET "stage_id" =
UPDATE ci_builds
SET stage_id =
(SELECT id FROM ci_stages
WHERE ci_stages.pipeline_id = ci_builds.commit_id
AND ci_stages.name = ci_builds.stage)
WHERE #{scope} AND "ci_builds"."stage_id" IS NULL
WHERE ci_builds.id BETWEEN #{start_id.to_i} AND #{stop_id.to_i}
AND ci_builds.stage_id IS NULL
SQL
ActiveRecord::Base.connection.execute(sql)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment