@@ -138,7 +138,7 @@ class Person < PrimaryApplicationRecord
138
138
end
139
139
` ` `
140
140
141
- On the other hand, we need to setup our models persisted in the "animals" database :
141
+ On the other hand, we need to set up our models persisted in the "animals" database :
142
142
143
143
` ` ` ruby
144
144
class AnimalsRecord < ApplicationRecord
@@ -212,7 +212,7 @@ db:setup:primary # Create the primary database, loads the sche
212
212
213
213
Running a command like `bin/rails db:create` will create both the primary and animals databases.
214
214
Note that there is no command for creating the database users, and you'll need to do that manually
215
- to support the readonly users for your replicas. If you want to create just the animals
215
+ to support the read-only users for your replicas. If you want to create just the animals
216
216
database you can run `bin/rails db:create:animals`.
217
217
218
218
# # Connecting to Databases without Managing Schema and Migrations
@@ -295,8 +295,8 @@ use a different parent class.
295
295
Finally, in order to use the read-only replica in your application, you'll need to activate
296
296
the middleware for automatic switching.
297
297
298
- Automatic switching allows the application to switch from the writer to replica or replica
299
- to writer based on the HTTP verb and whether there was a recent write by the requesting user.
298
+ Automatic switching allows the application to switch from the writer to the replica or the replica
299
+ to the writer based on the HTTP verb and whether there was a recent write by the requesting user.
300
300
301
301
If the application receives a POST, PUT, DELETE, or PATCH request, the application will
302
302
automatically write to the writer database. If the request is not one of those methods,
@@ -328,7 +328,7 @@ to the replicas unless they wrote recently.
328
328
329
329
The automatic connection switching in Rails is relatively primitive and deliberately doesn't
330
330
do a whole lot. The goal is a system that demonstrates how to do automatic connection
331
- switching that was flexible enough to be customizable by app developers.
331
+ switching that is flexible enough to be customizable by app developers.
332
332
333
333
The setup in Rails allows you to easily change how the switching is done and what
334
334
parameters it's based on. Let's say you want to use a cookie instead of a session to
@@ -392,7 +392,7 @@ using the connection specification name. This means that if you pass an unknown
392
392
like `connected_to(role : :nonexistent)` you will get an error that says
393
393
` ActiveRecord::ConnectionNotEstablished (No connection pool for 'ActiveRecord::Base' found for the 'nonexistent' role.)`
394
394
395
- If you want Rails to ensure any queries performed are read only, pass `prevent_writes : true`.
395
+ If you want Rails to ensure any queries performed are read- only, pass `prevent_writes : true`.
396
396
This just prevents queries that look like writes from being sent to the database.
397
397
You should also configure your replica database to run in read-only mode.
398
398
517
517
```
518
518
519
519
Applications must provide a resolver to provide application-specific logic. An example resolver that
520
- uses subdomain to determine the shard might look like this:
520
+ uses a subdomain to determine the shard might look like this:
521
521
522
522
``` ruby
523
523
config.active_record.shard_resolver = -> (request) {
0 commit comments