diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-12-05 12:02:07 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-01-06 14:09:59 +0100 |
commit | 2ab69f0d0c825f8546f189a61189246d6c90b7ff (patch) | |
tree | e043bfc888e2bfe1e5ae2eb46a86af48d5c0171c /db | |
parent | 6d972724d426938a0bfd6744dc6464ec5f7e17f9 (diff) | |
download | gitlab-ce-2ab69f0d0c825f8546f189a61189246d6c90b7ff.tar.gz |
Schedule full build stage migration in the background
For builds that are still missing `stage_id`.
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20171205101928_schedule_build_stage_migration.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/db/post_migrate/20171205101928_schedule_build_stage_migration.rb b/db/post_migrate/20171205101928_schedule_build_stage_migration.rb new file mode 100644 index 00000000000..60293c60e8e --- /dev/null +++ b/db/post_migrate/20171205101928_schedule_build_stage_migration.rb @@ -0,0 +1,20 @@ +class ScheduleBuildStageMigration < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + MIGRATION = 'MigrateBuildStage'.freeze + BATCH = 10_000 + + class Build < ActiveRecord::Base + include EachBatch + self.table_name = 'ci_builds' + end + + def change + Build.where('stage_id IS NULL').each_batch(of: BATCH) do |builds, index| + builds.pluck(:id).map { |id| [MIGRATION, [id]] }.tap do |migrations| + BackgroundMigrationWorker.perform_bulk_in(index.minutes, migrations) + end + end + end +end |