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

[POOL-608] allow for case insensitive users search by email #1283

Merged

Conversation

srenatus
Copy link
Contributor

So far, this is for GET /users?email=foo%40bar.com, and adding an index to make this not super slow (not verified if it's strictly necessary, so if tests in hosted reveal that we don't need this, we could drop b358900).

It doesn't yet forbid creating a second user with the same email (case sensitively).

@stevendanna
Copy link
Contributor

I believe we will need a partybus migration to deploy the new sqitch index on upgrades.

@srenatus srenatus force-pushed the sr/pool-608/search-users-by-case-insenstive-email branch from b358900 to 50c6112 Compare May 30, 2017 13:58
@srenatus srenatus changed the title [POOL-608] allow for case insensitive users search by email HOLD [POOL-608] allow for case insensitive users search by email May 30, 2017
@srenatus
Copy link
Contributor Author

We've come to the conclusion that this is a cumbersome approach, and that it might be easier to get a migration in place for changing email's column type from text to citext (case insensitive). (That way, we've got stronger guarantees and less to worry about when it comes to inserting/updating data with properly downcased emails.)

I'll put this branch on hold and start another one for the migration.

@srenatus srenatus force-pushed the sr/pool-608/search-users-by-case-insenstive-email branch from 50c6112 to 8d50b22 Compare May 31, 2017 09:20
@srenatus
Copy link
Contributor Author

After some more discussion, it might be the case that the best compromise is as follows:

  1. query case insensitively
  2. make manage react properly when more than one user with this email (or eMAIL or Email) is returned
  3. ignore that the situation could be created again by someone adding a user record with a differently cased email

That way we don't need a migration. Also, we wave off any guarantees of duplicate entries not happening -- they may be there already (and we can't fix those), so they may be added as well. They just may be there.

@srenatus
Copy link
Contributor Author

This would be good to go. Just waiting for chef/chef-zero#265 to merge so we can drop 8d50b22.

@srenatus srenatus force-pushed the sr/pool-608/search-users-by-case-insenstive-email branch from 8d50b22 to f401d6e Compare June 1, 2017 08:26
@srenatus
Copy link
Contributor Author

srenatus commented Jun 1, 2017

The chef-zero change this depends on has been merged ✔️

The only missing bit is asking ops if creating that index will be fine as-is for hosted. ✔️


-- TODO 2017/05/30 sr: check with ops if this should include CONCURRENTLY
-- https://www.postgresql.org/docs/9.2/static/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY
CREATE INDEX users_lower_email_idx ON users (lower(email));
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should only create the index if it doesn't exist, that way ops can deploy it different if they choose to and this will still be safe to run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uhm, yeah, that's a good idea. CREATE INDEX IF NOT EXISTS it shall be.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, I think CREATE INDEX IF NOT EXISTS isn't supported in 9.2. This stack-overflow answer presents alternatives for different versions:

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would have been sooo nice. But thanks! 😃

@srenatus srenatus force-pushed the sr/pool-608/search-users-by-case-insenstive-email branch from e227807 to 4069b32 Compare June 1, 2017 14:49
@srenatus srenatus changed the title HOLD [POOL-608] allow for case insensitive users search by email [POOL-608] allow for case insensitive users search by email Jun 2, 2017
@srenatus
Copy link
Contributor Author

srenatus commented Jun 2, 2017

I don't believe this has to be held back anymore. The index creation is done concurrently now, and the corresponding verification disabled. No user should be hurt in the process.

@srenatus srenatus force-pushed the sr/pool-608/search-users-by-case-insenstive-email branch from 4069b32 to 60f00a2 Compare June 2, 2017 11:40
@stevendanna
Copy link
Contributor

cc @chef/chef-server-maintainers

@marcparadise marcparadise force-pushed the sr/pool-608/search-users-by-case-insenstive-email branch 2 times, most recently from 37b429e to bbef679 Compare June 7, 2017 16:05
Also adds tests to pedant that failed before.

Signed-off-by: Stephan Renatus <srenatus@chef.io>
Signed-off-by: Stephan Renatus <srenatus@chef.io>
Signed-off-by: Stephan Renatus <srenatus@chef.io>
Signed-off-by: Stephan Renatus <srenatus@chef.io>
This doesn't work with PG 9.6.

Signed-off-by: Stephan Renatus <srenatus@chef.io>
@marcparadise marcparadise merged commit 95a5cd2 into master Jun 7, 2017
@marcparadise marcparadise deleted the sr/pool-608/search-users-by-case-insenstive-email branch June 7, 2017 16:16
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.

3 participants