Database.yml for mysql as primary db and sqlite for solid cache/queue/job

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

1 Like

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
1 Like

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

Giuseppe, might be late to the party but if you want to add development configs you can follow this guide by the maintainer.

tl;dr is just copy the production config and change to development.

1 Like