diff options
author | Yuji Yaginuma <yuuji.yaginuma@gmail.com> | 2019-04-02 16:30:46 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-02 16:30:46 +0900 |
commit | ef5ebd93d68c8287e42754e6bafc6c2ec0afa900 (patch) | |
tree | 91649bf3eb2d307bda7a8536e9665d6d9df12247 /railties | |
parent | 0214d406b1df96dc51487d45fd841941270d43fd (diff) | |
parent | 29b16d3ff87a3da4ec4ac33a17ad9fd9540284c8 (diff) | |
download | rails-ef5ebd93d68c8287e42754e6bafc6c2ec0afa900.tar.gz rails-ef5ebd93d68c8287e42754e6bafc6c2ec0afa900.tar.bz2 rails-ef5ebd93d68c8287e42754e6bafc6c2ec0afa900.zip |
Merge pull request #35703 from y-yagi/add_database_option_to_dbconsole_command
Rename `connection` option to `database` in `dbconsole` command
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 5 | ||||
-rw-r--r-- | railties/lib/rails/commands/dbconsole/dbconsole_command.rb | 26 | ||||
-rw-r--r-- | railties/test/commands/dbconsole_test.rb | 24 |
3 files changed, 42 insertions, 13 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 64f90fbbcc..c5136b7ab0 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,8 @@ +* The `connection` option of `rails dbconsole` command is deprecated in + favor of `database` option. + + *Yuji Yaginuma* + * Replace `chromedriver-helper` gem with `webdrivers` in default Gemfile. `chromedriver-helper` is deprecated as of March 31, 2019 and won't receive any further updates. diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index 0fac7d34a0..72f3235ce3 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "active_support/deprecation" +require "active_support/core_ext/string/filters" require "rails/command/environment_argument" module Rails @@ -89,15 +91,15 @@ module Rails def config @config ||= begin - # We need to check whether the user passed the connection the + # We need to check whether the user passed the database the # first time around to show a consistent error message to people # relying on 2-level database configuration. - if @options["connection"] && configurations[connection].blank? - raise ActiveRecord::AdapterNotSpecified, "'#{connection}' connection is not configured. Available configuration: #{configurations.inspect}" - elsif configurations[environment].blank? && configurations[connection].blank? + if @options["database"] && configurations[database].blank? + raise ActiveRecord::AdapterNotSpecified, "'#{database}' database is not configured. Available configuration: #{configurations.inspect}" + elsif configurations[environment].blank? && configurations[database].blank? raise ActiveRecord::AdapterNotSpecified, "'#{environment}' database is not configured. Available configuration: #{configurations.inspect}" else - configurations[connection] || configurations[environment].presence + configurations[database] || configurations[environment].presence end end end @@ -106,8 +108,8 @@ module Rails Rails.respond_to?(:env) ? Rails.env : Rails::Command.environment end - def connection - @options.fetch(:connection, "primary") + def database + @options.fetch(:database, "primary") end private @@ -156,12 +158,22 @@ module Rails class_option :connection, aliases: "-c", type: :string, desc: "Specifies the connection to use." + class_option :database, aliases: "--db", type: :string, + desc: "Specifies the database to use." + def perform extract_environment_option_from_argument # RAILS_ENV needs to be set before config/application is required. ENV["RAILS_ENV"] = options[:environment] + if options["connection"] + ActiveSupport::Deprecation.warn(<<-MSG.squish) + `connection` option is deprecated and will be removed in Rails 6.1. Please use `database` option instead. + MSG + options["database"] = options["connection"] + end + require_application_and_environment! Rails::DBConsole.start(options) end diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 65f6916acb..76a7cd055f 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -216,22 +216,22 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end end - def test_specifying_a_custom_connection_and_environment + def test_specifying_a_custom_database_and_environment stub_available_environments(["development"]) do - dbconsole = parse_arguments(["-c", "custom", "-e", "development"]) + dbconsole = parse_arguments(["--db", "custom", "-e", "development"]) assert_equal "development", dbconsole[:environment] - assert_equal "custom", dbconsole.connection + assert_equal "custom", dbconsole.database end end - def test_specifying_a_missing_connection + def test_specifying_a_missing_database app_db_config({}) do e = assert_raises(ActiveRecord::AdapterNotSpecified) do - Rails::Command.invoke(:dbconsole, ["-c", "i_do_not_exist"]) + Rails::Command.invoke(:dbconsole, ["--db", "i_do_not_exist"]) end - assert_includes e.message, "'i_do_not_exist' connection is not configured." + assert_includes e.message, "'i_do_not_exist' database is not configured." end end @@ -245,6 +245,18 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end end + def test_connection_options_is_deprecate + command = Rails::Command::DbconsoleCommand.new([], ["-c", "custom"]) + Rails::DBConsole.stub(:start, nil) do + assert_deprecated("`connection` option is deprecated") do + command.perform + end + end + + assert_equal "custom", command.options["connection"] + assert_equal "custom", command.options["database"] + end + def test_print_help_short stdout = capture(:stdout) do Rails::Command.invoke(:dbconsole, ["-h"]) |