Skip to content

Commit d98ec8c

Browse files
committed
fix(ActiveRecord): correctly connect to the database in Rails 7.2+
add active_record 7.2 to ci matrix
1 parent c2bc038 commit d98ec8c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.github/workflows/test-postgresql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
- { ruby: 2.6.2, postgresql: 11, active_record: '~> 6.0.0' }
1111
- { ruby: 3.1.1, postgresql: 11, active_record: '~> 6.1.0' }
1212
- { ruby: 3.1.1, postgresql: 14, active_record: '~> 7.0.0' }
13+
- { ruby: 3.1.1, postgresql: 14, active_record: '~> 7.2.0' }
1314
name: test (ruby=${{ matrix.entry.ruby }}, postgresql=${{ matrix.entry.postgresql }}, active_record=${{ matrix.entry.active_record }})
1415
steps:
1516
- uses: actions/checkout@v2

lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
module SlackRubyBotServer
77
module DatabaseAdapter
88
def self.check!
9-
ActiveRecord::Base.connection_pool.with_connection(&:active?)
9+
if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('7.2')
10+
raise 'Database does not exist.' unless ActiveRecord::Base.connection.database_exists?
11+
else
12+
ActiveRecord::Base.connection_pool.with_connection(&:active?)
13+
end
14+
1015
raise 'Unexpected error.' unless ActiveRecord::Base.connected?
1116
rescue StandardError => e
1217
warn "Error connecting to PostgreSQL: #{e.message}"

0 commit comments

Comments
 (0)