New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Active Storage can be configured by STORAGE_URL #50477
base: main
Are you sure you want to change the base?
Conversation
@@ -32,5 +32,16 @@ def resolve(class_name) | |||
rescue LoadError | |||
raise "Missing service adapter for #{class_name.inspect}" | |||
end | |||
|
|||
def build_configurations(configurations) | |||
if storage_url = ENV["STORAGE_URL"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be comparison or is it an assignment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a conditional assignment, in order to give ENV["STORAGE_URL"]
priority over the rest of the configuration.
Active Storage doesn't need to support multiple configurations if the URL is set, unlike AR where you can have 2 or 3-tierd configs, so this is a simpler approach.
attr_reader :uri | ||
|
||
def build_url_hash | ||
service = uri.scheme && uri.scheme.tr("-", "_") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be refactored:
uri.scheme&.tr("-", "_")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just code I copied from AR:
rails/activerecord/lib/active_record/database_configurations/connection_url_resolver.rb
Line 83 in e3da4fc
adapter = uri.scheme && @uri.scheme.tr("-", "_") |
Fixes #50448
NOTE: This is a proof-of-concept, that I came up with based on my understanding of ActiveRecord::DatabaseConfigurations and try to find a tiny seam to add support for this feature. Open to feedback and suggestions, but wanted to take a stab at this while it was fresh in my head.