Skip to content
Snippets Groups Projects
Commit d953f176 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Improve readability of build stage id migration query

parent 01128b13
Branches
Tags
No related merge requests found
Loading
@@ -5,12 +5,13 @@ module Gitlab
Loading
@@ -5,12 +5,13 @@ module Gitlab
raise ArgumentError unless id.present? raise ArgumentError unless id.present?
   
sql = <<-SQL.strip_heredoc sql = <<-SQL.strip_heredoc
UPDATE "ci_builds" SET "stage_id" = ( UPDATE "ci_builds"
SELECT id FROM ci_stages SET "stage_id" =
WHERE ci_stages.pipeline_id = ci_builds.commit_id (SELECT id FROM ci_stages
AND ci_stages.name = ci_builds.stage WHERE ci_stages.pipeline_id = ci_builds.commit_id
) AND ci_stages.name = ci_builds.stage)
WHERE "ci_builds"."id" = #{id} AND "ci_builds"."stage_id" IS NULL WHERE "ci_builds"."id" = #{id}
AND "ci_builds"."stage_id" IS NULL
SQL SQL
   
ActiveRecord::Base.connection.execute(sql) ActiveRecord::Base.connection.execute(sql)
Loading
Loading
Loading
@@ -58,11 +58,11 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
Loading
@@ -58,11 +58,11 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
   
it 'schedules background migrations' do it 'schedules background migrations' do
Sidekiq::Testing.inline! do Sidekiq::Testing.inline! do
expect(jobs.where(stage_id: nil)).to be_present expect(jobs.where(stage_id: nil).count).to eq 5
   
migrate! migrate!
   
expect(jobs.where(stage_id: nil)).to be_one expect(jobs.where(stage_id: nil).count).to eq 1
end end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment