diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-05 11:38:06 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-05 11:38:06 +0300 |
commit | c5ede858eab81e662c48761749ff2fa22dbfa9df (patch) | |
tree | 3118abb851c551c9bcac5949b01ccce5f8d2abcc /db/post_migrate | |
parent | c5f1e1a70bd79b36fe8cfda75b7366dd8ee90d66 (diff) | |
parent | f6966d96ec5941db364a2c8d9d2d80d3aa7d20f2 (diff) |
Merge branch 'fix/gb/stage-id-reference-background-migration' into backstage/gb/migrate-stages-statuses
* fix/gb/stage-id-reference-background-migration: (22 commits)
Reduce a delay between stage_id scheduled migrations
Improve exception description in bg migrations
Do not override original AR5 batching interface
Sanitize id value passed to async background migration
Improve code examples in background migrations docs
Add description to exception in bg migrations worker
Do not compare float with integer in migrations specs
Improve readability of build stage id migration query
Use integers to schedule delayed background migrations
Test if argument passed to a migration is present
Make `inline` a default sidekiq testing processing again
Improve specs for background stage_id ref migration
Perform stage_id ref backgound migration in bulks
Remove unused background migrations matcher
Use ActiveRecord 5 batching to schedule bg migration
Make it possible to schedule bg migrations in bulk
Add specs for delayed stage_id background migrations
Schedule background migration only when it is needed
Find builds that require a migration in batches
Update `db/schema.rb` with a new schema version
...
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb | 29 |
1 files changed, 29 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..ebec4cb6bb7 --- /dev/null +++ b/db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb @@ -0,0 +1,29 @@ +class MigrateStageIdReferenceInBackground < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 10000 + MIGRATION = 'MigrateBuildStageIdReference'.freeze + + disable_ddl_transaction! + + class Build < ActiveRecord::Base + self.table_name = 'ci_builds' + end + + def up + index = 1 + + Build.where(stage_id: nil).in_batches(of: BATCH_SIZE) do |relation| + jobs = relation.pluck(:id).map { |id| [MIGRATION, [id]] } + schedule = index * 2.minutes + index += 1 + + BackgroundMigrationWorker.perform_bulk_in(schedule, jobs) + end + end + + def down + # noop + end +end |