Commit 4a2f8604 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Properly migrate files

parent e268960b
require 'fog/aws'
require 'carrierwave/storage/fog'
class ObjectStoreUploader < GitlabUploader class ObjectStoreUploader < GitlabUploader
before :store, :set_default_local_store before :store, :set_default_local_store
...@@ -38,30 +41,35 @@ class ObjectStoreUploader < GitlabUploader ...@@ -38,30 +41,35 @@ class ObjectStoreUploader < GitlabUploader
end end
end end
def filename
super || file&.filename
end
def migrate!(new_store) def migrate!(new_store)
raise 'Undefined new store' unless new_store raise 'Undefined new store' unless new_store
return unless object_store != new_store return unless object_store != new_store
return unless file
# retrive file from current storage old_file = file
current_file = file old_store = object_store
# change storage # change storage
self.object_store = new_store self.object_store = new_store
# store file on a new storage # store file on a new storage
new_file = storage.store!(current_file) new_file = storage.store!(old_file)
# since we change storage store the new storage # since we change storage store the new storage
# in case of failure delete new file # in case of failure delete new file
begin begin
subject.save! subject.save!
rescue rescue
self.object_store = old_store
new_file.delete new_file.delete
end end
# since we migrated file we can delete it now old_file.delete
current_file.delete
end end
def move_to_store def move_to_store
......
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