Yeah that seems to be in line with what the Rails guide and code say, if you explicitly provide a url:
, it seems like it has the highest precedence. If you don’t provide a url but there is a (X_)DATABASE_URL
env var present, then the env var subcomponents get merged on top of the components defined in yaml[1][2][3][4][5][6].
Yeah it is mildly ugly but I guess backwards compatibility trumps everything. When you start having multiple databases in your database.yml there is no way around a wordier database.yml
with additional config. It gets even wordier by the way if you want to have multiple databases both in development and production : Best way to play around with Solid Queue in development? · Issue #332 · rails/solid_queue · GitHub.
I am wondering if we couldn’t have our cake and eat it too by introducing some syntactic sugar or helpers on top of database.yml
to shorten default configuration for solid databases. For what they’re worth here are some random ideas:
-
url: <%= Rails.configuration.solid.cable_db_url %>
as a shorthand for
url: <%= URI.parse(ENV["DATABASE_URL"]).tap { |url| url.path += "_cache" } if ENV["DATABASE_URL"] %>
-
solid: true
to do thiscache: <<: *primary_production solid: true queue: <<: *primary_production solid: true ...
as a shorthand for this
cache: <<: *primary_production url: <%= URI.parse(ENV['DATABASE_URL']).tap { |u| u.path += '_cache' } if ENV['DATABASE_URL'] %> migrations_paths: db/cache_migrate queue: <<: *primary_production url: <%= URI.parse(ENV['DATABASE_URL']).tap { |u| u.path += '_queue' } if ENV['DATABASE_URL'] %> migrations_paths: db/queue_migrate ...
I like this one because it could significantly reduce verbosity for a default Rails 8 setup, and you could still override it if needed.