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
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/secure_files/migration_helper.rb')
-rw-r--r--lib/gitlab/ci/secure_files/migration_helper.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/gitlab/ci/secure_files/migration_helper.rb b/lib/gitlab/ci/secure_files/migration_helper.rb
new file mode 100644
index 00000000000..13796f2476e
--- /dev/null
+++ b/lib/gitlab/ci/secure_files/migration_helper.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module SecureFiles
+ class MigrationHelper
+ class << self
+ def migrate_to_remote_storage(&block)
+ migrate_in_batches(
+ ::Ci::SecureFile.with_files_stored_locally,
+ ::Ci::SecureFileUploader::Store::REMOTE,
+ &block
+ )
+ end
+
+ private
+
+ def batch_size
+ ENV.fetch('MIGRATION_BATCH_SIZE', 10).to_i
+ end
+
+ def migrate_in_batches(files, store, &block)
+ files.find_each(batch_size: batch_size) do |file| # rubocop:disable CodeReuse/ActiveRecord
+ file.file.migrate!(store)
+
+ yield file if block
+ end
+ end
+ end
+ end
+ end
+ end
+end