Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-06-07 12:50:46 +0300
committerKamil Trzciński <ayufan@ayufan.eu>2019-06-07 12:50:46 +0300
commitfd19f887dfeeeedb483c4a4fb32f9f768e89389c (patch)
tree458f68144f89ded038967444831e5889a0e0527f /db
parentabb2d4c601d796339c8d7cb0c00946696730f198 (diff)
parent3335918bff211f543ec0f304fbfaf8278daa91d2 (diff)
Merge branch '50070-legacy-attachments' into 'master'
Migrate legacy uploads Closes #57217 See merge request gitlab-org/gitlab-ce!24679
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20190114184258_migrate_legacy_attachments.rb32
1 files changed, 32 insertions, 0 deletions
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