| | | 1 | | using System; |
| | | 2 | | using System.Threading; |
| | | 3 | | using System.Threading.Tasks; |
| | | 4 | | using Jellyfin.Database.Implementations; |
| | | 5 | | using MediaBrowser.Controller.Configuration; |
| | | 6 | | using Microsoft.EntityFrameworkCore; |
| | | 7 | | |
| | | 8 | | namespace Jellyfin.Server.Migrations.Routines; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Part 2 Migration for NormalisedUsername. |
| | | 12 | | /// </summary> |
| | | 13 | | [JellyfinMigration("2026-05-22T09:23:04", nameof(UpdateNormalizedUsername), Stage = Stages.JellyfinMigrationStageTypes.C |
| | | 14 | | #pragma warning disable SA1649 // File name should match first type name |
| | | 15 | | public class UpdateNormalizedUsername : IAsyncMigrationRoutine |
| | | 16 | | #pragma warning restore SA1649 // File name should match first type name |
| | | 17 | | { |
| | | 18 | | private readonly IDbContextFactory<JellyfinDbContext> _contextFactory; |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Initializes a new instance of the <see cref="UpdateNormalizedUsername"/> class. |
| | | 22 | | /// </summary> |
| | | 23 | | /// <param name="contextFactory">Db Context factory.</param> |
| | | 24 | | public UpdateNormalizedUsername(IDbContextFactory<JellyfinDbContext> contextFactory) |
| | | 25 | | { |
| | 0 | 26 | | _contextFactory = contextFactory; |
| | 0 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <inheritdoc/> |
| | | 30 | | public async Task PerformAsync(CancellationToken cancellationToken) |
| | | 31 | | { |
| | 0 | 32 | | var dbContext = await _contextFactory.CreateDbContextAsync(cancellationToken).ConfigureAwait(false); |
| | 0 | 33 | | await using (dbContext.ConfigureAwait(false)) |
| | | 34 | | { |
| | 0 | 35 | | var users = await dbContext.Users.ToListAsync(cancellationToken).ConfigureAwait(false); |
| | 0 | 36 | | foreach (var user in users) |
| | | 37 | | { |
| | 0 | 38 | | user.NormalizedUsername = user.Username.ToUpperInvariant(); |
| | | 39 | | } |
| | | 40 | | |
| | 0 | 41 | | await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); |
| | | 42 | | } |
| | 0 | 43 | | } |
| | | 44 | | } |