File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed
lib/rails/commands/dbconsole Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -97,15 +97,18 @@ def start
97
97
def db_config
98
98
return @db_config if defined? ( @db_config )
99
99
100
- # We need to check whether the user passed the database the
101
- # first time around to show a consistent error message to people
102
- # relying on 2-level database configuration.
103
-
104
- @db_config = configurations . configs_for ( env_name : environment , name : database , include_hidden : true )
100
+ # If the user provided a database, use that. Otherwise find
101
+ # the first config in the database.yml
102
+ if database
103
+ @db_config = configurations . configs_for ( env_name : environment , name : database , include_hidden : true )
104
+ else
105
+ @db_config = configurations . find_db_config ( environment )
106
+ end
105
107
106
108
unless @db_config
109
+ missing_db = database ? "'#{ database } ' database is not" : "No databases are"
107
110
raise ActiveRecord ::AdapterNotSpecified ,
108
- "' #{ database } ' database is not configured for '#{ environment } '. Available configuration: #{ configurations . inspect } "
111
+ "#{ missing_db } configured for '#{ environment } '. Available configuration: #{ configurations . inspect } "
109
112
end
110
113
111
114
@db_config
@@ -116,7 +119,7 @@ def environment
116
119
end
117
120
118
121
def database
119
- @options . fetch ( :database , "primary" )
122
+ @options [ :database ]
120
123
end
121
124
122
125
private
Original file line number Diff line number Diff line change @@ -271,7 +271,7 @@ def test_specifying_a_missing_environment
271
271
Rails ::Command . invoke ( :dbconsole )
272
272
end
273
273
274
- assert_includes e . message , "'primary' database is not configured for 'test'."
274
+ assert_includes e . message , "No databases are configured for 'test'."
275
275
end
276
276
end
277
277
You can’t perform that action at this time.
0 commit comments