2018-12-23 12:14:25 +05:30
|
|
|
class MoveAppearanceToSystemDir < ActiveRecord::Migration[4.2]
|
2017-08-17 22:00:37 +05:30
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
DOWNTIME = false
|
|
|
|
DIRECTORY_TO_MOVE = 'appearance'.freeze
|
|
|
|
|
|
|
|
def up
|
|
|
|
source = File.join(old_upload_dir, DIRECTORY_TO_MOVE)
|
|
|
|
destination = File.join(new_upload_dir, DIRECTORY_TO_MOVE)
|
|
|
|
|
|
|
|
move_directory(source, destination)
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
source = File.join(new_upload_dir, DIRECTORY_TO_MOVE)
|
|
|
|
destination = File.join(old_upload_dir, DIRECTORY_TO_MOVE)
|
|
|
|
|
|
|
|
move_directory(source, destination)
|
|
|
|
end
|
|
|
|
|
|
|
|
def move_directory(source, destination)
|
|
|
|
unless file_storage?
|
|
|
|
say 'Not using file storage, skipping'
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
unless File.directory?(source)
|
|
|
|
say "#{source} did not exist, skipping"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if File.directory?(destination)
|
|
|
|
say "#{destination} already existed, skipping"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
say "Moving #{source} -> #{destination}"
|
|
|
|
FileUtils.mv(source, destination)
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_storage?
|
|
|
|
CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File
|
|
|
|
end
|
|
|
|
|
|
|
|
def base_directory
|
|
|
|
Rails.root
|
|
|
|
end
|
|
|
|
|
|
|
|
def old_upload_dir
|
|
|
|
File.join(base_directory, "public", "uploads")
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_upload_dir
|
2017-09-10 17:25:29 +05:30
|
|
|
File.join(base_directory, "public", "uploads", "-", "system")
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|