diff --git a/src/NzbDrone.Core/Datastore/Migration/141_add_update_history.cs b/src/NzbDrone.Core/Datastore/Migration/141_add_update_history.cs index dd6ae0237..a0b4a9a7a 100644 --- a/src/NzbDrone.Core/Datastore/Migration/141_add_update_history.cs +++ b/src/NzbDrone.Core/Datastore/Migration/141_add_update_history.cs @@ -18,14 +18,6 @@ protected override void LogDbUpgrade() .WithColumn("Date").AsDateTime().NotNullable().Indexed() .WithColumn("Version").AsString().NotNullable() .WithColumn("EventType").AsInt32().NotNullable(); - - Insert.IntoTable("UpdateHistory") - .Row(new - { - Date = new UtcConverter().ToDB(DateTime.UtcNow).ToString(), - Version = BuildInfo.Version.ToString(), - EventType = 2 - }); } } } diff --git a/src/NzbDrone.Core/Update/History/UpdateHistoryService.cs b/src/NzbDrone.Core/Update/History/UpdateHistoryService.cs index 8d11ea054..09cf70602 100644 --- a/src/NzbDrone.Core/Update/History/UpdateHistoryService.cs +++ b/src/NzbDrone.Core/Update/History/UpdateHistoryService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using NLog; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging.Events; @@ -17,24 +18,42 @@ public class UpdateHistoryService : IUpdateHistoryService, IHandle InstalledSince(DateTime dateTime) { - return _repository.InstalledSince(dateTime); + try + { + return _repository.InstalledSince(dateTime); + } + catch (Exception ex) + { + _logger.Warn(ex, "Failed to get list of previously installed versions"); + return new List(); + } } public void Handle(ApplicationStartedEvent message) @@ -45,19 +64,29 @@ public void Handle(ApplicationStartedEvent message) return; } - var history = _repository.LastInstalled(); + UpdateHistory history; + try + { + history = _repository.LastInstalled(); + } + catch (Exception ex) + { + _logger.Warn(ex, "Cleaning corrupted update history"); + _repository.Purge(); + history = null; + } if (history == null || history.Version != BuildInfo.Version) - { - _prevVersion = history.Version; - - _repository.Insert(new UpdateHistory { - Date = DateTime.UtcNow, - Version = BuildInfo.Version, - EventType = UpdateHistoryEventType.Installed - }); - } + _prevVersion = history?.Version; + + _repository.Insert(new UpdateHistory + { + Date = DateTime.UtcNow, + Version = BuildInfo.Version, + EventType = UpdateHistoryEventType.Installed + }); + } } public void HandleAsync(ApplicationStartedEvent message)