< Summary - Jellyfin

Information
Class: Jellyfin.Server.Migrations.JellyfinMigrationService
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Migrations/JellyfinMigrationService.cs
Line coverage
41%
Covered lines: 102
Uncovered lines: 141
Coverable lines: 243
Total lines: 464
Line coverage: 41.9%
Branch coverage
25%
Covered branches: 25
Total branches: 98
Branch coverage: 25.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 3/6/2026 - 12:14:09 AM Line coverage: 81.3% (35/43) Branch coverage: 16.6% (2/12) Total lines: 4594/19/2026 - 12:14:27 AM Line coverage: 41.4% (100/241) Branch coverage: 21.5% (19/88) Total lines: 4595/4/2026 - 12:15:16 AM Line coverage: 41.4% (100/241) Branch coverage: 20.4% (18/88) Total lines: 4595/7/2026 - 12:15:44 AM Line coverage: 41.4% (100/241) Branch coverage: 20.6% (19/92) Total lines: 4595/22/2026 - 12:15:17 AM Line coverage: 41.4% (100/241) Branch coverage: 21.7% (20/92) Total lines: 4595/27/2026 - 12:15:38 AM Line coverage: 41.9% (102/243) Branch coverage: 25.5% (25/98) Total lines: 464 3/6/2026 - 12:14:09 AM Line coverage: 81.3% (35/43) Branch coverage: 16.6% (2/12) Total lines: 4594/19/2026 - 12:14:27 AM Line coverage: 41.4% (100/241) Branch coverage: 21.5% (19/88) Total lines: 4595/4/2026 - 12:15:16 AM Line coverage: 41.4% (100/241) Branch coverage: 20.4% (18/88) Total lines: 4595/7/2026 - 12:15:44 AM Line coverage: 41.4% (100/241) Branch coverage: 20.6% (19/92) Total lines: 4595/22/2026 - 12:15:17 AM Line coverage: 41.4% (100/241) Branch coverage: 21.7% (20/92) Total lines: 4595/27/2026 - 12:15:38 AM Line coverage: 41.9% (102/243) Branch coverage: 25.5% (25/98) Total lines: 464

Coverage delta

