summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-29 15:26:47 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-29 15:26:47 +0200
commit6db8253cb86f44a80282706cc3de3df954661434 (patch)
tree919fcd90701c47e3e2e10189b35e2d36d93916ec
parentc7f6e5efb51d28242bfe5102b9db9cd7a6c1e24b (diff)
downloadgitlab-ce-6db8253cb86f44a80282706cc3de3df954661434.tar.gz
Improve readability of build stage id migration query
-rw-r--r--lib/gitlab/background_migration/migrate_build_stage_id_reference.rb13
-rw-r--r--spec/migrations/migrate_stage_id_reference_in_background_spec.rb4
2 files changed, 9 insertions, 8 deletions
diff --git a/lib/gitlab/background_migration/migrate_build_stage_id_reference.rb b/lib/gitlab/background_migration/migrate_build_stage_id_reference.rb
index 711126ea0d3..c8669ca3272 100644
--- a/lib/gitlab/background_migration/migrate_build_stage_id_reference.rb
+++ b/lib/gitlab/background_migration/migrate_build_stage_id_reference.rb
@@ -5,12 +5,13 @@ module Gitlab
raise ArgumentError unless id.present?
sql = <<-SQL.strip_heredoc
- 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 "ci_builds"."id" = #{id} AND "ci_builds"."stage_id" IS NULL
+ 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 "ci_builds"."id" = #{id}
+ AND "ci_builds"."stage_id" IS NULL
SQL
ActiveRecord::Base.connection.execute(sql)
diff --git a/spec/migrations/migrate_stage_id_reference_in_background_spec.rb b/spec/migrations/migrate_stage_id_reference_in_background_spec.rb
index 1bd2c14b61c..63787d71233 100644
--- a/spec/migrations/migrate_stage_id_reference_in_background_spec.rb
+++ b/spec/migrations/migrate_stage_id_reference_in_background_spec.rb
@@ -58,11 +58,11 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
it 'schedules background migrations' 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!
- expect(jobs.where(stage_id: nil)).to be_one
+ expect(jobs.where(stage_id: nil).count).to eq 1
end
end
end