aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Monteiro <marknr.monteiro@protonmail.com>2020-03-08 16:05:31 +0100
committerMark Monteiro <marknr.monteiro@protonmail.com>2020-03-08 16:05:31 +0100
commit72bf920291d1c486aaf66544ccd6eb64c13e254b (patch)
treee2d9b9dffd553964e775d067124866be3205d94b
parent8dbb1c92573ba5cf3e4f8d953ffd6083a8ccbde4 (diff)
Use a Guid to uniquely identify migrations instead of a string name
Also use a list instead of an array to store executed migrations in the configuration class
-rw-r--r--Jellyfin.Server/Migrations/IMigrationRoutine.cs7
-rw-r--r--Jellyfin.Server/Migrations/MigrationOptions.cs11
-rw-r--r--Jellyfin.Server/Migrations/MigrationRunner.cs11
-rw-r--r--Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs3
-rw-r--r--Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs3
5 files changed, 22 insertions, 13 deletions
diff --git a/Jellyfin.Server/Migrations/IMigrationRoutine.cs b/Jellyfin.Server/Migrations/IMigrationRoutine.cs
index 20a3aa3d6..eab995d67 100644
--- a/Jellyfin.Server/Migrations/IMigrationRoutine.cs
+++ b/Jellyfin.Server/Migrations/IMigrationRoutine.cs
@@ -9,7 +9,12 @@ namespace Jellyfin.Server.Migrations
internal interface IMigrationRoutine
{
/// <summary>
- /// Gets the name of the migration, must be unique.
+ /// Gets the unique id for this migration. This should never be modified after the migration has been created.
+ /// </summary>
+ public Guid Id { get; }
+
+ /// <summary>
+ /// Gets the display name of the migration.
/// </summary>
public string Name { get; }
diff --git a/Jellyfin.Server/Migrations/MigrationOptions.cs b/Jellyfin.Server/Migrations/MigrationOptions.cs
index 6b7831158..d95354145 100644
--- a/Jellyfin.Server/Migrations/MigrationOptions.cs
+++ b/Jellyfin.Server/Migrations/MigrationOptions.cs
@@ -1,3 +1,6 @@
+using System;
+using System.Collections.Generic;
+
namespace Jellyfin.Server.Migrations
{
/// <summary>
@@ -10,14 +13,12 @@ namespace Jellyfin.Server.Migrations
/// </summary>
public MigrationOptions()
{
- Applied = System.Array.Empty<string>();
+ Applied = new List<Guid>();
}
-#pragma warning disable CA1819 // Properties should not return arrays
/// <summary>
- /// Gets or sets the list of applied migration routine names.
+ /// Gets the list of applied migration routine names.
/// </summary>
- public string[] Applied { get; set; }
-#pragma warning restore CA1819 // Properties should not return arrays
+ public List<Guid> Applied { get; }
}
}
diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs
index 821f51c02..2081143d2 100644
--- a/Jellyfin.Server/Migrations/MigrationRunner.cs
+++ b/Jellyfin.Server/Migrations/MigrationRunner.cs
@@ -29,22 +29,20 @@ namespace Jellyfin.Server.Migrations
var logger = loggerFactory.CreateLogger<MigrationRunner>();
var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration<MigrationOptions>(MigrationsListStore.StoreKey);
- if (!host.ServerConfigurationManager.Configuration.IsStartupWizardCompleted && migrationOptions.Applied.Length == 0)
+ if (!host.ServerConfigurationManager.Configuration.IsStartupWizardCompleted && migrationOptions.Applied.Count == 0)
{
// If startup wizard is not finished, this is a fresh install.
// Don't run any migrations, just mark all of them as applied.
logger.LogInformation("Marking all known migrations as applied because this is fresh install");
- migrationOptions.Applied = Migrations.Select(m => m.Name).ToArray();
+ migrationOptions.Applied.AddRange(Migrations.Select(m => m.Id));
host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions);
return;
}
- var applied = migrationOptions.Applied.ToList();
-
for (var i = 0; i < Migrations.Length; i++)
{
var migrationRoutine = Migrations[i];
- if (applied.Contains(migrationRoutine.Name))
+ if (migrationOptions.Applied.Contains(migrationRoutine.Id))
{
logger.LogDebug("Skipping migration '{Name}' since it is already applied", migrationRoutine.Name);
continue;
@@ -64,8 +62,7 @@ namespace Jellyfin.Server.Migrations
// Mark the migration as completed
logger.LogInformation("Migration '{Name}' applied successfully", migrationRoutine.Name);
- applied.Add(migrationRoutine.Name);
- migrationOptions.Applied = applied.ToArray();
+ migrationOptions.Applied.Add(migrationRoutine.Id);
host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions);
logger.LogDebug("Migration '{Name}' marked as applied in configuration.", migrationRoutine.Name);
}
diff --git a/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs b/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs
index 834099ea0..3bc32c047 100644
--- a/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs
+++ b/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs
@@ -37,6 +37,9 @@ namespace Jellyfin.Server.Migrations.Routines
};
/// <inheritdoc/>
+ public Guid Id => Guid.Parse("{EF103419-8451-40D8-9F34-D1A8E93A1679}");
+
+ /// <inheritdoc/>
public string Name => "CreateLoggingConfigHeirarchy";
/// <inheritdoc/>
diff --git a/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs
index 279e7bbea..673f0e415 100644
--- a/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs
+++ b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs
@@ -13,6 +13,9 @@ namespace Jellyfin.Server.Migrations.Routines
internal class DisableTranscodingThrottling : IMigrationRoutine
{
/// <inheritdoc/>
+ public Guid Id => Guid.Parse("{4124C2CD-E939-4FFB-9BE9-9B311C413638}");
+
+ /// <inheritdoc/>
public string Name => "DisableTranscodingThrottling";
/// <inheritdoc/>