2020-03-05 17:09:33 +00:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using MediaBrowser.Common.Configuration;
|
2020-03-05 15:21:27 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
namespace Jellyfin.Server.Migrations
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The class that knows how migrate between different Jellyfin versions.
|
|
|
|
/// </summary>
|
2020-03-05 17:09:33 +00:00
|
|
|
public sealed class MigrationRunner
|
2020-03-05 15:21:27 +00:00
|
|
|
{
|
2020-03-05 17:09:33 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The list of known migrations, in order of applicability.
|
|
|
|
/// </summary>
|
|
|
|
internal static readonly IUpdater[] Migrations =
|
2020-03-05 15:21:27 +00:00
|
|
|
{
|
2020-03-05 17:40:17 +00:00
|
|
|
new Routines.DisableTranscodingThrottling(),
|
|
|
|
new Routines.DisableZealousLogging()
|
2020-03-05 15:21:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Run all needed migrations.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="host">CoreAppHost that hosts current version.</param>
|
2020-03-05 17:09:33 +00:00
|
|
|
/// <param name="loggerFactory">Factory for making the logger.</param>
|
|
|
|
public static void Run(CoreAppHost host, ILoggerFactory loggerFactory)
|
2020-03-05 15:21:27 +00:00
|
|
|
{
|
2020-03-05 17:09:33 +00:00
|
|
|
var logger = loggerFactory.CreateLogger<MigrationRunner>();
|
2020-03-05 17:37:49 +00:00
|
|
|
var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration<MigrationOptions>(MigrationsListStore.StoreKey);
|
2020-03-05 17:09:33 +00:00
|
|
|
var applied = migrationOptions.Applied.ToList();
|
2020-03-05 15:21:27 +00:00
|
|
|
|
2020-03-05 17:09:33 +00:00
|
|
|
for (var i = 0; i < Migrations.Length; i++)
|
2020-03-05 15:21:27 +00:00
|
|
|
{
|
2020-03-05 17:09:33 +00:00
|
|
|
var updater = Migrations[i];
|
|
|
|
if (applied.Contains(updater.Name))
|
2020-03-05 15:21:27 +00:00
|
|
|
{
|
2020-03-05 17:09:33 +00:00
|
|
|
logger.LogDebug("Skipping migration {0} as it is already applied", updater.Name);
|
2020-03-05 15:21:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-03-05 17:09:33 +00:00
|
|
|
try
|
2020-03-05 15:21:27 +00:00
|
|
|
{
|
2020-03-05 17:09:33 +00:00
|
|
|
updater.Perform(host, logger);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
logger.LogError(ex, "Cannot apply migration {0}", updater.Name);
|
|
|
|
continue;
|
2020-03-05 15:21:27 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 17:09:33 +00:00
|
|
|
applied.Add(updater.Name);
|
2020-03-05 15:21:27 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 17:09:33 +00:00
|
|
|
if (applied.Count > migrationOptions.Applied.Length)
|
|
|
|
{
|
|
|
|
logger.LogInformation("Some migrations were run, saving the state");
|
|
|
|
migrationOptions.Applied = applied.ToArray();
|
2020-03-05 17:37:49 +00:00
|
|
|
host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions);
|
2020-03-05 17:09:33 +00:00
|
|
|
}
|
2020-03-05 15:21:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|