summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-07 09:35:28 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-07 15:08:15 +0200
commitfb89ba24825853ca29b804a4a08f7c83210f09db (patch)
tree5906aab32eb7210888762e27cc60c029503e7a73 /db
parent2917f4868a19ab17a0217703c7b842261f8b9e46 (diff)
downloadgitlab-ce-fb89ba24825853ca29b804a4a08f7c83210f09db.tar.gz
Schedule stage_id background migration in ranges
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb17
1 files changed, 8 insertions, 9 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
index ebec4cb6bb7..0d108d18501 100644
--- a/db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
+++ b/db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
@@ -7,19 +7,18 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
disable_ddl_transaction!
- class Build < ActiveRecord::Base
- self.table_name = 'ci_builds'
- end
-
+ ##
+ # It will take around 3 days to process 20M ci_builds.
+ #
def up
- index = 1
+ opts = { scope: ->(table, query) { query.where(table[:stage_id].eq(nil)) },
+ of: BATCH_SIZE }
- Build.where(stage_id: nil).in_batches(of: BATCH_SIZE) do |relation|
- jobs = relation.pluck(:id).map { |id| [MIGRATION, [id]] }
+ walk_table_in_batches(:ci_builds, **opts) do |index, start_id, stop_id|
schedule = index * 2.minutes
- index += 1
- BackgroundMigrationWorker.perform_bulk_in(schedule, jobs)
+ BackgroundMigrationWorker
+ .perform_in(schedule, MIGRATION, [start_id, stop_id])
end
end