using System; using System.Threading; using System.Threading.Tasks; using Jellyfin.Database.Implementations; using MediaBrowser.Controller.Configuration; using Microsoft.EntityFrameworkCore; namespace Jellyfin.Server.Migrations.Routines; /// /// Part 2 Migration for NormalisedUsername. /// [JellyfinMigration("2026-05-22T09:23:04", nameof(UpdateNormalizedUsername), Stage = Stages.JellyfinMigrationStageTypes.CoreInitialisation)] #pragma warning disable SA1649 // File name should match first type name public class UpdateNormalizedUsername : IAsyncMigrationRoutine #pragma warning restore SA1649 // File name should match first type name { private readonly IDbContextFactory _contextFactory; /// /// Initializes a new instance of the class. /// /// Db Context factory. public UpdateNormalizedUsername(IDbContextFactory contextFactory) { _contextFactory = contextFactory; } /// public async Task PerformAsync(CancellationToken cancellationToken) { var dbContext = await _contextFactory.CreateDbContextAsync(cancellationToken).ConfigureAwait(false); await using (dbContext.ConfigureAwait(false)) { var users = await dbContext.Users.ToListAsync(cancellationToken).ConfigureAwait(false); foreach (var user in users) { user.NormalizedUsername = user.Username.ToUpperInvariant(); } await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } } }