From bbd721b10ad74cd359326744d163a667b59cc5f5 Mon Sep 17 00:00:00 2001 From: moskirathe Date: Thu, 25 Jun 2026 22:57:37 -0400 Subject: [PATCH 1/3] Stop updating user username via background job and on login --- crates/crates_io_database/src/models/user.rs | 1 - src/worker/jobs/update_user_from_github.rs | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/crates_io_database/src/models/user.rs b/crates/crates_io_database/src/models/user.rs index f765d37da91..1c817440f1f 100644 --- a/crates/crates_io_database/src/models/user.rs +++ b/crates/crates_io_database/src/models/user.rs @@ -125,7 +125,6 @@ impl NewUser<'_> { .do_update() .set(( users::gh_login.eq(excluded(users::gh_login)), - users::username.eq(excluded(users::username)), users::name.eq(excluded(users::name)), users::gh_encrypted_token.eq(excluded(users::gh_encrypted_token)), )) diff --git a/src/worker/jobs/update_user_from_github.rs b/src/worker/jobs/update_user_from_github.rs index 12e6c900b39..e5ef15c4b23 100644 --- a/src/worker/jobs/update_user_from_github.rs +++ b/src/worker/jobs/update_user_from_github.rs @@ -167,10 +167,7 @@ impl UpdateUserFromGithub { if oauth_github.login != github_user.login { diesel::update(users::table) .filter(users::id.eq(oauth_github.user_id)) - .set(( - users::gh_login.eq(&github_user.login), - users::username.eq(&github_user.login), - )) + .set(users::gh_login.eq(&github_user.login)) .execute(conn) .await?; } From f4d2a978839187c988883c70189b268e5d91211f Mon Sep 17 00:00:00 2001 From: moskirathe Date: Thu, 25 Jun 2026 23:26:54 -0400 Subject: [PATCH 2/3] fix test - no longer need to assert that username is updated when user updates or deletes gh account --- src/tests/worker/update_user_from_github.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tests/worker/update_user_from_github.rs b/src/tests/worker/update_user_from_github.rs index 32727e0f517..3824df260d4 100644 --- a/src/tests/worker/update_user_from_github.rs +++ b/src/tests/worker/update_user_from_github.rs @@ -82,7 +82,6 @@ impl UpdateTest { // For now, we want to update the `User` record too let user_after_update = User::find(&conn, user_id).await?; assert_eq!(user_after_update.gh_login, expected_username); - assert_eq!(user_after_update.username, expected_username); if job_result.is_err() { // The worker leaves failed rows in `background_jobs` so they can From 2a601cea8c5109774158c48223cb8bf955d363ce Mon Sep 17 00:00:00 2001 From: moskirathe Date: Fri, 3 Jul 2026 08:34:48 -0400 Subject: [PATCH 3/3] assert that username remains unchanged after user github update --- src/tests/user.rs | 2 ++ src/tests/worker/update_user_from_github.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/tests/user.rs b/src/tests/user.rs index b00f775ee3c..537726ee54c 100644 --- a/src/tests/user.rs +++ b/src/tests/user.rs @@ -51,6 +51,8 @@ async fn updating_existing_user_doesnt_change_api_token() -> anyhow::Result<()> let user = assert_ok!(User::find(&conn, api_token.user_id).await); assert_eq!(user.gh_login, "bar"); + // updating existing user should not change their username + assert_eq!(user.username, "foo"); let decrypted_token = encryption.decrypt(&user.gh_encrypted_token)?; assert_eq!(decrypted_token.expose_secret(), "bar_token"); diff --git a/src/tests/worker/update_user_from_github.rs b/src/tests/worker/update_user_from_github.rs index 3824df260d4..06f8bf80c49 100644 --- a/src/tests/worker/update_user_from_github.rs +++ b/src/tests/worker/update_user_from_github.rs @@ -82,6 +82,8 @@ impl UpdateTest { // For now, we want to update the `User` record too let user_after_update = User::find(&conn, user_id).await?; assert_eq!(user_after_update.gh_login, expected_username); + // The user's username should not be updated + assert_eq!(user_after_update.username, existing_gh_user.login); if job_result.is_err() { // The worker leaves failed rows in `background_jobs` so they can