diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-03-07 15:52:29 +0300 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2018-03-09 11:56:49 +0300 |
commit | 7b22381603d4f2cddc87b1b70e5be076df63cf01 (patch) | |
tree | fe7e3fc8fcef4a512ff3e4006ca8a8df56cee964 /db/migrate/20180309121820_reschedule_commits_count_for_merge_request_diff.rb | |
parent | 47b9854dac5d255f0ad68cb3310c66a7111b792e (diff) |
Reschedule commits_count background migration
We still have >100K unmigrated MergeRequestDiffs
which don't have commits_count set yet (see
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/17567#note_61904891)
This migration re-schedules the original background migration.
To assure that records are not processed twice, records with
commits_count set are skipped.
Related to #41698 and !17567
Diffstat (limited to 'db/migrate/20180309121820_reschedule_commits_count_for_merge_request_diff.rb')
-rw-r--r-- | db/migrate/20180309121820_reschedule_commits_count_for_merge_request_diff.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/db/migrate/20180309121820_reschedule_commits_count_for_merge_request_diff.rb b/db/migrate/20180309121820_reschedule_commits_count_for_merge_request_diff.rb new file mode 100644 index 00000000000..990759104b0 --- /dev/null +++ b/db/migrate/20180309121820_reschedule_commits_count_for_merge_request_diff.rb @@ -0,0 +1,30 @@ +class RescheduleCommitsCountForMergeRequestDiff < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + MIGRATION = 'AddMergeRequestDiffCommitsCount'.freeze + BATCH_SIZE = 5000 + DELAY_INTERVAL = 5.minutes.to_i + + class MergeRequestDiff < ActiveRecord::Base + self.table_name = 'merge_request_diffs' + + include ::EachBatch + end + + disable_ddl_transaction! + + def up + say 'Populating the MergeRequestDiff `commits_count` (reschedule)' + + execute("SET statement_timeout TO '60s'") if Gitlab::Database.postgresql? + + MergeRequestDiff.where(commits_count: nil).each_batch(of: BATCH_SIZE) do |relation, index| + start_id, end_id = relation.pluck('MIN(id), MAX(id)').first + delay = index * DELAY_INTERVAL + + BackgroundMigrationWorker.perform_in(delay, MIGRATION, [start_id, end_id]) + end + end +end |