Rails 7 + multiple databases with Active Record is failing coz of this gem
kapso opened this issue · 1 comments
kapso commented
Steps to reproduce
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
class ReadReplicaRecord < ApplicationRecord
self.abstract_class = true
connects_to database: { writing: :primary, reading: :primary_replica }
end
class User < ReadReplicaRecord
end
database.yml
default: &default
adapter: postgresql
encoding: unicode
host: localhost
username: db_user
password:
development:
primary:
<<: *default
url: postgres://db_user:@localhost:5432/db_name
primary_replica:
<<: *default
url: postgres://db_user:@localhost:5432/db_name
The following fails, (if you remove the ros-apartment
gem, it will work)
ReadReplicaRecord.connected_to(role: :reading) do
User.count
end
Additional NOTES
- You don't even need to define -
config/initializers/apartment.rb
- This failure only happens in
Rails 7
- Rails 6.x works fine
- Multiple Databases with Active Record - https://guides.rubyonrails.org/active_record_multiple_databases.html
Expected behavior (without ros-apartment
gem)
Loading development environment (Rails 7.0.2.2)
irb(main):001:1* ReadReplicaRecord.connected_to(role: :reading) do
irb(main):002:1* User.count
irb(main):003:0> end
User Count (1.0ms) SELECT COUNT(*) FROM "users"
=> 80
Actual behavior (with ros-apartment
gem)
irb(main):001:1* ReadReplicaRecord.connected_to(role: :reading) do
irb(main):002:1* User.count
irb(main):003:0> end
/Users/kapil/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/activerecord-7.0.2.2/lib/active_record/connection_handling.rb:137:in `connected_to': unknown keyword: :database (ArgumentError)
System configuration
Rails 7.0.2.2
Ruby 3.1.0
ros-apartment 2.11.0
PostgreSQL 14.1