validates_uniqueness_of should honor the collation#13465
Closed
shugo wants to merge 1 commit intorails:masterfrom
Closed
validates_uniqueness_of should honor the collation#13465shugo wants to merge 1 commit intorails:masterfrom
shugo wants to merge 1 commit intorails:masterfrom
Conversation
…ption of validates_uniqueness_of is omitted.
Member
There was a problem hiding this comment.
Is it case-sensitive by default for all adapters?
Contributor
Author
There was a problem hiding this comment.
Yes, it is. An adapter should override it, if necessary.
Contributor
|
Is this still relevant? Otherwise, it's stale and should be closed. |
kamipo
added a commit
that referenced
this pull request
Feb 21, 2019
…collation issues In MySQL, the default collation is case insensitive. Since the uniqueness validator enforces case sensitive comparison by default, it frequently causes mismatched collation issues (performance, weird behavior, etc) to MySQL users. https://grosser.it/2009/12/11/validates_uniqness_of-mysql-slow/ #1399 #13465 gitlabhq/gitlabhq@c1dddf8 huginn/huginn#1330 (comment) This extracts `default_uniqueness_comparison` to ease to handle the mismatched collation issues on the connection.
kamipo
added a commit
to kamipo/rails
that referenced
this pull request
Mar 4, 2019
In MySQL, the default collation is case insensitive. Since the uniqueness validator enforces case sensitive comparison by default, it frequently causes mismatched collation issues (performance, weird behavior, etc) to MySQL users. https://grosser.it/2009/12/11/validates_uniqness_of-mysql-slow/ rails#1399 rails#13465 gitlabhq/gitlabhq@c1dddf8 huginn/huginn#1330 (comment) I'd like to deprecate the implicit default enforcing since I frequently experienced the problems in code reviews. Note that this change has no effect to sqlite3, postgresql, and oracle-enhanced adapters which are implemented as case sensitive by default, only affect to mysql2 adapter (I can take a work if sqlserver adapter will support Rails 6.0).
Member
|
This will be fixed in Rails 6.1. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, if the case_sensitive option of
validates_uniqueness_ofis omitted,trueis used by default.However, the default collation of MySQL for
rake db:create:allin Rails isutf8_unicode_ci, which means that you need to specifycase_sensitive: falsefor eachvalidates_uniqueness_of, except when the collation is explicitly set to*_bin. Otherwise, a DB-level unique constraint violation may occur even if the AR-level validation succeeded.In MySQL each column has its own collation, and the preferred case sensitivity can be guessed from the value of the collation. Why not use the guessed value as the default?