CleanMusicArtist.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Linq;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using Jellyfin.Data.Enums;
  5. using Jellyfin.Database.Implementations;
  6. using Jellyfin.Server.ServerSetupApp;
  7. using Microsoft.EntityFrameworkCore;
  8. using Microsoft.Extensions.Logging;
  9. namespace Jellyfin.Server.Migrations.Routines;
  10. /// <summary>
  11. /// Cleans up all Music artists that have been migrated in the 10.11 RC migrations.
  12. /// </summary>
  13. [JellyfinMigration("2025-10-09T20:00:00", nameof(CleanMusicArtist))]
  14. [JellyfinMigrationBackup(JellyfinDb = true)]
  15. public class CleanMusicArtist : IAsyncMigrationRoutine
  16. {
  17. private readonly IStartupLogger<CleanMusicArtist> _startupLogger;
  18. private readonly IDbContextFactory<JellyfinDbContext> _dbContextFactory;
  19. /// <summary>
  20. /// Initializes a new instance of the <see cref="CleanMusicArtist"/> class.
  21. /// </summary>
  22. /// <param name="startupLogger">The startup logger.</param>
  23. /// <param name="dbContextFactory">The Db context factory.</param>
  24. public CleanMusicArtist(IStartupLogger<CleanMusicArtist> startupLogger, IDbContextFactory<JellyfinDbContext> dbContextFactory)
  25. {
  26. _startupLogger = startupLogger;
  27. _dbContextFactory = dbContextFactory;
  28. }
  29. /// <inheritdoc/>
  30. public async Task PerformAsync(CancellationToken cancellationToken)
  31. {
  32. var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken).ConfigureAwait(false);
  33. await using (context.ConfigureAwait(false))
  34. {
  35. var peoples = context.Peoples.Where(e => e.PersonType == nameof(PersonKind.Artist) || e.PersonType == nameof(PersonKind.AlbumArtist));
  36. _startupLogger.LogInformation("Delete {Number} Artist and Album Artist person types from db", await peoples.CountAsync(cancellationToken).ConfigureAwait(false));
  37. await peoples
  38. .ExecuteDeleteAsync(cancellationToken)
  39. .ConfigureAwait(false);
  40. }
  41. }
  42. }