We added a check for ConnectionNotEstablished, which causes the check to return false if there is no database available (the case in buildkite for rake tasks like assets:precompile), this changed the implementation from an existence check (I can connect to the database, but the table is not present, the situation when we have created a db, but not yet populated the schema) to an availability check (either the db is live but the table is absent, or the db is absent, in either case we know we can't read from the table yet). Change table_exists? to table_available? to indicate the new behavior and update the two call sites.
13 lines
499 B
Ruby
13 lines
499 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_available?(table)
|
|
ActiveRecord::Base.connection.table_exists?(table)
|
|
rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished
|
|
false
|
|
end
|
|
end
|