From f530378df336051bdfac7c418eb2c4ab4726c9b2 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Thu, 24 Oct 2019 11:46:22 +1100 Subject: [PATCH] FIX: Restore for non-multisite is not raising an error on reconnect step (#8237) That commit introduced a bug to the system: https://github.com/discourse/discourse/commit/f69dacf979317946ed4a3e81e85fcca1b45bedf0 Restore works fine for multisite, however, stopped working for non-multisite. Reason for that was that `establish_connection` method got a check if the multisite instance is available: ``` def self.instance @instance end def self.establish_connection(opts) @instance.establish_connection(opts) if @instance end ``` However, the reload method don't have that check ``` def self.reload @instance = new(instance.config_filename) end ``` To solve it, let's ensure we are in a multisite environment before call reload --- lib/backup_restore/restorer.rb | 2 +- spec/lib/backup_restore/restorer_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb index 1efceafd128..8d902da8a14 100644 --- a/lib/backup_restore/restorer.rb +++ b/lib/backup_restore/restorer.rb @@ -404,7 +404,7 @@ module BackupRestore def reconnect_database log "Reconnecting to the database..." - RailsMultisite::ConnectionManagement::reload + RailsMultisite::ConnectionManagement::reload if RailsMultisite::ConnectionManagement::instance RailsMultisite::ConnectionManagement::establish_connection(db: @current_db) end diff --git a/spec/lib/backup_restore/restorer_spec.rb b/spec/lib/backup_restore/restorer_spec.rb index 8bd311580f4..4eac39bdd85 100644 --- a/spec/lib/backup_restore/restorer_spec.rb +++ b/spec/lib/backup_restore/restorer_spec.rb @@ -124,5 +124,10 @@ describe BackupRestore::Restorer do restorer.send(:reconnect_database) expect(RailsMultisite::ConnectionManagement.current_db).to eq('second') end + + it 'it is not erroring for non multisite' do + RailsMultisite::ConnectionManagement::clear_settings! + expect{ restorer.send(:reconnect_database) }.not_to raise_error + end end end