Skip to content

Commit

Permalink
Prevent getting table info if not connected to db
Browse files Browse the repository at this point in the history
Fixes lynndylanhurley#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.
  • Loading branch information
cbliard committed Jan 20, 2017
1 parent e605614 commit 6d764da
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/models/devise_token_auth/concerns/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6d764da

Please sign in to comment.