Hello! We have an internal gem for replicas, but we are working to migrate off of that to native Rails. Is it possible to have 2 different database.yml files (i.e. database.yml and database_old.yml) and conditionally load one based on an environment toggle? If yes, how/where would you tell Rails to load which YAML file? Thanks so much!
Oh that’s interesting. But isn’t that for the whole application? Something I’ve done is when using a Rails engine, you can have it connect to a different database. So on Rails 6.1 you could define an initializer and do this
# engines/my_engine/config/initializers/database_connection.rb
Rails.application.reloader.to_prepare do
MyEngine::ApplicationRecord.connects_to database: { writing: :my_engine, reading: :my_engine }
end
And make sure to define that :my_engine as a section in your database.yml for the parent app.