Procházet zdrojové kódy

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
Mark Monteiro před 5 roky
rodič
revize
72bf920291

+ 6 - 1
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; }
 

+ 6 - 5
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; }
     }
 }

+ 4 - 7
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);
             }

+ 3 - 0
Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs

@@ -36,6 +36,9 @@ namespace Jellyfin.Server.Migrations.Routines
             @"{""Serilog"":{""MinimumLevel"":""Information"",""WriteTo"":[{""Name"":""Console"",""Args"":{""outputTemplate"":""[{Timestamp:HH:mm:ss}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message:lj}{NewLine}{Exception}""}},{""Name"":""Async"",""Args"":{""configure"":[{""Name"":""File"",""Args"":{""path"":""%JELLYFIN_LOG_DIR%//log_.log"",""rollingInterval"":""Day"",""retainedFileCountLimit"":3,""rollOnFileSizeLimit"":true,""fileSizeLimitBytes"":100000000,""outputTemplate"":""[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] [{ThreadId}] {SourceContext}:{Message}{NewLine}{Exception}""}}]}}],""Enrich"":[""FromLogContext"",""WithThreadId""]}}",
         };
 
+        /// <inheritdoc/>
+        public Guid Id => Guid.Parse("{EF103419-8451-40D8-9F34-D1A8E93A1679}");
+
         /// <inheritdoc/>
         public string Name => "CreateLoggingConfigHeirarchy";
 

+ 3 - 0
Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs

@@ -12,6 +12,9 @@ namespace Jellyfin.Server.Migrations.Routines
     /// </summary>
     internal class DisableTranscodingThrottling : IMigrationRoutine
     {
+        /// <inheritdoc/>
+        public Guid Id => Guid.Parse("{4124C2CD-E939-4FFB-9BE9-9B311C413638}");
+
         /// <inheritdoc/>
         public string Name => "DisableTranscodingThrottling";