1
1
# frozen_string_literal: true
2
2
3
+ require "active_support/deprecation"
4
+ require "active_support/core_ext/string/filters"
3
5
require "rails/command/environment_argument"
4
6
5
7
module Rails
@@ -89,15 +91,15 @@ def start
89
91
90
92
def config
91
93
@config ||= begin
92
- # We need to check whether the user passed the connection the
94
+ # We need to check whether the user passed the database the
93
95
# first time around to show a consistent error message to people
94
96
# relying on 2-level database configuration.
95
- if @options [ "connection " ] && configurations [ connection ] . blank?
96
- raise ActiveRecord ::AdapterNotSpecified , "'#{ connection } ' connection is not configured. Available configuration: #{ configurations . inspect } "
97
- elsif configurations [ environment ] . blank? && configurations [ connection ] . blank?
97
+ if @options [ "database " ] && configurations [ database ] . blank?
98
+ raise ActiveRecord ::AdapterNotSpecified , "'#{ database } ' database is not configured. Available configuration: #{ configurations . inspect } "
99
+ elsif configurations [ environment ] . blank? && configurations [ database ] . blank?
98
100
raise ActiveRecord ::AdapterNotSpecified , "'#{ environment } ' database is not configured. Available configuration: #{ configurations . inspect } "
99
101
else
100
- configurations [ connection ] || configurations [ environment ] . presence
102
+ configurations [ database ] || configurations [ environment ] . presence
101
103
end
102
104
end
103
105
end
@@ -106,8 +108,8 @@ def environment
106
108
Rails . respond_to? ( :env ) ? Rails . env : Rails ::Command . environment
107
109
end
108
110
109
- def connection
110
- @options . fetch ( :connection , "primary" )
111
+ def database
112
+ @options . fetch ( :database , "primary" )
111
113
end
112
114
113
115
private
@@ -156,12 +158,22 @@ class DbconsoleCommand < Base # :nodoc:
156
158
class_option :connection , aliases : "-c" , type : :string ,
157
159
desc : "Specifies the connection to use."
158
160
161
+ class_option :database , aliases : "--db" , type : :string ,
162
+ desc : "Specifies the database to use."
163
+
159
164
def perform
160
165
extract_environment_option_from_argument
161
166
162
167
# RAILS_ENV needs to be set before config/application is required.
163
168
ENV [ "RAILS_ENV" ] = options [ :environment ]
164
169
170
+ if options [ "connection" ]
171
+ ActiveSupport ::Deprecation . warn ( <<-MSG . squish )
172
+ `connection` option is deprecated and will be removed in Rails 6.1. Please use `database` option instead.
173
+ MSG
174
+ options [ "database" ] = options [ "connection" ]
175
+ end
176
+
165
177
require_application_and_environment!
166
178
Rails ::DBConsole . start ( options )
167
179
end
0 commit comments