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

Avoid false positives on case-insensitive unique indexes when using CITEXT fields #168

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

gee-forr
Copy link

This should resolve #167

Hi there @gregnavis and @fatkodima

Please take a look at this PR and let me know if you need any changes. I wasn't able to run tests locally, so I took my best stab at getting them to work. I'll fix them if they break on CI.

Thanks so much for this great gem - I'm happy to have been able to contribute, even in this tiny way :)

@fatkodima
Copy link
Contributor

Please, make sure, that commits are squashed into one.

@gee-forr
Copy link
Author

Please, make sure, that commits are squashed into one.

Hi @fatkodima - apologies if I'm misunderstanding -- but won't you merge my PR in via a squash once it's ready?

I don't know yet if this PR needs any more fixes or amendments either.

Copy link
Owner

@gregnavis gregnavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. I left some minor comments.

Re squashing: no need to worry about that. I squash commit when merging PRs.

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -66,6 +66,7 @@ def validations_without_indexes
columns[-1] = "lower(#{columns[-1]})" unless case_sensitive

next if unique_index?(model.table_name, columns)
next if model.columns_hash[attribute.to_s]&.type == :citext # citext is case-insensitive by default
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions:

  1. Why is &. needed here?
  2. If we change &. to just ., will the test suite fail?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @gregnavis - It failed on a few tests so I added it in.

Do you think there's possibly a less inelegant way to handle this? I'm not a super fan of the safe-navigation operator myself, and it's normally indicative of a code smell of some sort, but I didn't see a way around it without making the code really contort itself to avoid it.

Let me know if you've got a preferred way to not use &.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @gregnavis - checking in to see if you're happy with my response on ☝🏻 and if there's any other changes you'd like to see?

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

Successfully merging this pull request may close these issues.

False positives when case-insensitive unique indexes have CITEXT strings
3 participants