class ActiveRecord::ConnectionAdapters::ConnectionHandler

def while_preventing_writes(enabled = true)

method.
See +READ_QUERY+ for the queries that are blocked by this

user and is meant to be a safeguard against accidental writes.
This method does not provide the same protection as a readonly

will prevent writes to the database for the duration of the block.
even if you are on a database that can write. +while_preventing_writes+
In some cases you may want to prevent writes to the database

Prevent writing to the database regardless of role.
def while_preventing_writes(enabled = true)
  unless ActiveRecord.legacy_connection_handling
    raise NotImplementedError, "`while_preventing_writes` is only available on the connection_handler with legacy_connection_handling"
  end
  original, self.prevent_writes = self.prevent_writes, enabled
  yield
ensure
  self.prevent_writes = original
end