From f464e5ef5826c07936261fc9a49212133b871dc1 Mon Sep 17 00:00:00 2001 From: markokajzer Date: Wed, 27 Nov 2024 12:55:11 +0100 Subject: [PATCH] fix(ActiveRecord): correctly connect to the database in Rails 7.2+ --- .../config/database_adapters/activerecord.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb b/lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb index d7ea4ad..6e35d56 100644 --- a/lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb +++ b/lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb @@ -6,7 +6,12 @@ module SlackRubyBotServer module DatabaseAdapter def self.check! - ActiveRecord::Base.connection_pool.with_connection(&:active?) + if ActiveRecord::VERSION::STRING >= "7.2" + raise "Database does not exist." unless ActiveRecord::Base.connection.database_exists? + else + ActiveRecord::Base.connection_pool.with_connection(&:active?) + end + raise 'Unexpected error.' unless ActiveRecord::Base.connected? rescue StandardError => e warn "Error connecting to PostgreSQL: #{e.message}"