incorrect_length_validation-check: Consider check constraints with column lenght limits#218
Open
fatkodima wants to merge 1 commit into
Open
Conversation
gregnavis
requested changes
Apr 24, 2025
gregnavis
left a comment
Owner
There was a problem hiding this comment.
I love the idea! I left a suggestion on how to improve it: support columns with both column and check limits + add support for <.
| end | ||
|
|
||
| def column_limit(table, column) | ||
| return column.limit if column.limit |
Owner
There was a problem hiding this comment.
There's an edge case we need to handle: a column can have both a limit and a check constraint. I suggest we add a method check_constraint_length_limit and pick the minimum of column.limit and check_constraint_length_limit(table, column).
| return column.limit if column.limit | ||
|
|
||
| # Example: char_length(name::text) <= 64 | ||
| pattern = /(char_|character_)?length\(['"`]?#{column.name}(::text)?['"`]?\)\s*<=\s*(?<limit>\d+)/i |
Owner
There was a problem hiding this comment.
I suggest we add support for both < and <= and adjust the limit accordingly, i.e. < 100 means the limit is <= 99.
…lumn lenght limits
fc2fe26 to
b3e2816
Compare
Contributor
Author
|
Made changes. |
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.
In postgres, when adding a limit to some existing text column, it will exclusively lock the table (preventing reads and writes) until the column data is verified and the column is changed. This is problematic for large tables and a different approach is usually used - check constraints with length limit (e.g.
CHECK (length(email) <= 64)).This PR extends existing checker to account for this.