Просмотр исходного кода

Store migration names alongside Ids in configuration in order to assist with development/debugging

Mark Monteiro 5 лет назад
Родитель
Сommit
9e89cbbc3a

+ 2 - 2
Jellyfin.Server/Migrations/MigrationOptions.cs

@@ -13,12 +13,12 @@ namespace Jellyfin.Server.Migrations
         /// </summary>
         /// </summary>
         public MigrationOptions()
         public MigrationOptions()
         {
         {
-            Applied = new List<Guid>();
+            Applied = new List<(Guid Id, string Name)>();
         }
         }
 
 
         /// <summary>
         /// <summary>
         /// Gets the list of applied migration routine names.
         /// Gets the list of applied migration routine names.
         /// </summary>
         /// </summary>
-        public List<Guid> Applied { get; }
+        public List<(Guid Id, string Name)> Applied { get; }
     }
     }
 }
 }

+ 6 - 4
Jellyfin.Server/Migrations/MigrationRunner.cs

@@ -33,16 +33,18 @@ namespace Jellyfin.Server.Migrations
             {
             {
                 // If startup wizard is not finished, this is a fresh install.
                 // If startup wizard is not finished, this is a fresh install.
                 // Don't run any migrations, just mark all of them as applied.
                 // 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.AddRange(Migrations.Select(m => m.Id));
+                logger.LogInformation("Marking all known migrations as applied because this is a fresh install");
+                migrationOptions.Applied.AddRange(Migrations.Select(m => (m.Id, m.Name)));
                 host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions);
                 host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions);
                 return;
                 return;
             }
             }
 
 
+            var appliedMigrationIds = migrationOptions.Applied.Select(m => m.Id).ToHashSet();
+
             for (var i = 0; i < Migrations.Length; i++)
             for (var i = 0; i < Migrations.Length; i++)
             {
             {
                 var migrationRoutine = Migrations[i];
                 var migrationRoutine = Migrations[i];
-                if (migrationOptions.Applied.Contains(migrationRoutine.Id))
+                if (appliedMigrationIds.Contains(migrationRoutine.Id))
                 {
                 {
                     logger.LogDebug("Skipping migration '{Name}' since it is already applied", migrationRoutine.Name);
                     logger.LogDebug("Skipping migration '{Name}' since it is already applied", migrationRoutine.Name);
                     continue;
                     continue;
@@ -62,7 +64,7 @@ namespace Jellyfin.Server.Migrations
 
 
                 // Mark the migration as completed
                 // Mark the migration as completed
                 logger.LogInformation("Migration '{Name}' applied successfully", migrationRoutine.Name);
                 logger.LogInformation("Migration '{Name}' applied successfully", migrationRoutine.Name);
-                migrationOptions.Applied.Add(migrationRoutine.Id);
+                migrationOptions.Applied.Add((migrationRoutine.Id, migrationRoutine.Name));
                 host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions);
                 host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions);
                 logger.LogDebug("Migration '{Name}' marked as applied in configuration.", migrationRoutine.Name);
                 logger.LogDebug("Migration '{Name}' marked as applied in configuration.", migrationRoutine.Name);
             }
             }