2019-10-12 21:52:04 +05:30
|
|
|
# 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
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
migration = 'LegacyUploadsMigrator'
|
2019-10-12 21:52:04 +05:30
|
|
|
batch_size = 5000
|
|
|
|
delay_interval = 5.minutes.to_i
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
Upload.where(uploader: 'AttachmentUploader', model_type: 'Note').each_batch(of: batch_size) do |relation, index|
|
2019-10-12 21:52:04 +05:30
|
|
|
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
|