Skip to content

Commit 16b64e5

Browse files
committed
Merge pull request #42285 from cthornton/include-replicas
Support using replicas when using `rails dbconsole`
1 parent 255b5ff commit 16b64e5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

railties/lib/rails/commands/dbconsole/dbconsole_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def db_config
102102
# first time around to show a consistent error message to people
103103
# relying on 2-level database configuration.
104104

105-
@db_config = configurations.configs_for(env_name: environment, name: database)
105+
@db_config = configurations.configs_for(env_name: environment, name: database, include_replicas: true)
106106

107107
unless @db_config
108108
raise ActiveRecord::AdapterNotSpecified,

railties/test/commands/dbconsole_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,25 @@ def test_specifying_a_custom_database_and_environment
226226
end
227227
end
228228

229+
def test_specifying_a_replica_database
230+
options = {
231+
database: "primary_replica",
232+
}
233+
234+
sample_config = {
235+
"test" => {
236+
"primary" => {},
237+
"primary_replica" => {
238+
"replica" => true
239+
}
240+
}
241+
}
242+
243+
app_db_config(sample_config) do
244+
assert_equal "primary_replica", Rails::DBConsole.new(options).db_config.name
245+
end
246+
end
247+
229248
def test_specifying_a_missing_database
230249
app_db_config({}) do
231250
e = assert_raises(ActiveRecord::AdapterNotSpecified) do

0 commit comments

Comments
 (0)