From 3335918bff211f543ec0f304fbfaf8278daa91d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarka=20Ko=C5=A1anov=C3=A1?= Date: Wed, 23 Jan 2019 19:44:12 +0100 Subject: Migrate legacy uploads to the project location Uploads coming from AttachmentUploader need to be moved to the currently supported location (FileUploader) --- .../20190114184258_migrate_legacy_attachments.rb | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 db/migrate/20190114184258_migrate_legacy_attachments.rb (limited to 'db') diff --git a/db/migrate/20190114184258_migrate_legacy_attachments.rb b/db/migrate/20190114184258_migrate_legacy_attachments.rb new file mode 100644 index 00000000000..e9fb7952dc9 --- /dev/null +++ b/db/migrate/20190114184258_migrate_legacy_attachments.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class MigrateLegacyAttachments < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + + MIGRATION = 'MigrateLegacyUploads'.freeze + BATCH_SIZE = 5000 + DELAY_INTERVAL = 5.minutes.to_i + + class Upload < ActiveRecord::Base + self.table_name = 'uploads' + + include ::EachBatch + end + + def up + 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 + + # not needed + def down + end +end -- cgit v1.2.3