|
@@ -149,11 +149,18 @@ namespace Jellyfin.Server.Migrations
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ List<IMigrationRoutine> databaseMigrations = [];
|
|
try
|
|
try
|
|
{
|
|
{
|
|
foreach (var migrationRoutine in migrationsToBeApplied)
|
|
foreach (var migrationRoutine in migrationsToBeApplied)
|
|
{
|
|
{
|
|
logger.LogInformation("Applying migration '{Name}'", migrationRoutine.Name);
|
|
logger.LogInformation("Applying migration '{Name}'", migrationRoutine.Name);
|
|
|
|
+ var isDbMigration = migrationRoutine is IDatabaseMigrationRoutine;
|
|
|
|
+
|
|
|
|
+ if (isDbMigration)
|
|
|
|
+ {
|
|
|
|
+ databaseMigrations.Add(migrationRoutine);
|
|
|
|
+ }
|
|
|
|
|
|
try
|
|
try
|
|
{
|
|
{
|
|
@@ -167,17 +174,31 @@ 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, migrationRoutine.Name));
|
|
|
|
- saveConfiguration(migrationOptions);
|
|
|
|
- logger.LogDebug("Migration '{Name}' marked as applied in configuration.", migrationRoutine.Name);
|
|
|
|
|
|
+ if (!isDbMigration)
|
|
|
|
+ {
|
|
|
|
+ migrationOptions.Applied.Add((migrationRoutine.Id, migrationRoutine.Name));
|
|
|
|
+ saveConfiguration(migrationOptions);
|
|
|
|
+ logger.LogDebug("Migration '{Name}' marked as applied in configuration.", migrationRoutine.Name);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- catch (System.Exception) when (migrationKey is not null && jellyfinDatabaseProvider is not null)
|
|
|
|
|
|
+ catch (Exception) when (migrationKey is not null && jellyfinDatabaseProvider is not null)
|
|
{
|
|
{
|
|
- logger.LogInformation("Rollback on database as migration reported failure.");
|
|
|
|
- await jellyfinDatabaseProvider.RestoreBackupFast(migrationKey, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
|
+ if (databaseMigrations.Count != 0)
|
|
|
|
+ {
|
|
|
|
+ logger.LogInformation("Rolling back database as migrations reported failure.");
|
|
|
|
+ await jellyfinDatabaseProvider.RestoreBackupFast(migrationKey, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
+ }
|
|
|
|
+
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ foreach (var migrationRoutine in databaseMigrations)
|
|
|
|
+ {
|
|
|
|
+ migrationOptions.Applied.Add((migrationRoutine.Id, migrationRoutine.Name));
|
|
|
|
+ saveConfiguration(migrationOptions);
|
|
|
|
+ logger.LogDebug("Migration '{Name}' marked as applied in configuration.", migrationRoutine.Name);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|