Commit d9dd0e5b authored by Jarka Košanová's avatar Jarka Košanová

Merge branch '31015-migrate-legacy-attachments' into 'master'

Migrate legacy uploads to the project location

Closes #31015

See merge request gitlab-org/gitlab!29295
parents f333eb77 75f4323b
---
title: Migrate legacy uploads out of deprecated paths
merge_request: 29295
author:
type: fixed
# frozen_string_literal: true
class MigrateLegacyAttachments < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false
MIGRATION = 'LegacyUploadsMigrator'
BATCH_SIZE = 5000
INTERVAL = 5.minutes.to_i
class Upload < ActiveRecord::Base
self.table_name = 'uploads'
include ::EachBatch
end
def up
queue_background_migration_jobs_by_range_at_intervals(Upload.where(uploader: 'AttachmentUploader', model_type: 'Note'),
MIGRATION,
INTERVAL,
batch_size: BATCH_SIZE)
end
def down
# no-op
end
end
...@@ -13152,5 +13152,6 @@ COPY "schema_migrations" (version) FROM STDIN; ...@@ -13152,5 +13152,6 @@ COPY "schema_migrations" (version) FROM STDIN;
20200408110856 20200408110856
20200408153842 20200408153842
20200408175424 20200408175424
20200409211607
\. \.
...@@ -111,24 +111,6 @@ sudo -u git -H bundle exec rake "gitlab:uploads:migrate[FileUploader, MergeReque ...@@ -111,24 +111,6 @@ sudo -u git -H bundle exec rake "gitlab:uploads:migrate[FileUploader, MergeReque
sudo -u git -H bundle exec rake "gitlab:uploads:migrate[DesignManagement::DesignV432x230Uploader, DesignManagement::Action]" sudo -u git -H bundle exec rake "gitlab:uploads:migrate[DesignManagement::DesignV432x230Uploader, DesignManagement::Action]"
``` ```
## Migrate legacy uploads out of deprecated paths
> Introduced in GitLab 12.3.
To migrate all uploads created by legacy uploaders, run:
**Omnibus Installation**
```shell
gitlab-rake gitlab:uploads:legacy:migrate
```
**Source Installation**
```shell
bundle exec rake gitlab:uploads:legacy:migrate
```
## Migrate from object storage to local storage ## Migrate from object storage to local storage
If you need to disable Object Storage for any reason, first you need to migrate If you need to disable Object Storage for any reason, first you need to migrate
......
# 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'
batch_size = 5000
delay_interval = 5.minutes.to_i
Upload.where(uploader: 'AttachmentUploader', model_type: 'Note').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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment