fix(backend): propagate user renames to artist and harden migration backfill
Code review of the Artist/ownership refactor surfaced three gaps: - SyncUser updated User.Name on every login but never the linked Artist row, so renames never reached track credits - defeating the point of centralizing names in Artist. - YouTubeTrackProvisioner looked up artists by ExternalId only when a browseId was known, so it could never reuse the ExternalId-less rows the migration backfilled from legacy Artist strings, creating duplicate Artist rows for the same person. It now adopts the backfilled row (assigning it the browseId) when one matches by normalized name. - AddArtistsAndTrackOwnership deduped legacy YouTube artist strings case-sensitively before hashing them into a case-insensitive unique index, and never guarded against local tracks with no UserHasTrack row - either would abort the migration on real data. Backfill now dedupes via DISTINCT ON over the normalized name and drops orphaned local tracks before the ownership check constraint is added.
This commit is contained in:
@@ -47,6 +47,14 @@ namespace Musify.Application.Users
|
||||
user.SecondName = request.SecondName;
|
||||
user.ProfilePictureUrl = request.ProfilePictureUrl;
|
||||
|
||||
var artist = await database.Artists
|
||||
.SingleOrDefaultAsync(a => a.UserId == request.Id, cancellationToken);
|
||||
if (artist is not null)
|
||||
{
|
||||
artist.Name = request.Name;
|
||||
artist.NormalizedName = request.Name.ToUpperInvariant();
|
||||
}
|
||||
|
||||
var written = await database.SaveChangesAsync(cancellationToken);
|
||||
if (written > 0)
|
||||
logger.LogInformation("Synced profile for user {UserId}", request.Id);
|
||||
|
||||
Reference in New Issue
Block a user