Coverage delta 40 -40

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
CheckFirstTimeRunOrMigration()36.36%1012245.31%
MigrateStepAsync()46.87%1413252.63%
GetJellyfinVersion()100%11100%
CleanupSystemAfterMigration()0%210140%
PrepareSystemForMigration()0%342180%
MergeBackupAttributes(...)0%110100%
.ctor(...)100%11100%
PerformAsync()100%11100%
.ctor(...)100%11100%
PerformAsync()100%11100%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Migrations/JellyfinMigrationService.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Globalization;
 4using System.IO;
 5using System.Linq;
 6using System.Reflection;
 7using System.Threading;
 8using System.Threading.Tasks;
 9using Emby.Server.Implementations.Serialization;
 10using Jellyfin.Database.Implementations;
 11using Jellyfin.Server.Implementations.SystemBackupService;
 12using Jellyfin.Server.Migrations.Stages;
 13using Jellyfin.Server.ServerSetupApp;
 14using MediaBrowser.Common.Configuration;
 15using MediaBrowser.Controller.SystemBackupService;
 16using MediaBrowser.Model.Configuration;
 17using Microsoft.EntityFrameworkCore;
 18using Microsoft.EntityFrameworkCore.Infrastructure;
 19using Microsoft.EntityFrameworkCore.Migrations;
 20using Microsoft.EntityFrameworkCore.Storage;
 21using Microsoft.Extensions.Logging;
 22
 23namespace Jellyfin.Server.Migrations;
 24
 25/// <summary>
 26/// Handles Migration of the Jellyfin data structure.
 27/// </summary>
 28internal class JellyfinMigrationService
 29{
 30    private const string DbFilename = "library.db";
 31    private readonly IDbContextFactory<JellyfinDbContext> _dbContextFactory;
 32    private readonly ILoggerFactory _loggerFactory;
 33    private readonly IStartupLogger _startupLogger;
 34    private readonly IBackupService? _backupService;
 35    private readonly IJellyfinDatabaseProvider? _jellyfinDatabaseProvider;
 36    private readonly IApplicationPaths _applicationPaths;
 37    private (string? LibraryDb, string? JellyfinDb, BackupManifestDto? FullBackup) _backupKey;
 38
 39    /// <summary>
 40    /// Initializes a new instance of the <see cref="JellyfinMigrationService"/> class.
 41    /// </summary>
 42    /// <param name="dbContextFactory">Provides access to the jellyfin database.</param>
 43    /// <param name="loggerFactory">The logger factory.</param>
 44    /// <param name="startupLogger">The startup logger for Startup UI intigration.</param>
 45    /// <param name="applicationPaths">Application paths for library.db backup.</param>
 46    /// <param name="backupService">The jellyfin backup service.</param>
 47    /// <param name="jellyfinDatabaseProvider">The jellyfin database provider.</param>
 48    public JellyfinMigrationService(
 49        IDbContextFactory<JellyfinDbContext> dbContextFactory,
 50        ILoggerFactory loggerFactory,
 51        IStartupLogger<JellyfinMigrationService> startupLogger,
 52        IApplicationPaths applicationPaths,
 53        IBackupService? backupService = null,
 54        IJellyfinDatabaseProvider? jellyfinDatabaseProvider = null)
 55    {
 6356        _dbContextFactory = dbContextFactory;
 6357        _loggerFactory = loggerFactory;
 6358        _startupLogger = startupLogger;
 6359        _backupService = backupService;
 6360        _jellyfinDatabaseProvider = jellyfinDatabaseProvider;
 6361        _applicationPaths = applicationPaths;
 62#pragma warning disable CS0618 // Type or member is obsolete
 6363        Migrations = [.. typeof(IMigrationRoutine).Assembly.GetTypes().Where(e => typeof(IMigrationRoutine).IsAssignable
 6364            .Select(e => (Type: e, Metadata: e.GetCustomAttribute<JellyfinMigrationAttribute>(), Backup: e.GetCustomAttr
 6365            .Where(e => e.Metadata is not null)
 6366            .GroupBy(e => e.Metadata!.Stage)
 6367            .Select(f =>
 6368            {
 6369                var stage = new MigrationStage(f.Key);
 6370                foreach (var item in f)
 6371                {
 6372                    JellyfinMigrationBackupAttribute? backupMetadata = null;
 6373                    if (item.Backup?.Any() == true)
 6374                    {
 6375                        backupMetadata = item.Backup.Aggregate(MergeBackupAttributes);
 6376                    }
 6377
 6378                    stage.Add(new(item.Type, item.Metadata!, backupMetadata));
 6379                }
 6380
 6381                return stage;
 6382            })];
 83#pragma warning restore CS0618 // Type or member is obsolete
 6384    }
 85
 86    private interface IInternalMigration
 87    {
 88        Task PerformAsync(IStartupLogger logger);
 89    }
 90
 91    private HashSet<MigrationStage> Migrations { get; set; }
 92
 93    public async Task CheckFirstTimeRunOrMigration(IApplicationPaths appPaths, StartupOptions startupOptions)
 94    {
 2195        var logger = _startupLogger.With(_loggerFactory.CreateLogger<JellyfinMigrationService>()).BeginGroup($"Migration
 2196        logger.LogInformation("Initialise Migration service.");
 2197        var xmlSerializer = new MyXmlSerializer();
 2198        var serverConfig = File.Exists(appPaths.SystemConfigurationFilePath)
 2199            ? (ServerConfiguration)xmlSerializer.DeserializeFromFile(typeof(ServerConfiguration), appPaths.SystemConfigu
 21100            : new ServerConfiguration();
 21101        if (!serverConfig.IsStartupWizardCompleted || startupOptions.StartupMode is Configuration.StartupMode.SeedSystem
 102        {
 21103            logger.LogInformation("System initialization detected. Seed data. Startup mode is: {StartupMode}", startupOp
 21104            var flatApplyMigrations = Migrations.SelectMany(e => e.Where(f => !f.Metadata.RunMigrationOnSetup)).ToArray(
 105
 21106            var dbContext = await _dbContextFactory.CreateDbContextAsync().ConfigureAwait(false);
 21107            await using (dbContext.ConfigureAwait(false))
 108            {
 21109                var databaseCreator = dbContext.Database.GetService<IDatabaseCreator>() as IRelationalDatabaseCreator
 21110                    ?? throw new InvalidOperationException("Jellyfin does only support relational databases.");
 21111                if (!await databaseCreator.ExistsAsync().ConfigureAwait(false))
 112                {
 21113                    await databaseCreator.CreateAsync().ConfigureAwait(false);
 114                }
 115
 21116                var historyRepository = dbContext.GetService<IHistoryRepository>();
 117
 21118                await historyRepository.CreateIfNotExistsAsync().ConfigureAwait(false);
 21119                var appliedMigrations = await dbContext.Database.GetAppliedMigrationsAsync().ConfigureAwait(false);
 21120                var startupScripts = flatApplyMigrations
 21121                    .Where(e => !appliedMigrations.Any(f => f != e.BuildCodeMigrationId()))
 21122                    .Select(e => (Migration: e.Metadata, Script: historyRepository.GetInsertScript(new HistoryRow(e.Buil
 21123                    .ToArray();
 1554124                foreach (var item in startupScripts)
 125                {
 756126                    logger.LogInformation("Seed migration {Key}-{Name}.", item.Migration.Key, item.Migration.Name);
 756127                    await dbContext.Database.ExecuteSqlRawAsync(item.Script).ConfigureAwait(false);
 128                }
 21129            }
 130
 21131            logger.LogInformation("Migration system initialisation completed.");
 21132        }
 133        else
 134        {
 135            // migrate any existing migration.xml files
 0136            var migrationConfigPath = Path.Join(appPaths.ConfigurationDirectoryPath, "migrations.xml");
 0137            var migrationOptions = File.Exists(migrationConfigPath)
 0138                 ? (MigrationOptions)xmlSerializer.DeserializeFromFile(typeof(MigrationOptions), migrationConfigPath)!
 0139                 : null;
 0140            if (migrationOptions is not null && migrationOptions.Applied.Count > 0)
 141            {
 0142                logger.LogInformation("Old migration style migration.xml detected. Migrate now.");
 143                try
 144                {
 0145                    var dbContext = await _dbContextFactory.CreateDbContextAsync().ConfigureAwait(false);
 0146                    await using (dbContext.ConfigureAwait(false))
 147                    {
 0148                        var historyRepository = dbContext.GetService<IHistoryRepository>();
 0149                        var appliedMigrations = await dbContext.Database.GetAppliedMigrationsAsync().ConfigureAwait(fals
 0150                        var lastOldAppliedMigration = Migrations
 0151                            .SelectMany(e => e.Where(e => e.Metadata.Key is not null)) // only consider migrations that 
 0152                            .Where(e => migrationOptions.Applied.Any(f => f.Id.Equals(e.Metadata.Key!.Value)))
 0153                            .Where(e => !appliedMigrations.Contains(e.BuildCodeMigrationId()))
 0154                            .OrderBy(e => e.BuildCodeMigrationId())
 0155                            .Last(); // this is the latest migration applied in the old migration.xml
 156
 0157                        IReadOnlyList<CodeMigration> oldMigrations = [
 0158                            .. Migrations
 0159                            .SelectMany(e => e)
 0160                            .OrderBy(e => e.BuildCodeMigrationId())
 0161                            .TakeWhile(e => e.BuildCodeMigrationId() != lastOldAppliedMigration.BuildCodeMigrationId()),
 0162                            lastOldAppliedMigration
 0163                        ];
 164                        // those are all migrations that had to run in the old migration system, even if not noted in th
 165
 0166                        var startupScripts = oldMigrations.Select(e => (Migration: e.Metadata, Script: historyRepository
 0167                        foreach (var item in startupScripts)
 168                        {
 0169                            logger.LogInformation("Migrate migration {Key}-{Name}.", item.Migration.Key, item.Migration.
 0170                            await dbContext.Database.ExecuteSqlRawAsync(item.Script).ConfigureAwait(false);
 171                        }
 172
 0173                        logger.LogInformation("Rename old migration.xml to migration.xml.backup");
 0174                        File.Move(migrationConfigPath, Path.ChangeExtension(migrationConfigPath, ".xml.backup"), true);
 0175                    }
 0176                }
 0177                catch (Exception ex)
 178                {
 0179                    logger.LogCritical(ex, "Failed to apply migrations");
 0180                    throw;
 181                }
 182            }
 0183        }
 21184    }
 185
 186    public async Task MigrateStepAsync(JellyfinMigrationStageTypes stage, IServiceProvider? serviceProvider)
 187    {
 63188        var logger = _startupLogger.With(_loggerFactory.CreateLogger<JellyfinMigrationService>()).BeginGroup($"Migrate s
 63189        ICollection<CodeMigration> migrationStage = (Migrations.FirstOrDefault(e => e.Stage == stage) as ICollection<Cod
 190
 63191        var dbContext = await _dbContextFactory.CreateDbContextAsync().ConfigureAwait(false);
 63192        await using (dbContext.ConfigureAwait(false))
 193        {
 63194            var historyRepository = dbContext.GetService<IHistoryRepository>();
 63195            var migrationsAssembly = dbContext.GetService<IMigrationsAssembly>();
 63196            (string Key, IInternalMigration Migration)[] migrations = [];
 197
 198            do
 199            { // migrations may alter the migration state. Reevaluate the applicable migrations after every stage ran un
 105200                var appliedMigrations = await historyRepository.GetAppliedMigrationsAsync().ConfigureAwait(false);
 105201                var pendingCodeMigrations = migrationStage
 105202                    .Where(e => appliedMigrations.All(f => f.MigrationId != e.BuildCodeMigrationId()))
 105203                    .Select(e => (Key: e.BuildCodeMigrationId(), Migration: new InternalCodeMigration(e, serviceProvider
 105204                    .ToArray();
 205
 105206                (string Key, InternalDatabaseMigration Migration)[] pendingDatabaseMigrations = [];
 105207                if (stage is JellyfinMigrationStageTypes.CoreInitialisation)
 208                {
 42209                    pendingDatabaseMigrations = migrationsAssembly.Migrations.Where(f => appliedMigrations.All(e => e.Mi
 42210                       .Select(e => (Key: e.Key, Migration: new InternalDatabaseMigration(e, dbContext)))
 42211                       .ToArray();
 212                }
 213
 105214                (string Key, IInternalMigration Migration)[] pendingMigrations = [.. pendingCodeMigrations, .. pendingDa
 105215                logger.LogInformation("There are {Pending} migrations for stage {Stage}.", pendingCodeMigrations.Length,
 105216                migrations = pendingMigrations.OrderBy(e => e.Key).ToArray();
 217
 2478218                foreach (var item in migrations)
 219                {
 1134220                    var migrationLogger = logger.With(_loggerFactory.CreateLogger(item.Migration.GetType().Name)).BeginG
 221                    try
 222                    {
 1134223                        migrationLogger.LogInformation("Perform migration {Name}", item.Key);
 1134224                        await item.Migration.PerformAsync(migrationLogger).ConfigureAwait(false);
 1134225                        migrationLogger.LogInformation("Migration {Name} was successfully applied", item.Key);
 1134226                    }
 0227                    catch (Exception ex)
 228                    {
 0229                        migrationLogger.LogCritical("Error: {Error}", ex.Message);
 0230                        migrationLogger.LogError(ex, "Migration {Name} failed", item.Key);
 231
 0232                        if (_backupKey != default && _backupService is not null && _jellyfinDatabaseProvider is not null
 233                        {
 0234                            if (_backupKey.LibraryDb is not null)
 235                            {
 0236                                migrationLogger.LogInformation("Attempt to rollback librarydb.");
 237                                try
 238                                {
 0239                                    var libraryDbPath = Path.Combine(_applicationPaths.DataPath, DbFilename);
 0240                                    File.Move(_backupKey.LibraryDb, libraryDbPath, true);
 0241                                }
 0242                                catch (Exception inner)
 243                                {
 0244                                    migrationLogger.LogCritical(inner, "Could not rollback {LibraryPath}. Manual interve
 0245                                }
 246                            }
 247
 0248                            if (_backupKey.JellyfinDb is not null)
 249                            {
 0250                                migrationLogger.LogInformation("Attempt to rollback JellyfinDb.");
 251                                try
 252                                {
 0253                                    await _jellyfinDatabaseProvider.RestoreBackupFast(_backupKey.JellyfinDb, Cancellatio
 0254                                }
 0255                                catch (Exception inner)
 256                                {
 0257                                    migrationLogger.LogCritical(inner, "Could not rollback {LibraryPath}. Manual interve
 0258                                }
 259                            }
 260
 0261                            if (_backupKey.FullBackup is not null)
 262                            {
 0263                                migrationLogger.LogInformation("Attempt to rollback from backup.");
 264                                try
 265                                {
 0266                                    await _backupService.RestoreBackupAsync(_backupKey.FullBackup.Path).ConfigureAwait(f
 0267                                }
 0268                                catch (Exception inner)
 269                                {
 0270                                    migrationLogger.LogCritical(inner, "Could not rollback from backup {Backup}. Manual 
 0271                                }
 272                            }
 273                        }
 274
 0275                        throw;
 276                    }
 1134277                }
 210278            } while (migrations.Length != 0);
 63279        }
 63280    }
 281
 282    private static string GetJellyfinVersion()
 283    {
 861284        return Assembly.GetEntryAssembly()!.GetName().Version!.ToString();
 285    }
 286
 287    public async Task CleanupSystemAfterMigration(ILogger logger)
 288    {
 0289        if (_backupKey != default)
 290        {
 0291            if (_backupKey.LibraryDb is not null)
 292            {
 0293                logger.LogInformation("Attempt to cleanup librarydb backup.");
 294                try
 295                {
 0296                    File.Delete(_backupKey.LibraryDb);
 0297                }
 0298                catch (Exception inner)
 299                {
 0300                    logger.LogCritical(inner, "Could not cleanup {LibraryPath}.", _backupKey.LibraryDb);
 0301                }
 302            }
 303
 0304            if (_backupKey.JellyfinDb is not null && _jellyfinDatabaseProvider is not null)
 305            {
 0306                logger.LogInformation("Attempt to cleanup JellyfinDb backup.");
 307                try
 308                {
 0309                    await _jellyfinDatabaseProvider.DeleteBackup(_backupKey.JellyfinDb).ConfigureAwait(false);
 0310                }
 0311                catch (Exception inner)
 312                {
 0313                    logger.LogCritical(inner, "Could not cleanup {LibraryPath}.", _backupKey.JellyfinDb);
 0314                }
 315            }
 316
 0317            if (_backupKey.FullBackup is not null)
 318            {
 0319                logger.LogInformation("Attempt to cleanup from migration backup.");
 320                try
 321                {
 0322                    File.Delete(_backupKey.FullBackup.Path);
 0323                }
 0324                catch (Exception inner)
 325                {
 0326                    logger.LogCritical(inner, "Could not cleanup backup {Backup}.", _backupKey.FullBackup.Path);
 0327                }
 328            }
 329        }
 0330    }
 331
 332    public async Task PrepareSystemForMigration(ILogger logger)
 333    {
 0334        logger.LogInformation("Prepare system for possible migrations");
 335        JellyfinMigrationBackupAttribute backupInstruction;
 336        IReadOnlyList<HistoryRow> appliedMigrations;
 0337        var dbContext = await _dbContextFactory.CreateDbContextAsync().ConfigureAwait(false);
 0338        await using (dbContext.ConfigureAwait(false))
 339        {
 0340            var historyRepository = dbContext.GetService<IHistoryRepository>();
 0341            var migrationsAssembly = dbContext.GetService<IMigrationsAssembly>();
 0342            appliedMigrations = await historyRepository.GetAppliedMigrationsAsync().ConfigureAwait(false);
 0343            backupInstruction = new JellyfinMigrationBackupAttribute()
 0344            {
 0345                JellyfinDb = migrationsAssembly.Migrations.Any(f => appliedMigrations.All(e => e.MigrationId != f.Key))
 0346            };
 0347        }
 348
 0349        backupInstruction = Migrations.SelectMany(e => e)
 0350           .Where(e => appliedMigrations.All(f => f.MigrationId != e.BuildCodeMigrationId()))
 0351           .Select(e => e.BackupRequirements)
 0352           .Where(e => e is not null)
 0353           .Aggregate(backupInstruction, MergeBackupAttributes!);
 354
 0355        if (backupInstruction.LegacyLibraryDb)
 356        {
 0357            logger.LogInformation("A migration will attempt to modify the library.db, will attempt to backup the file no
 358            // for legacy migrations that still operates on the library.db
 0359            var libraryDbPath = Path.Combine(_applicationPaths.DataPath, DbFilename);
 0360            if (File.Exists(libraryDbPath))
 361            {
 0362                for (int i = 1; ; i++)
 363                {
 0364                    var bakPath = string.Format(CultureInfo.InvariantCulture, "{0}.bak{1}", libraryDbPath, i);
 0365                    if (!File.Exists(bakPath))
 366                    {
 367                        try
 368                        {
 0369                            logger.LogInformation("Backing up {Library} to {BackupPath}", DbFilename, bakPath);
 0370                            File.Copy(libraryDbPath, bakPath);
 0371                            _backupKey = (bakPath, _backupKey.JellyfinDb, _backupKey.FullBackup);
 0372                            logger.LogInformation("{Library} backed up to {BackupPath}", DbFilename, bakPath);
 0373                            break;
 374                        }
 0375                        catch (Exception ex)
 376                        {
 0377                            logger.LogError(ex, "Cannot make a backup of {Library} at path {BackupPath}", DbFilename, ba
 0378                            throw;
 379                        }
 380                    }
 381                }
 382
 0383                logger.LogInformation("{Library} has been backed up as {BackupPath}", DbFilename, _backupKey.LibraryDb);
 384            }
 385            else
 386            {
 0387                logger.LogError("Cannot make a backup of {Library} at path {BackupPath} because file could not be found 
 388            }
 389        }
 390
 0391        if (backupInstruction.JellyfinDb && _jellyfinDatabaseProvider is not null)
 392        {
 0393            logger.LogInformation("A migration will attempt to modify the jellyfin.db, will attempt to backup the file n
 0394            _backupKey = (_backupKey.LibraryDb, await _jellyfinDatabaseProvider.MigrationBackupFast(CancellationToken.No
 0395            logger.LogInformation("Jellyfin database has been backed up as {BackupPath}", _backupKey.JellyfinDb);
 396        }
 397
 0398        if (_backupService is not null && (backupInstruction.Metadata || backupInstruction.Subtitles || backupInstructio
 399        {
 0400            logger.LogInformation("A migration will attempt to modify system resources. Will attempt to create backup no
 0401            _backupKey = (_backupKey.LibraryDb, _backupKey.JellyfinDb, await _backupService.CreateBackupAsync(new Backup
 0402            {
 0403                Metadata = backupInstruction.Metadata,
 0404                Subtitles = backupInstruction.Subtitles,
 0405                Trickplay = backupInstruction.Trickplay,
 0406                Database = false // database backups are explicitly handled by the provider itself as the backup service
 0407            }).ConfigureAwait(false));
 0408            logger.LogInformation("Pre-Migration backup successfully created as {BackupKey}", _backupKey.FullBackup.Path
 409        }
 0410    }
 411
 412    private static JellyfinMigrationBackupAttribute MergeBackupAttributes(JellyfinMigrationBackupAttribute left, Jellyfi
 413    {
 0414        return new JellyfinMigrationBackupAttribute()
 0415        {
 0416            JellyfinDb = left!.JellyfinDb || right!.JellyfinDb,
 0417            LegacyLibraryDb = left.LegacyLibraryDb || right!.LegacyLibraryDb,
 0418            Metadata = left.Metadata || right!.Metadata,
 0419            Subtitles = left.Subtitles || right!.Subtitles,
 0420            Trickplay = left.Trickplay || right!.Trickplay
 0421        };
 422    }
 423
 424    private class InternalCodeMigration : IInternalMigration
 425    {
 426        private readonly CodeMigration _codeMigration;
 427        private readonly IServiceProvider? _serviceProvider;
 428        private JellyfinDbContext _dbContext;
 429
 430        public InternalCodeMigration(CodeMigration codeMigration, IServiceProvider? serviceProvider, JellyfinDbContext d
 431        {
 105432            _codeMigration = codeMigration;
 105433            _serviceProvider = serviceProvider;
 105434            _dbContext = dbContext;
 105435        }
 436
 437        public async Task PerformAsync(IStartupLogger logger)
 438        {
 105439            await _codeMigration.Perform(_serviceProvider, logger, CancellationToken.None).ConfigureAwait(false);
 440
 105441            var historyRepository = _dbContext.GetService<IHistoryRepository>();
 105442            var createScript = historyRepository.GetInsertScript(new HistoryRow(_codeMigration.BuildCodeMigrationId(), G
 105443            await _dbContext.Database.ExecuteSqlRawAsync(createScript).ConfigureAwait(false);
 105444        }
 445    }
 446
 447    private class InternalDatabaseMigration : IInternalMigration
 448    {
 449        private readonly JellyfinDbContext _jellyfinDbContext;
 450        private KeyValuePair<string, TypeInfo> _databaseMigrationInfo;
 451
 452        public InternalDatabaseMigration(KeyValuePair<string, TypeInfo> databaseMigrationInfo, JellyfinDbContext jellyfi
 453        {
 1029454            _databaseMigrationInfo = databaseMigrationInfo;
 1029455            _jellyfinDbContext = jellyfinDbContext;
 1029456        }
 457
 458        public async Task PerformAsync(IStartupLogger logger)
 459        {
 1029460            var migrator = _jellyfinDbContext.GetService<IMigrator>();
 1029461            await migrator.MigrateAsync(_databaseMigrationInfo.Key).ConfigureAwait(false);
 1029462        }
 463    }
 464}