Skip to content

Commit

Permalink
fix(ActiveRecord): correctly connect to the database in Rails 7.2+
Browse files Browse the repository at this point in the history
add active_record 7.2 to ci matrix
  • Loading branch information
markokajzer committed Nov 29, 2024
1 parent c2bc038 commit d98ec8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/test-postgresql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
- { ruby: 2.6.2, postgresql: 11, active_record: '~> 6.0.0' }
- { ruby: 3.1.1, postgresql: 11, active_record: '~> 6.1.0' }
- { ruby: 3.1.1, postgresql: 14, active_record: '~> 7.0.0' }
- { ruby: 3.1.1, postgresql: 14, active_record: '~> 7.2.0' }
name: test (ruby=${{ matrix.entry.ruby }}, postgresql=${{ matrix.entry.postgresql }}, active_record=${{ matrix.entry.active_record }})
steps:
- uses: actions/checkout@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
module SlackRubyBotServer
module DatabaseAdapter
def self.check!
ActiveRecord::Base.connection_pool.with_connection(&:active?)
if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('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}"
Expand Down

0 comments on commit d98ec8c

Please sign in to comment.