Skip to content

Commit

Permalink
Changing Location docs suggest using unique immutable storage location
Browse files Browse the repository at this point in the history
From conversation at #703
  • Loading branch information
jrochkind committed Sep 9, 2024
1 parent 1ce6da4 commit 3b15996
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions doc/changing_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: changing-location
title: Migrating File Locations
---

This guide shows how to migrate the location of uploaded files on the same
This guide shows how to migrate the location of uploaded files on the same
storage in production, with zero downtime.

Let's assume we have a `Photo` model with an `image` file attachment:
Expand Down Expand Up @@ -31,14 +31,26 @@ to work with the previously stored urls because the files have not been migrated
```rb
class ImageUploader < Shrine
def generate_location(io, **options)
# change location generation
# change location generation, eg....
[
options[:record] && options[:record].class.name.underscore,
option[:record] && options[:record].id,
super
].compact.join("/")
end
end
```

We can now deploy this change to production so new file uploads will be stored in
We can now deploy this change to production so new file uploads will be stored in
the new location.

As seen above, we can call `super` to get the include the default location, which uses ruby
`SecureRandom.hex` to have a unique immutable storage location. While it isn't
strictly required to have a unique immutable storage location, it makes many
things work smoother when different content will get a different storage location,
and is recommended. One approach is using fixed directory/prefix as above.


## 2. Move existing files

To move existing files to new location, run the following script. It fetches
Expand Down

0 comments on commit 3b15996

Please sign in to comment.