From 3af00a65e689a725fd081725c5d23aed51d6ea42 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Fri, 14 Jun 2019 14:20:48 +1000 Subject: [PATCH] FIX: site settings loading default values when no db This fixes a condition where an intermittent db connection could cause invalid site settings to be stored It also removes a catch all we had. Somewhere around Rails 5 `db:create` started wanting full environment this is a problem for Discourse since it needs to boot up data from the db. This removes the catch all and surgically adds a db / redis bypass to db:create task. --- lib/site_settings/db_provider.rb | 7 +------ lib/tasks/db.rake | 13 ++++++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/site_settings/db_provider.rb b/lib/site_settings/db_provider.rb index 40c3f823e2d..6f291995d35 100644 --- a/lib/site_settings/db_provider.rb +++ b/lib/site_settings/db_provider.rb @@ -58,12 +58,7 @@ class SiteSettings::DbProvider # table is not in the db yet, initial migration, etc def table_exists? @table_exists ||= {} - begin - @table_exists[current_site] ||= ActiveRecord::Base.connection.table_exists?(@model.table_name) - rescue - STDERR.puts "No connection to db, unable to retrieve site settings! (normal when running db:create)" - @table_exists[current_site] = false - end + @table_exists[current_site] ||= ActiveRecord::Base.connection.table_exists?(@model.table_name) end end diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index b5e4d77d3be..d55ecb6d3c7 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -21,12 +21,23 @@ task 'db:environment:set' => [:load_config] do |_, args| end end -task 'db:create' => [:load_config] do |_, args| +task 'db:force_skip_persist' do + GlobalSetting.skip_db = true + GlobalSetting.skip_redis = true +end + +task 'db:create' do |_, args| if MultisiteTestHelpers.load_multisite? system("RAILS_DB=discourse_test_multisite rake db:create") end end +begin + reqs = Rake::Task['db:create'].prerequisites.map(&:to_sym) + Rake::Task['db:create'].clear_prerequisites + Rake::Task['db:create'].enhance(["db:force_skip_persist"] + reqs) +end + task 'db:drop' => [:load_config] do |_, args| if MultisiteTestHelpers.load_multisite? system("RAILS_DB=discourse_test_multisite rake db:drop")