Is it possible to have 2 database configs during Rails upgrade for dual boot?

I’m working on upgrading our Rails application from version 5.2 to 6.0. We’re using an ar-octopus gem for accessing our database replica. This gem is deprecated on newer versions of Rails, because of built-in multi db support since 6.0.

I am trying to do a “dual boot” upgrade strategy with the help of bootboot gem to get our codebase to run on both versions of Rails, and run our tests on both versions so that latest changes in the codebase will be compatible with the new version of Rails while we slowly roll out the new version.

Multi db support requires a change from 2-tier to 3-tier database config. This config is not compatible with 5.2, so we can’t have the same config for both versions.

Ideally, I would like to have database.yml and and have Rails use the appropriate config by looking at DEPENDENCIES_NEXT env variable.

As far as I looked, there is no datbase_config_path option. And the config/database.yml is pretty much hardcoded everywhere since it’s a pretty solid convention for Rails applications.

So my question are:

  1. Is there any way to monkey patch some code in Rails framework to change the database config path?
  2. If not, maybe I can monkeypatch the config parser to handle 3-tier configs, and use a single new version file?

I’m searching the Rails source code, but I’m not that familiar with it, so it takes me a lot of time. I figured I would ask the community to help while I do that, maybe some of you have already done something similar or can point to a specific place to look at?

Any help would be appreciated, thank you!