With the new multiple database support in Rails 6 connecting to more than one database from Rails becomes easier. There is a small gotcha to be aware of though. Take the following configuration:
development:
primary:
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: <%= ENV["PG_HOST"] || "/tmp" %>
username: <%= ENV["PRIMARY_USERNAME"] %>
password: <%= ENV["PRIMARY_PASSWORD"] %>
database: "primary"
secondary:
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: <%= ENV["PG_HOST"] || "/tmp" %>
username: <%= ENV["SECONDARY_USERNAME"] %>
password: <%= ENV["SECONDARY_PASSWORD"] %>
database: <%= ENV["SECONDARY_DATABASE"] %>
Now imagine you for some reason forget to set SECONDARY_DATABASE
. In this case Rails will report that there
is no configuration at all for the secondary database.