diogob / carrierwave-postgresql

Use PostgreSQL large objects (AKA BLOBs) to store your files inside the database
http://diogob.github.com/carrierwave-postgresql/
MIT License
56 stars 25 forks source link

Changing the OID of an uploader #19

Closed chrisnicola closed 9 years ago

chrisnicola commented 9 years ago

I'm migrating some data to a new model and there doesn't seem to be an easy way to assign the old OID to the new model. This seems to be a Carrierwave limitation though. Are you aware of a way to do this?

chrisnicola commented 9 years ago

In the end I solved this but the process is very awkward. Any attempt to set the OID directly will fail. Also if you destroy the old model while it holds the OID reference the OID is destroyed. This works however:

      new_model.update_column(:image, old_model.image.identifier)
      # Remove the reference to the image from the old_model
      old_model.update_column(:image, nil)
      # Alternatively you may want to delete the model altogether, be sure to use delete not destroy
      OldModel.delete(old_model.id)
diogob commented 9 years ago

Your solution should work fine, the OID is just a number that references to a system table. I actually think that is the most elegant solution. Changing the carrierwave storage to handle this case (updating the OID instead of the whole file) seems even more awkward.

chrisnicola commented 9 years ago

Thanks. I've also updated it to show that the delete method must be used to avoid triggering the calback that unlinks the large object.