I ended up hacking my database.yml
file like this
<%= ctrys = ['nl','uk']; main = ENV.fetch('DEFAULT_SHARD'){'nl'}; ctrys.delete(main); ctrys.unshift(main);nil %>
development:
<%= ctrys[0] %>:
<<: *default_database
database: <%= ENV.fetch("DATABASE_DATABASE_#{ctrys[0].upcase}") { Rails.application.credentials.dig(:mysql, :"database_#{ctrys[0]}") } %>
<%= ctrys[1] %>:
<<: *default_database
database: <%= ENV.fetch("DATABASE_DATABASE_#{ctrys[1].upcase}") { Rails.application.credentials.dig(:mysql, :"database_#{ctrys[1]}") } %>
I can use it like this:
~prompt% DISABLE_SPRING=true DEFAULT_SHARD="uk" rails
Loading development environment (Rails 7.0.1)
hvg-web(dev)> ActiveRecord::Base.connection.pool.db_config.name
=> "uk"
(spring will cache it, so disable spring)
this hack does give the test-runner a challenge though:
/usr/src/app# rspec
Running via Spring preloader in process 2504
Running via Spring preloader in process 2510
Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB.
feels hacky, but it works - maybe somebody else can come up with a better plan?