diff options
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/active_record_transaction_observer.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/config/initializers/active_record_transaction_observer.rb b/config/initializers/active_record_transaction_observer.rb index 1dc7b55ed5a..a133c6b8be8 100644 --- a/config/initializers/active_record_transaction_observer.rb +++ b/config/initializers/active_record_transaction_observer.rb @@ -3,7 +3,20 @@ return unless Gitlab.com? || Gitlab.dev_or_test_env? Gitlab::Application.configure do - if Feature.feature_flags_available? && ::Feature.enabled?(:active_record_transactions_tracking, type: :ops) + # When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised + active_db_connection = begin + ActiveRecord::Base.connection.active? # rubocop:disable Database/MultipleDatabases + rescue StandardError + false + end + + feature_flags_available = begin + active_db_connection && Feature::FlipperFeature.table_exists? + rescue ActiveRecord::NoDatabaseError + false + end + + if feature_flags_available && ::Feature.enabled?(:active_record_transactions_tracking, type: :ops) Gitlab::Database::Transaction::Observer.register! end end |