To use ActiveRecord (e.g., with PostgreSQL), add pg, activerecord, otr-activerecord, and pagy_cursor to your Gemfile. This project supports ActiveRecord/Rails major versions 6.0, 6.1, and 7.0.
- Configure the connection in
config/postgresql.yml. - Establish the connection in your startup code using
ActiveRecord::Base.establish_connection with the loaded YAML configuration.
gem 'pg'
gem 'activerecord', require: 'active_record'
gem 'slack-ruby-bot-server'
gem 'otr-activerecord'
gem 'pagy_cursor'
default: &default
adapter: postgresql
pool: 10
timeout: 5000
encoding: unicode
development:
<<: *default
database: bot_development
test:
<<: *default
database: bot_test
production:
<<: *default
database: bot
yml = ERB.new(File.read(File.expand_path('config/postgresql.yml', __dir__))).result
db_config = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1')
::YAML.safe_load(yml, aliases: true)[ENV['RACK_ENV']]
else
::YAML.safe_load(yml, [], [], true)[ENV['RACK_ENV']]
end
ActiveRecord::Base.establish_connection(db_config)