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