From 6d764da48dccec44f707d62dcc6aa4fbd2562c02 Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Thu, 19 Jan 2017 10:53:59 +0100 Subject: [PATCH] Prevent getting table info if not connected to db Fixes #327 When precompiling assets while building a docker image, the database is not available and the DeviseTokenAuth::Concerns::User concern tries to load user table information from database and fails. It now checks if the database connection is available before gathering information about user table. --- app/models/devise_token_auth/concerns/user.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/devise_token_auth/concerns/user.rb b/app/models/devise_token_auth/concerns/user.rb index df097b846..3c0097477 100644 --- a/app/models/devise_token_auth/concerns/user.rb +++ b/app/models/devise_token_auth/concerns/user.rb @@ -95,7 +95,15 @@ module ClassMethods def tokens_has_json_column_type? - table_exists? && self.columns_hash['tokens'] && self.columns_hash['tokens'].type.in?([:json, :jsonb]) + database_exists? && table_exists? && self.columns_hash['tokens'] && self.columns_hash['tokens'].type.in?([:json, :jsonb]) + end + + def database_exists? + ActiveRecord::Base.connection + rescue ActiveRecord::NoDatabaseError + false + else + true end end