-
Notifications
You must be signed in to change notification settings - Fork 655
Gh login cant be unique #1109
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
Merged
bors-voyager
merged 4 commits into
rust-lang:master
from
integer32llc:gh_login_cant_be_unique
Oct 9, 2017
Merged
Gh login cant be unique #1109
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e7a490b
Remove unique gh_login index migration because it can't run on prod
carols10cents 10d88b1
Create migrations to fix anyone's local db if they ran 2017-09-26-200549
carols10cents 40ca32d
When there are users with same gh_login, choose the latest id
carols10cents e691e75
Add a regular, non-unique index on lower(gh_login)
carols10cents File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
DROP INDEX lower_gh_login; | ||
ALTER TABLE users DROP CONSTRAINT unique_gh_login; | ||
CREATE INDEX index_users_gh_login ON users (gh_login); | ||
-- This migration intentionally left blank; see corresponding up.sql |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
DROP INDEX IF EXISTS index_users_gh_login; | ||
ALTER TABLE users ADD CONSTRAINT unique_gh_login UNIQUE(gh_login); | ||
CREATE UNIQUE INDEX lower_gh_login ON users (lower(gh_login)); | ||
-- This migration was merged into the master branch but could not be deployed to production | ||
-- because production gh_login isn't actually unique. Later, this migration was commented out | ||
-- so that it will be a no-op on production, and a new migration was added to correct the database | ||
-- of anyone who ran this migration locally. | ||
-- | ||
-- DROP INDEX IF EXISTS index_users_gh_login; | ||
-- ALTER TABLE users ADD CONSTRAINT unique_gh_login UNIQUE(gh_login); | ||
-- CREATE UNIQUE INDEX lower_gh_login ON users (lower(gh_login)); | ||
SELECT 1; |
1 change: 1 addition & 0 deletions
1
migrations/2017-10-06-234455_fix_local_dbs_unique_gh_login/down.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- This file intentionally left blank; see the corresponding up.sql |
7 changes: 7 additions & 0 deletions
7
migrations/2017-10-06-234455_fix_local_dbs_unique_gh_login/up.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- This migration should have no effect on production. | ||
-- Its sole purpose is to fix the local database of anyone who ran 2017-09-26-200549 locally-- | ||
-- that migration can't be run on production because lower(gh_login) isn't unique on production. | ||
|
||
CREATE INDEX IF NOT EXISTS index_users_gh_login ON users (gh_login); | ||
ALTER TABLE users DROP CONSTRAINT IF EXISTS unique_gh_login; | ||
DROP INDEX IF EXISTS lower_gh_login; |
2 changes: 2 additions & 0 deletions
2
migrations/2017-10-09-135625_add_lower_gh_login_index/down.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DROP INDEX IF EXISTS lower_gh_login; | ||
CREATE INDEX index_users_gh_login ON users (gh_login); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DROP INDEX IF EXISTS index_users_gh_login; | ||
CREATE INDEX lower_gh_login ON users (lower(gh_login)); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,20 +81,46 @@ fn show() { | |
} | ||
|
||
#[test] | ||
fn show_case_insensitive() { | ||
fn show_latest_user_case_insensitively() { | ||
let (_b, app, middle) = ::app(); | ||
{ | ||
let conn = t!(app.diesel_database.get()); | ||
|
||
// Please do not delete or modify the setup of this test in order to get it to pass. | ||
// This setup mimics how GitHub works. If someone abandons a GitHub account, the username is | ||
// available for anyone to take. We need to support having multiple user accounts | ||
// with the same gh_login in crates.io. `gh_id` is stable across renames, so that field | ||
// should be used for uniquely identifying GitHub accounts whenever possible. For the | ||
// crates.io/user/:username pages, the best we can do is show the last crates.io account | ||
// created with that username. | ||
t!( | ||
NewUser::new(1, "foobar", Some("[email protected]"), None, None, "bar") | ||
.create_or_update(&conn) | ||
NewUser::new( | ||
1, | ||
"foobar", | ||
Some("[email protected]"), | ||
Some("I was first then deleted my github account"), | ||
None, | ||
"bar" | ||
).create_or_update(&conn) | ||
); | ||
t!( | ||
NewUser::new( | ||
2, | ||
"FOOBAR", | ||
Some("[email protected]"), | ||
Some("I was second, I took the foobar username on github"), | ||
None, | ||
"bar" | ||
).create_or_update(&conn) | ||
); | ||
} | ||
let mut req = ::req(app.clone(), Method::Get, "api/v1/users/fOObAr"); | ||
let mut response = ok_resp!(middle.call(&mut req)); | ||
let json: UserShowPublicResponse = ::json(&mut response); | ||
assert_eq!("foobar", json.user.login); | ||
assert_eq!( | ||
"I was second, I took the foobar username on github", | ||
json.user.name.unwrap() | ||
); | ||
} | ||
|
||
#[test] | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still want this index to be on the lowercase name though, don't we? Should we have another migration that is along the lines of:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good call!