dragonfly icon indicating copy to clipboard operation
dragonfly copied to clipboard

Migrate data between datastores

Open cambridgemike opened this issue 10 years ago • 2 comments

It would be great if there were a way to migrate data between datastores.

Posted an SO question about this as well http://stackoverflow.com/questions/27992698/how-to-migrate-data-between-datastores-using-dragonfly

cambridgemike avatar Jan 16 '15 21:01 cambridgemike

You probably have something like this Dragonfly.app.configure do somewhere in your app. You would update this to your new configuration. You'd preserve your old configuration in a block like Dragonfly.app("filestore").configure do.

Then you for each resource you might do something like:

old_app = Dragonfly.app("filestore")
Image.find_each do |image|
  job = old_app.fetch(image.photo_uid)
  image.photo = job.to_file(job.name)
  image.save
end

You could also look at how files are stored in S3 and write something to copy the files from your local data store to S3 and then simply update the data store provider in the app. Yeah, I think I'd go with this option if you can.

lcowell avatar May 02 '15 15:05 lcowell

@lcowell thanks for perfect tip.

Finally I changed the migrating procedure a bit (do not save and validate whole object, do not create temp file):

 old_app = Dragonfly.app("filestore")
 Image.find_each do |image|
   job = old_app.fetch(image.photo_uid)
   image.update_attributes!(image_uid: Dragonfly.app.store(job.data, job.meta))
 end

lksv avatar Sep 18 '15 10:09 lksv