diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-07 16:19:43 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-07 16:19:43 +0300 |
commit | b41b4d2e6a44a04fc3e6fff09cf45f93033ff0ad (patch) | |
tree | d2b48bb242119e451ecb3052c9a28d0a50af4441 /db | |
parent | b7b3aef444bba457b4967ee7fa122527853a2eb5 (diff) |
Use new `each_batch` helper instead of custom one
In stage_id backgrond migration.
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb | 14 |
1 files changed, 8 insertions, 6 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 0d108d18501..107a5661329 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,18 +7,20 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration 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 - opts = { scope: ->(table, query) { query.where(table[:stage_id].eq(nil)) }, - of: BATCH_SIZE } - - walk_table_in_batches(:ci_builds, **opts) do |index, start_id, stop_id| + Build.all.each_batch(of: BATCH_SIZE) do |relation, index| + range = relation.pluck('MIN(id)', 'MAX(id)').first schedule = index * 2.minutes - BackgroundMigrationWorker - .perform_in(schedule, MIGRATION, [start_id, stop_id]) + BackgroundMigrationWorker.perform_in(schedule, MIGRATION, range) end end |