< Summary - Jellyfin

Information
Class: Jellyfin.Server.Migrations.Routines.MigrateRatingLevels
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Migrations/Routines/20260915120000_MigrateRatingLevels.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 30
Coverable lines: 30
Total lines: 75
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 5/31/2026 - 12:15:44 AM Line coverage: 0% (0/28) Branch coverage: 0% (0/8) Total lines: 6811/13/2026 - 12:19:51 AM Line coverage: 0% (0/30) Branch coverage: 0% (0/8) Total lines: 75 5/31/2026 - 12:15:44 AM Line coverage: 0% (0/28) Branch coverage: 0% (0/8) Total lines: 6811/13/2026 - 12:19:51 AM Line coverage: 0% (0/30) Branch coverage: 0% (0/8) Total lines: 75

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
PerformAsync(...)100%210%
PerformCore()0%7280%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Migrations/Routines/20260915120000_MigrateRatingLevels.cs

#LineLine coverage
 1using System.Linq;
 2using System.Threading;
 3using System.Threading.Tasks;
 4using Jellyfin.Database.Implementations;
 5using Jellyfin.Server.ServerSetupApp;
 6using MediaBrowser.Model.Globalization;
 7using Microsoft.EntityFrameworkCore;
 8using Microsoft.Extensions.Logging;
 9
 10namespace Jellyfin.Server.Migrations.Routines;
 11
 12/// <summary>
 13/// Migrate rating levels.
 14/// </summary>
 15[JellyfinMigration("2026-09-15T12:00:00", nameof(MigrateRatingLevels))]
 16[JellyfinMigrationBackup(JellyfinDb = true)]
 17internal class MigrateRatingLevels : IDatabaseMigrationRoutine
 18{
 19    private readonly IStartupLogger _logger;
 20    private readonly IDbContextFactory<JellyfinDbContext> _provider;
 21    private readonly ILocalizationManager _localizationManager;
 22
 23    public MigrateRatingLevels(
 24        IDbContextFactory<JellyfinDbContext> provider,
 25        IStartupLogger<MigrateRatingLevels> logger,
 26        ILocalizationManager localizationManager)
 27    {
 028        _provider = provider;
 029        _localizationManager = localizationManager;
 030        _logger = logger;
 031    }
 32
 33    /// <inheritdoc />
 34    public Task PerformAsync(CancellationToken cancellationToken)
 35    {
 36        // This routine predates the async interface and has not been ported to async database access yet.
 037        PerformCore();
 038        return Task.CompletedTask;
 39    }
 40
 41    private void PerformCore()
 42    {
 043        _logger.LogInformation("Recalculating parental rating levels based on rating string.");
 044        using var context = _provider.CreateDbContext();
 045        using var transaction = context.Database.BeginTransaction();
 046        var ratings = context.BaseItems.AsNoTracking().Select(e => e.OfficialRating).Distinct();
 047        foreach (var rating in ratings)
 48        {
 049            if (string.IsNullOrEmpty(rating))
 50            {
 051                int? value = null;
 052                context.BaseItems
 053                    .Where(e => e.OfficialRating == null || e.OfficialRating == string.Empty)
 054                    .ExecuteUpdate(f => f.SetProperty(e => e.InheritedParentalRatingValue, value));
 055                context.BaseItems
 056                    .Where(e => e.OfficialRating == null || e.OfficialRating == string.Empty)
 057                    .ExecuteUpdate(f => f.SetProperty(e => e.InheritedParentalRatingSubValue, value));
 58            }
 59            else
 60            {
 061                var ratingValue = _localizationManager.GetRatingScore(rating);
 062                var score = ratingValue?.Score;
 063                var subScore = ratingValue?.SubScore;
 064                context.BaseItems
 065                    .Where(e => e.OfficialRating == rating)
 066                    .ExecuteUpdate(f => f.SetProperty(e => e.InheritedParentalRatingValue, score));
 067                context.BaseItems
 068                    .Where(e => e.OfficialRating == rating)
 069                    .ExecuteUpdate(f => f.SetProperty(e => e.InheritedParentalRatingSubValue, subScore));
 70            }
 71        }
 72
 073        transaction.Commit();
 074    }
 75}