rails db:console no longer works, errors out with 'primary' database is not configured

This has been reported on Stack Overflow: https://stackoverflow.com/questions/69546832/gitlab-rails-dbconsole-command-returns-primary-database-not-configured-for-pr

% bin/rails dbconsole
Traceback (most recent call last):
	15: from bin/rails:4:in `<main>'
	14: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	13: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	12: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	11: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	10: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	 9: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/commands.rb:18:in `<main>'
	 8: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/command.rb:48:in `invoke'
	 7: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/command/base.rb:69:in `perform'
	 6: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
	 5: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
	 4: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
	 3: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/commands/dbconsole/dbconsole_command.rb:181:in `perform'
	 2: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/commands/dbconsole/dbconsole_command.rb:10:in `start'
	 1: from /Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/commands/dbconsole/dbconsole_command.rb:19:in `start'
/Users/stanhu/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.1.4.6/lib/rails/commands/dbconsole/dbconsole_command.rb:108:in `db_config': 'primary' database is not configured for 'development'. Available configuration: #<ActiveRecord::DatabaseConfigurations:0x0000000134cd43c8 @configurations=[#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00000001369fbe38 @env_name="development", @name="main", @configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :database=>"gitlabhq_development", :host=>"/Users/stanhu/gdk-ee/postgresql", :port=>5432, :pool=>10, :prepared_statements=>false, :variables=>{"statement_timeout"=>"120s"}}>, #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00000001369fbdc0 @env_name="development", @name="ci", @configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :database=>"gitlabhq_development", :database_tasks=>false, :host=>"/Users/stanhu/gdk-ee/postgresql", :port=>5432, :pool=>10, :prepared_statements=>false, :variables=>{"statement_timeout"=>"120s"}}>, #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00000001369fbc30 @env_name="test", @name="main", @configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :database=>"gitlabhq_test", :host=>"/Users/stanhu/gdk-ee/postgresql", :port=>5432, :pool=>10, :prepared_statements=>false, :variables=>{"statement_timeout"=>"120s"}}>, #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00000001369fbbb8 @env_name="test", @name="ci", @configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :database=>"gitlabhq_test", :database_tasks=>false, :host=>"/Users/stanhu/gdk-ee/postgresql", :port=>5432, :pool=>10, :prepared_statements=>false, :variables=>{"statement_timeout"=>"120s"}}>]> (ActiveRecord::AdapterNotSpecified)

It seems Rails might be defaulting to primary in https://github.com/rails/rails/blob/16b64e541b4bac11d12be515a01d6f874cf6a79f/railties/lib/rails/commands/dbconsole/dbconsole_command.rb#L120?

Workaround seems to be add --db main to the argument:

% bin/rails dbconsole --db main
psql (12.9)
Type "help" for help.

gitlabhq_development=#