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.
This commit is contained in:
Sam Saffron 2019-06-14 14:20:48 +10:00
parent 62f4284865
commit 3af00a65e6
2 changed files with 13 additions and 7 deletions

View File

@ -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
end
end

View File

@ -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")