Skip to content

Commit 48b2499

Browse files
committed
Deprecate environment as an argument for dbconsole and console
People should rather rely on the `-e` or `--environment` options to specify in which environment they want to work. This will allow us to specify the connection to pick as a regular argument in the future.
1 parent 1acd9a6 commit 48b2499

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

railties/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
* Passing the environment's name as a regular argument to the
2+
`rails dbconsole` and `rails console` commands is deprecated.
3+
The `-e` option should be used instead.
4+
5+
Previously:
6+
7+
$ bin/rails dbconsole production
8+
9+
Now:
10+
11+
$ bin/rails dbconsole -e production
12+
13+
*Robin Dupret*, *Kasper Timm Hansen*
14+
115
* Allow to pass a custom connection name to the `rails dbconsole`
216
command when using a 3-level database configuration.
317

railties/lib/rails/command/environment_argument.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ module EnvironmentArgument #:nodoc:
1313
def extract_environment_option_from_argument
1414
if environment
1515
self.options = options.merge(environment: acceptable_environment(environment))
16+
17+
ActiveSupport::Deprecation.warn "Passing the environment's name as a " \
18+
"regular argument is deprecated and " \
19+
"will be removed in the next Rails " \
20+
"version. Please, use the -e option " \
21+
"instead."
1622
elsif !options[:environment]
1723
self.options = options.merge(environment: Rails::Command.environment)
1824
end

railties/test/commands/console_test.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_start_with_sandbox
4747
end
4848

4949
def test_console_with_environment
50-
start ["-e production"]
50+
start ["-e", "production"]
5151
assert_match(/\sproduction\s/, output)
5252
end
5353

@@ -88,18 +88,24 @@ def test_environment_option
8888
end
8989

9090
def test_rails_env_is_production_when_first_argument_is_p
91-
start ["p"]
92-
assert_match(/\sproduction\s/, output)
91+
assert_deprecated do
92+
start ["p"]
93+
assert_match(/\sproduction\s/, output)
94+
end
9395
end
9496

9597
def test_rails_env_is_test_when_first_argument_is_t
96-
start ["t"]
97-
assert_match(/\stest\s/, output)
98+
assert_deprecated do
99+
start ["t"]
100+
assert_match(/\stest\s/, output)
101+
end
98102
end
99103

100104
def test_rails_env_is_development_when_argument_is_d
101-
start ["d"]
102-
assert_match(/\sdevelopment\s/, output)
105+
assert_deprecated do
106+
start ["d"]
107+
assert_match(/\sdevelopment\s/, output)
108+
end
103109
end
104110

105111
def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
@@ -111,7 +117,9 @@ def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
111117
end
112118
end
113119

114-
assert_match("dev", parse_arguments(["dev"])[:environment])
120+
assert_deprecated do
121+
assert_match("dev", parse_arguments(["dev"])[:environment])
122+
end
115123
ensure
116124
Rails::Command::ConsoleCommand.class_eval do
117125
undef_method :available_environments

railties/test/commands/dbconsole_test.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,18 @@ def test_env
9898
end
9999

100100
def test_rails_env_is_development_when_argument_is_dev
101-
stub_available_environments([ "development", "test" ]) do
102-
assert_match("development", parse_arguments([ "dev" ])[:environment])
101+
assert_deprecated do
102+
stub_available_environments([ "development", "test" ]) do
103+
assert_match("development", parse_arguments([ "dev" ])[:environment])
104+
end
103105
end
104106
end
105107

106108
def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
107-
stub_available_environments([ "dev" ]) do
108-
assert_match("dev", parse_arguments([ "dev" ])[:environment])
109+
assert_deprecated do
110+
stub_available_environments([ "dev" ]) do
111+
assert_match("dev", parse_arguments([ "dev" ])[:environment])
112+
end
109113
end
110114
end
111115

0 commit comments

Comments
 (0)