Skip to content

Commit 01d90fb

Browse files
authored
Active Storage: encourage Rails.env in bucket names
rails#42186 outlined a problem I've seen in the wild before (with AS, but also with other gems like papertrail) where developers interact with production data locally and inadvertently destroy it. A simple way to prevent this in the Active Storage case is to make the `bucket` name for services be based on `Rails.env`. This way, if you pull a production database copy and call `purge` on a blob for it, AS will try and destroy the file from the `your_own_bucket-development` bucket. But the file doesn't live there - it lives in the `your_own_bucket-production` bucket. This is just a suggestion and people who know what they are doing can name their buckets whatever they want. But for first time Active Storage users I think this removes an unnecessarily sharp knife.
1 parent be8d8ed commit 01d90fb

File tree

1 file changed

+3
-3
lines changed
  • railties/lib/rails/generators/rails/app/templates/config

1 file changed

+3
-3
lines changed

railties/lib/rails/generators/rails/app/templates/config/storage.yml.tt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ local:
1212
# access_key_id: <%%= Rails.application.credentials.dig(:aws, :access_key_id) %>
1313
# secret_access_key: <%%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
1414
# region: us-east-1
15-
# bucket: your_own_bucket
15+
# bucket: your_own_bucket-<%%= Rails.env %>
1616

1717
# Remember not to checkin your GCS keyfile to a repository
1818
# google:
1919
# service: GCS
2020
# project: your_project
2121
# credentials: <%%= Rails.root.join("path/to/gcs.keyfile") %>
22-
# bucket: your_own_bucket
22+
# bucket: your_own_bucket-<%%= Rails.env %>
2323

2424
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
2525
# microsoft:
2626
# service: AzureStorage
2727
# storage_account_name: your_account_name
2828
# storage_access_key: <%%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29-
# container: your_container_name
29+
# container: your_container_name-<%%= Rails.env %>
3030

3131
# mirror:
3232
# service: Mirror

0 commit comments

Comments
 (0)