From ecb2fd8222edf67b65c46362dc0b2361e3adf93a Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Fri, 14 Jun 2019 15:44:07 +1000 Subject: [PATCH] DEV: improve db:create to catch all cases - No RAILS_ENV - create multisite / dev / test - `test` RAILS_ENV - create multisite / test --- lib/tasks/db.rake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index d14354d499a..61975adef62 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -13,6 +13,10 @@ module MultisiteTestHelpers def self.load_multisite? Rails.env.test? && !ENV["RAILS_DB"] && !ENV["SKIP_MULTISITE"] end + + def self.create_multisite? + (ENV["RAILS_ENV"] == "test" || !ENV["RAILS_ENV"]) && !ENV["RAILS_DB"] && !ENV["SKIP_MULTISITE"] + end end task 'db:environment:set' => [:load_config] do |_, args| @@ -27,7 +31,7 @@ task 'db:force_skip_persist' do end task 'db:create' => [:load_config] do |_, args| - if !ENV['RAILS_ENV'] + if MultisiteTestHelpers.create_multisite? system("RAILS_ENV=test RAILS_DB=discourse_test_multisite rake db:create") end end @@ -39,8 +43,8 @@ begin end task 'db:drop' => [:load_config] do |_, args| - if MultisiteTestHelpers.load_multisite? - system("RAILS_DB=discourse_test_multisite rake db:drop") + if MultisiteTestHelpers.create_multisite? + system("RAILS_DB=discourse_test_multisite RAILS_ENV=test rake db:drop") end end