0

So I didn't realize that I had been saving files and images in production to config.active_storage.service = :local

I want it to match my staging which is config.active_storage.service = :digitalocean_spaces

The problem is when I switch it I break all the links to the old images. Question is how do I migrate those files into my digitalocean_spaces or even get them out of active_storage.serivce local to upload them into my digital oceans space

1 Answers1

0

You can now use Mirror Service:

You can keep multiple services in sync by defining a mirror service. A mirror service replicates uploads and deletes across two or more subordinate services.

A mirror service is intended to be used temporarily during a migration between services in production. You can start mirroring to a new service, copy pre-existing files from the old service to the new, then go all-in on the new service.

You'll also need a custom script to sync your files between the mirrors. Basically, you have to call mirror_later on each blob (works on Rails 6.1+):

ActiveStorage::Blob.all.each do |blob|
  blob.mirror_later
end

Read more examples and approaches in the following answer: How to sync new ActiveStorage mirrors?

markets
  • 6,709
  • 1
  • 38
  • 48