diff options
author | Michael Kozono <mkozono@gmail.com> | 2019-08-16 22:07:56 +0000 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2019-08-16 22:07:56 +0000 |
commit | 9eabc0d6fc268023db13e8dad315f99f4fe1a6da (patch) | |
tree | bc6fed5f91d4034fa60e20fb90dec918ecbe0b97 /lib/tasks | |
parent | e9cd5d41fb5ce3b51034bca96f269be8edc1cff0 (diff) | |
parent | 19db315734d54d6850b0139dda75da758b55af56 (diff) | |
download | gitlab-ce-9eabc0d6fc268023db13e8dad315f99f4fe1a6da.tar.gz |
Merge branch 'legacy-attachments-migrate-fix' into 'master'
Migrate legacy uploads rake tasks
See merge request gitlab-org/gitlab-ce!29409
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/uploads/legacy.rake | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/uploads/legacy.rake b/lib/tasks/gitlab/uploads/legacy.rake new file mode 100644 index 00000000000..18fb8afe455 --- /dev/null +++ b/lib/tasks/gitlab/uploads/legacy.rake @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +namespace :gitlab do + namespace :uploads do + namespace :legacy do + desc "GitLab | Uploads | Migrate all legacy attachments" + task migrate: :environment do + class Upload < ApplicationRecord + self.table_name = 'uploads' + + include ::EachBatch + end + + migration = 'LegacyUploadsMigrator'.freeze + batch_size = 5000 + delay_interval = 5.minutes.to_i + + Upload.where(uploader: 'AttachmentUploader').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 + end +end |