Commit 6acfb924 authored by Rémy Coutable's avatar Rémy Coutable Committed by Kirill Smelkov

Use ActiveRecord::Base.connection.active? and rescue any exception in connect_to_db?

( cherry picked from commit 55ab92c0 upstream )

This ensures that rake tasks that don't need a DB connection can be run
without one.
parent 0bd70b79
......@@ -41,8 +41,11 @@ module Gitlab
private
def connect_to_db?
# When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised
active_db_connection = ActiveRecord::Base.connection.active? rescue false
ENV['USE_DB'] != 'false' &&
ActiveRecord::Base.connection_pool.active_connection? &&
active_db_connection &&
ActiveRecord::Base.connection.table_exists?('application_settings')
rescue ActiveRecord::NoDatabaseError
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment