avram icon indicating copy to clipboard operation
avram copied to clipboard

Specify read/write databases

Open paulcsmith opened this issue 6 years ago • 1 comments

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

paulcsmith avatar Jul 09 '19 18:07 paulcsmith

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

matthewmcgarvey avatar Jan 06 '21 16:01 matthewmcgarvey