From 4eb1681658d9eed8f78dd04a4ce34d38211eb2d4 Mon Sep 17 00:00:00 2001 From: Arthur Dingemans Date: Fri, 13 Mar 2020 14:27:06 +0100 Subject: [PATCH] Don't crash when no database connection is present --- lib/apartment/railtie.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/apartment/railtie.rb b/lib/apartment/railtie.rb index b33cab2d..e082ab9e 100644 --- a/lib/apartment/railtie.rb +++ b/lib/apartment/railtie.rb @@ -35,9 +35,12 @@ class Railtie < Rails::Railtie Apartment::Tenant.init end # rubocop:disable Lint/SuppressedException - rescue ::ActiveRecord::NoDatabaseError + rescue ::ActiveRecord::NoDatabaseError, PG::ConnectionBad # Since `db:create` and other tasks invoke this block from Rails 5.2.0, # we need to swallow the error to execute `db:create` properly. + Rails.logger.warn do + 'Failed to initialize Apartment because a database connection could not be established.' + end end # rubocop:enable Lint/SuppressedException end