Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2017-07-08 14:04:25 +0300
committerGrzegorz Bizon <grzegorz@gitlab.com>2017-07-08 14:04:25 +0300
commit420f6b5474e49e17226415250846e48fe514fe0d (patch)
tree95b707efe16f90b6eb4a87c9bee349cd1cd3b256 /lib
parent43b9141c365930326d50c8c8566d67722172d2ec (diff)
parente36daa0fd95c93967708447b3b8f615c2a81e3b5 (diff)
Merge branch 'fix/gb/stage-id-reference-background-migration' into 'master'
Add build stage_id reference background migration Closes #34151 See merge request !12513
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/background_migration/migrate_build_stage_id_reference.rb19
1 files changed, 19 insertions, 0 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
new file mode 100644
index 00000000000..91540127ea9
--- /dev/null
+++ b/lib/gitlab/background_migration/migrate_build_stage_id_reference.rb
@@ -0,0 +1,19 @@
+module Gitlab
+ module BackgroundMigration
+ class MigrateBuildStageIdReference
+ def perform(start_id, stop_id)
+ 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 BETWEEN #{start_id.to_i} AND #{stop_id.to_i}
+ AND ci_builds.stage_id IS NULL
+ SQL
+
+ ActiveRecord::Base.connection.execute(sql)
+ end
+ end
+ end
+end