When building containers, when there is no postgresql instance, this check to AR::Base.connection is raising an error. We'd like to be able to continue running `rake assets:precompile` without needing a live db to check the schema for a table. Handle connection errors as though they were a table missing.
13 lines
496 B
Ruby
13 lines
496 B
Ruby
# Database related utility functions
|
|
module Database
|
|
# Checks if the database is ready and the specified table exists. This can be
|
|
# useful during bin/setup and similar tasks. It also works if the connection
|
|
# hasn't been established yet.
|
|
#
|
|
# @param table [String] the name of the table to check for
|
|
def self.table_exists?(table)
|
|
ActiveRecord::Base.connection.table_exists?(table)
|
|
rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished
|
|
false
|
|
end
|
|
end
|