Hello, I want to transition to the Rails 8 “solid” approach, using sqlite3 to manage caching, queues, and jobs, while sticking to my existing primary mysql database. I also want this particular setup to apply to all environments. What should database.yml look like? Thanks
Under the production
key, move your database connection data to primary
and add configurations for cache
and queue
as explained in the README for the gems.
Here’s an example:
production:
primary:
<<: *default
database: <%= ENV["MYSQL_DATABASE"].presence %>
username: <%= ENV["MYSQL_USERNAME"].presence %>
password: <%= ENV["MYSQL_PASSWORD"].presence %>
host: <%= ENV["MYSQL_HOST" ].presence %>
cache:
<<: *default
database: storage/production_cache.sqlite3
migrations_paths: db/cache_migrate
queue:
<<: *default
database: storage/production_queue.sqlite3
migrations_paths: db/queue_migrate
In all examples I have seen, cache and queue connections are defined under production. But what about development/test? Shouldn’t I duplicate the same setup for all environments?
Development:
- Cache: It’s usually memory store, no need to worry about the config
- Jobs: Yeah, you will need to do something similar to the production config with primary/queue
Test:
- Cache: It doesn’t, no need to worry about it
- Jobs: Has a special queue adapter to facilitate testing, no need to worry about it
I don’t think I use any solid
stuff in dev and certainly not in test.
Caching in dev is something you only want to do to test it out using bin/rails dev:cache
which toggles caching on/off