diff options
| author | Vasily <just.one.man@yandex.ru> | 2020-03-05 18:21:27 +0300 |
|---|---|---|
| committer | Vasily <just.one.man@yandex.ru> | 2020-03-05 18:21:27 +0300 |
| commit | 66e11879efcd2a77476ca9704fa938e89776956c (patch) | |
| tree | 8c1f03242d03f7c5bcf916439c0a496445d9d3f8 | |
| parent | dcf3dbb2507f9e6a213b62b47cf8c327873f78b1 (diff) | |
Shuffle migrations in a more manageable structure
| -rw-r--r-- | Jellyfin.Server/CoreAppHost.cs | 2 | ||||
| -rw-r--r-- | Jellyfin.Server/Migrations.cs | 92 | ||||
| -rw-r--r-- | Jellyfin.Server/Migrations/IUpdater.cs | 26 | ||||
| -rw-r--r-- | Jellyfin.Server/Migrations/MigrationRunner.cs | 46 | ||||
| -rw-r--r-- | Jellyfin.Server/Migrations/Pre_10_5.cs | 33 |
5 files changed, 106 insertions, 93 deletions
diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs index cd5a2ce85..7f4bd3dea 100644 --- a/Jellyfin.Server/CoreAppHost.cs +++ b/Jellyfin.Server/CoreAppHost.cs @@ -69,7 +69,7 @@ namespace Jellyfin.Server case 1: Logger.LogWarning("Version check shows Jellyfin was updated: previous version={0}, current version={1}", previousVersion, ApplicationVersion); - Migrations.Run(this, Logger); + Migrations.MigrationRunner.Run(this, Logger); ConfigurationManager.CommonConfiguration.PreviousVersion = ApplicationVersion; ConfigurationManager.SaveConfiguration(); diff --git a/Jellyfin.Server/Migrations.cs b/Jellyfin.Server/Migrations.cs deleted file mode 100644 index 95fea4ea5..000000000 --- a/Jellyfin.Server/Migrations.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.Configuration; -using Microsoft.Extensions.Logging; - -namespace Jellyfin.Server -{ - /// <summary> - /// The class that knows how migrate between different Jellyfin versions. - /// </summary> - internal static class Migrations - { - private static readonly IUpdater[] _migrations = - { - new Pre10_5() - }; - - /// <summary> - /// Interface that descibes a migration routine. - /// </summary> - private interface IUpdater - { - /// <summary> - /// Gets maximum version this Updater applies to. - /// If current version is greater or equal to it, skip the updater. - /// </summary> - public abstract Version Maximum { get; } - - /// <summary> - /// Execute the migration from version "from". - /// </summary> - /// <param name="host">Host that hosts current version.</param> - /// <param name="logger">Host logger.</param> - /// <param name="from">Version to migrate from.</param> - /// <returns>Whether configuration was changed.</returns> - public abstract bool Perform(CoreAppHost host, ILogger logger, Version from); - } - - /// <summary> - /// Run all needed migrations. - /// </summary> - /// <param name="host">CoreAppHost that hosts current version.</param> - /// <param name="logger">AppHost logger.</param> - /// <returns>Whether anything was changed.</returns> - public static bool Run(CoreAppHost host, ILogger logger) - { - bool updated = false; - var version = host.ServerConfigurationManager.CommonConfiguration.PreviousVersion; - - for (var i = 0; i < _migrations.Length; i++) - { - var updater = _migrations[i]; - if (version.CompareTo(updater.Maximum) >= 0) - { - logger.LogDebug("Skipping updater {0} as current version {1} >= its maximum applicable version {2}", updater, version, updater.Maximum); - continue; - } - - if (updater.Perform(host, logger, version)) - { - updated = true; - } - - version = updater.Maximum; - } - - return updated; - } - - private class Pre10_5 : IUpdater - { - public Version Maximum { get => Version.Parse("10.5.0"); } - - public bool Perform(CoreAppHost host, ILogger logger, Version from) - { - // Set EnableThrottling to false as it wasn't used before, and in 10.5.0 it may introduce issues - var encoding = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration<EncodingOptions>("encoding"); - if (encoding.EnableThrottling) - { - logger.LogInformation("Disabling transcoding throttling during migration"); - encoding.EnableThrottling = false; - - host.ServerConfigurationManager.SaveConfiguration("encoding", encoding); - return true; - } - - return false; - } - } - } -} diff --git a/Jellyfin.Server/Migrations/IUpdater.cs b/Jellyfin.Server/Migrations/IUpdater.cs new file mode 100644 index 000000000..60d970256 --- /dev/null +++ b/Jellyfin.Server/Migrations/IUpdater.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.Extensions.Logging; + +namespace Jellyfin.Server.Migrations +{ + /// <summary> + /// Interface that descibes a migration routine. + /// </summary> + internal interface IUpdater + { + /// <summary> + /// Gets maximum version this Updater applies to. + /// If current version is greater or equal to it, skip the updater. + /// </summary> + public abstract Version Maximum { get; } + + /// <summary> + /// Execute the migration from version "from". + /// </summary> + /// <param name="host">Host that hosts current version.</param> + /// <param name="logger">Host logger.</param> + /// <param name="from">Version to migrate from.</param> + /// <returns>Whether configuration was changed.</returns> + public abstract bool Perform(CoreAppHost host, ILogger logger, Version from); + } +} diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs new file mode 100644 index 000000000..ad54fa38e --- /dev/null +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -0,0 +1,46 @@ +using Microsoft.Extensions.Logging; + +namespace Jellyfin.Server.Migrations +{ + /// <summary> + /// The class that knows how migrate between different Jellyfin versions. + /// </summary> + public static class MigrationRunner + { + private static readonly IUpdater[] _migrations = + { + new Pre_10_5() + }; + + /// <summary> + /// Run all needed migrations. + /// </summary> + /// <param name="host">CoreAppHost that hosts current version.</param> + /// <param name="logger">AppHost logger.</param> + /// <returns>Whether anything was changed.</returns> + public static bool Run(CoreAppHost host, ILogger logger) + { + bool updated = false; + var version = host.ServerConfigurationManager.CommonConfiguration.PreviousVersion; + + for (var i = 0; i < _migrations.Length; i++) + { + var updater = _migrations[i]; + if (version.CompareTo(updater.Maximum) >= 0) + { + logger.LogDebug("Skipping updater {0} as current version {1} >= its maximum applicable version {2}", updater, version, updater.Maximum); + continue; + } + + if (updater.Perform(host, logger, version)) + { + updated = true; + } + + version = updater.Maximum; + } + + return updated; + } + } +} diff --git a/Jellyfin.Server/Migrations/Pre_10_5.cs b/Jellyfin.Server/Migrations/Pre_10_5.cs new file mode 100644 index 000000000..5389a2ad9 --- /dev/null +++ b/Jellyfin.Server/Migrations/Pre_10_5.cs @@ -0,0 +1,33 @@ +using System; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; +using Microsoft.Extensions.Logging; + +namespace Jellyfin.Server.Migrations +{ + /// <summary> + /// Updater that takes care of bringing configuration up to 10.5.0 standards. + /// </summary> + internal class Pre_10_5 : IUpdater + { + /// <inheritdoc/> + public Version Maximum { get => Version.Parse("10.5.0"); } + + /// <inheritdoc/> + public bool Perform(CoreAppHost host, ILogger logger, Version from) + { + // Set EnableThrottling to false as it wasn't used before, and in 10.5.0 it may introduce issues + var encoding = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration<EncodingOptions>("encoding"); + if (encoding.EnableThrottling) + { + logger.LogInformation("Disabling transcoding throttling during migration"); + encoding.EnableThrottling = false; + + host.ServerConfigurationManager.SaveConfiguration("encoding", encoding); + return true; + } + + return false; + } + } +} |
