avram
avram copied to clipboard
Specify read/write databases
Extracted from #9
abstract class BaseModel < Avram::Model
def database
PrimaryDatabase
end
# Or set separate read/write database
def read_database
ReplicaDatabase
end
def write_database
PrimaryDatabase
end
end
This will be super easy to implement except for the specs. Need to think of a reliable way to do test it
There's going to have to be some way to specify to all of Avram which connection to use and not just in a particular model. If I write to the database and then later query it in the same request, I expect my changes to be there but they might not have been propagated to the read-replica yet.
Rails lays out some ways they handle it here https://guides.rubyonrails.org/active_record_multiple_databases.html