From 4b1ae57f0f905bd8cb63e435197db5014239d39e Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Mon, 31 Dec 2018 13:46:30 -0500 Subject: Add rails db:system:change command Add `rails db:system:change` command for changing databases. ``` bin/rails db:system:change --to=postgresql force config/database.yml gsub Gemfile ``` The change command copies a template `config/database.yml` with the target database adapter into your app, and replaces your database gem with the target database gem. --- railties/test/commands/db_system_change_test.rb | 62 +++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 railties/test/commands/db_system_change_test.rb (limited to 'railties/test/commands') diff --git a/railties/test/commands/db_system_change_test.rb b/railties/test/commands/db_system_change_test.rb new file mode 100644 index 0000000000..bac757f1eb --- /dev/null +++ b/railties/test/commands/db_system_change_test.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require "isolation/abstract_unit" +require "rails/command" +require "rails/commands/db/system/change/change_command" + +class Rails::Command::Db::System::ChangeCommandTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + setup { build_app } + + teardown { teardown_app } + + test "change to existing database" do + change_database(to: "sqlite3") + + output = change_database(to: "sqlite3") + + assert_match "identical config/database.yml", output + assert_match "gsub Gemfile", output + end + + test "change to invalid database" do + output = change_database(to: "invalid-db") + + assert_match <<~MSG.squish, output + Invalid value for --to option. + Supported for preconfiguration are: + mysql, postgresql, sqlite3, oracle, frontbase, + ibm_db, sqlserver, jdbcmysql, jdbcsqlite3, + jdbcpostgresql, jdbc. + MSG + end + + test "change to postgresql" do + output = change_database(to: "postgresql") + + assert_match "force config/database.yml", output + assert_match "gsub Gemfile", output + end + + test "change to mysql" do + output = change_database(to: "mysql") + + assert_match "force config/database.yml", output + assert_match "gsub Gemfile", output + end + + test "change to sqlite3" do + change_database(to: "postgresql") + output = change_database(to: "sqlite3") + + assert_match "force config/database.yml", output + assert_match "gsub Gemfile", output + end + + private + def change_database(to:, **options) + args = ["--to", to] + rails "db:system:change", args, **options + end +end -- cgit v1.2.3 From d49899c15431104f8dad374363bac57479b4bd39 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Wed, 2 Jan 2019 13:35:56 -0500 Subject: Revise wording on invalid database error messages --- railties/test/commands/db_system_change_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test/commands') diff --git a/railties/test/commands/db_system_change_test.rb b/railties/test/commands/db_system_change_test.rb index bac757f1eb..2ff45a7878 100644 --- a/railties/test/commands/db_system_change_test.rb +++ b/railties/test/commands/db_system_change_test.rb @@ -25,7 +25,7 @@ class Rails::Command::Db::System::ChangeCommandTest < ActiveSupport::TestCase assert_match <<~MSG.squish, output Invalid value for --to option. - Supported for preconfiguration are: + Supported preconfigurations are: mysql, postgresql, sqlite3, oracle, frontbase, ibm_db, sqlserver, jdbcmysql, jdbcsqlite3, jdbcpostgresql, jdbc. -- cgit v1.2.3