diff options
author | Jarka Košanová <jarka@gitlab.com> | 2019-08-13 11:30:32 +0300 |
---|---|---|
committer | Jarka Košanová <jarka@gitlab.com> | 2019-08-16 08:52:30 +0300 |
commit | 19db315734d54d6850b0139dda75da758b55af56 (patch) | |
tree | 9cf00e191c70f9661fae2a2f63cd4c0cbf09da67 /lib/tasks/gitlab | |
parent | 0297f1c2b862edbe8015874913ebbab1393706e4 (diff) |
Add rake tasks for migrating leacy uploads
- move uploads created by AttachmentUploader
- handle also files created for legacy_diff_notes
Diffstat (limited to 'lib/tasks/gitlab')
-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 |