summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2017-07-08 11:04:25 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2017-07-08 11:04:25 +0000
commit420f6b5474e49e17226415250846e48fe514fe0d (patch)
tree95b707efe16f90b6eb4a87c9bee349cd1cd3b256 /db
parent43b9141c365930326d50c8c8566d67722172d2ec (diff)
parente36daa0fd95c93967708447b3b8f615c2a81e3b5 (diff)
downloadgitlab-ce-420f6b5474e49e17226415250846e48fe514fe0d.tar.gz
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 'db')
-rw-r--r--db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb b/db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
new file mode 100644
index 00000000000..f31015d77a3
--- /dev/null
+++ b/db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
@@ -0,0 +1,33 @@
+class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ BATCH_SIZE = 10000
+ RANGE_SIZE = 1000
+ MIGRATION = 'MigrateBuildStageIdReference'.freeze
+
+ disable_ddl_transaction!
+
+ class Build < ActiveRecord::Base
+ self.table_name = 'ci_builds'
+ include ::EachBatch
+ end
+
+ ##
+ # It will take around 3 days to process 20M ci_builds.
+ #
+ def up
+ Build.where(stage_id: nil).each_batch(of: BATCH_SIZE) do |relation, index|
+ relation.each_batch(of: RANGE_SIZE) do |relation|
+ range = relation.pluck('MIN(id)', 'MAX(id)').first
+
+ BackgroundMigrationWorker
+ .perform_in(index * 2.minutes, MIGRATION, range)
+ end
+ end
+ end
+
+ def down
+ # noop
+ end
+end