Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate uniqueness of causing reads to go to master #30

Closed
ccastaneda13 opened this issue Oct 9, 2018 · 2 comments
Closed

Validate uniqueness of causing reads to go to master #30

ccastaneda13 opened this issue Oct 9, 2018 · 2 comments

Comments

@ccastaneda13
Copy link

Using fresh_connection 2.4.4 and when trying to create a record that has a uniqueness validation, the query checks for existence of the record against master and not replica. Is there any way to force the query to go to replica? Thanks

Running Rails 4.2.7
Ruby 2.3.4

@tsukasaoishi
Copy link
Owner

tsukasaoishi commented Oct 9, 2018

The validation query must be executed on master DB.
Because of you can't validate when replication delay occurs.

example:

class User
  validates :email, uniqueness: true
end

User.create!(email: "tsukasa.oishi@gmail.com")
# If replication delay is occuring, the following query will succeed!
User.create!(email: "tsukasa.oishi@gmail.com")

@ccastaneda13
Copy link
Author

@tsukasaoishi thanks for the response! I see, will move the constraint to the database and remove the AR validation to avoid this query going to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants