2017-07-17 13:23:59 +00:00
|
|
|
module Gitlab
|
|
|
|
module BackgroundMigration
|
|
|
|
class MigrateSystemUploadsToNewFolder
|
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
attr_reader :old_folder, :new_folder
|
|
|
|
|
2017-07-17 16:11:07 +00:00
|
|
|
class Upload < ActiveRecord::Base
|
|
|
|
self.table_name = 'uploads'
|
|
|
|
include EachBatch
|
|
|
|
end
|
2017-07-17 13:23:59 +00:00
|
|
|
|
2017-07-17 16:11:07 +00:00
|
|
|
def perform(old_folder, new_folder)
|
2017-07-17 13:23:59 +00:00
|
|
|
replace_sql = replace_sql(uploads[:path], old_folder, new_folder)
|
2017-07-17 16:11:07 +00:00
|
|
|
affected_uploads = Upload.where(uploads[:path].matches("#{old_folder}%"))
|
2017-07-17 13:23:59 +00:00
|
|
|
|
2017-07-17 16:11:07 +00:00
|
|
|
affected_uploads.each_batch do |batch|
|
|
|
|
batch.update_all("path = #{replace_sql}")
|
2017-07-17 13:23:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def uploads
|
|
|
|
Arel::Table.new('uploads')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|