More logging, mark all migrations as applied if setup wizard is not complete

This commit is contained in:
Vasily 2020-03-06 13:22:44 +03:00
parent 216e425cc5
commit d4564d8e29

View File

@ -28,6 +28,17 @@ namespace Jellyfin.Server.Migrations
{ {
var logger = loggerFactory.CreateLogger<MigrationRunner>(); var logger = loggerFactory.CreateLogger<MigrationRunner>();
var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration<MigrationOptions>(MigrationsListStore.StoreKey); var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration<MigrationOptions>(MigrationsListStore.StoreKey);
if (!host.ServerConfigurationManager.Configuration.IsStartupWizardCompleted)
{
// 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();
host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions);
return;
}
var applied = migrationOptions.Applied.ToList(); var applied = migrationOptions.Applied.ToList();
for (var i = 0; i < Migrations.Length; i++) for (var i = 0; i < Migrations.Length; i++)
@ -35,20 +46,22 @@ namespace Jellyfin.Server.Migrations
var updater = Migrations[i]; var updater = Migrations[i];
if (applied.Contains(updater.Name)) if (applied.Contains(updater.Name))
{ {
logger.LogDebug("Skipping migration {0} as it is already applied", updater.Name); logger.LogDebug("Skipping migration {Name} as it is already applied", updater.Name);
continue; continue;
} }
logger.LogInformation("Applying migration {Name}", updater.Name);
try try
{ {
updater.Perform(host, logger); updater.Perform(host, logger);
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "Cannot apply migration {0}", updater.Name); logger.LogError(ex, "Cannot apply migration {Name}", updater.Name);
continue; continue;
} }
logger.LogInformation("Migration {Name} applied successfully", updater.Name);
applied.Add(updater.Name); applied.Add(updater.Name);
} }