1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test
Eileen Uchitelle f39d72d526 Add ability to prevent writes to a database
This PR adds the ability to prevent writes to a database even if the
database user is able to write (ie the database is a primary and not a
replica).

This is useful for a few reasons: 1) when converting your database from
a single db to a primary/replica setup - you can fix all the writes on
reads early on, 2) when we implement automatic database switching or
when an app is manually switching connections this feature can be used
to ensure reads are reading and writes are writing. We want to make sure
we raise if we ever try to write in read mode, regardless of database
type and 3) for local development if you don't want to set up multiple
databases but do want to support rw/ro queries.

This should be used in conjunction with `connected_to` in write mode.
For example:

```
ActiveRecord::Base.connected_to(role: :writing) do
  Dog.connection.while_preventing_writes do
    Dog.create! # will raise because we're preventing writes
  end
end

ActiveRecord::Base.connected_to(role: :reading) do
  Dog.connection.while_preventing_writes do
    Dog.first # will not raise because we're not writing
  end
end
```
2018-11-30 09:28:04 -05:00
..
active_record/connection_adapters Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
assets
cases Add ability to prevent writes to a database 2018-11-30 09:28:04 -05:00
fixtures Lazy checking whether or not values in IN clause are boundable 2018-10-24 11:26:49 +09:00
migrations Fix occurrences Fixnum|Bignum 2018-03-04 20:44:30 +02:00
models Merge pull request #34572 from kamipo/fix_scoping_with_query_method 2018-11-30 21:41:12 +09:00
schema Use squiggly heredoc to strip odd indentation in the executed SQL 2018-11-22 19:43:53 +09:00
support Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
config.example.yml Bump the minimum version of PostgreSQL to 9.3 2018-11-25 13:13:08 +00:00
config.rb Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00