Is it possible to disallow writes?
cjlarose opened this issue · comments
Chris LaRose commented
I'm interested in making specific blocks of code in my application perform reads from the slave pool, but they shouldn't try to write. I'd like to prevent application developers from accidentally writing code that doesn't correctly account for replication lag and other impacts brought on by reading from a slave, then writing to the primary.
Is something like this already possible with this gem? If not, I'm curious on your thoughts of a allow_writes
option that's on by default, but can be disabled. Alternatively, there could be a raise_on_attempted_writes
option that's false by default.
distribute_reads(allow_writes: false) do
User.find_each do |user| # replica
user.orders_count = user.orders.count # replica
user.save! # raise an exception
end
end
Andrew Kane commented
Chris LaRose commented