From 8921cbf3b1815d15f0d74e06b661781269d5e5fb Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Sun, 18 Jan 2015 10:29:27 -0800 Subject: [PATCH] forcing lib update on upgrade --- .../Migration/075_force_lib_updateFixture.cs | 100 ++++++++++++++++++ .../NzbDrone.Core.Test.csproj | 1 + .../Migration/075_force_lib_update.cs | 22 ++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 4 files changed, 124 insertions(+) create mode 100644 src/NzbDrone.Core.Test/Datastore/Migration/075_force_lib_updateFixture.cs create mode 100644 src/NzbDrone.Core/Datastore/Migration/075_force_lib_update.cs diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/075_force_lib_updateFixture.cs b/src/NzbDrone.Core.Test/Datastore/Migration/075_force_lib_updateFixture.cs new file mode 100644 index 000000000..fabf8ebcb --- /dev/null +++ b/src/NzbDrone.Core.Test/Datastore/Migration/075_force_lib_updateFixture.cs @@ -0,0 +1,100 @@ +using System.Linq; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Jobs; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; + +namespace NzbDrone.Core.Test.Datastore.Migration +{ + [TestFixture] + public class force_lib_updateFixture : MigrationTest + { + [Test] + public void should_not_fail_on_empty_db() + { + WithTestDb(c => { }); + + Mocker.Resolve().All().Should().BeEmpty(); + Mocker.Resolve().All().Should().BeEmpty(); + } + + + [Test] + public void should_reset_job_last_execution_time() + { + WithTestDb(c => + { + c.Insert.IntoTable("ScheduledTasks").Row(new + { + TypeName = "NzbDrone.Core.Tv.Commands.RefreshSeriesCommand", + Interval = 10, + LastExecution = "2000-01-01 00:00:00" + }); + + c.Insert.IntoTable("ScheduledTasks").Row(new + { + TypeName = "NzbDrone.Core.Backup.BackupCommand", + Interval = 10, + LastExecution = "2000-01-01 00:00:00" + }); + }); + + var jobs = Mocker.Resolve().All().ToList(); + + jobs.Single(c => c.TypeName == "NzbDrone.Core.Tv.Commands.RefreshSeriesCommand") + .LastExecution.Year.Should() + .Be(2014); + + jobs.Single(c => c.TypeName == "NzbDrone.Core.Backup.BackupCommand") + .LastExecution.Year.Should() + .Be(2000); + } + + + [Test] + public void should_reset_series_last_sync_time() + { + WithTestDb(c => + { + c.Insert.IntoTable("Series").Row(new + { + Tvdbid = 1, + TvRageId =1, + Title ="Title1", + CleanTitle ="CleanTitle1", + Status =1, + Images ="", + Path ="c:\\test", + Monitored =1, + SeasonFolder =1, + Runtime= 0, + SeriesType=0, + UseSceneNumbering =0, + LastInfoSync = "2000-01-01 00:00:00" + }); + + c.Insert.IntoTable("Series").Row(new + { + Tvdbid = 2, + TvRageId = 2, + Title = "Title2", + CleanTitle = "CleanTitle2", + Status = 1, + Images = "", + Path = "c:\\test2", + Monitored = 1, + SeasonFolder = 1, + Runtime = 0, + SeriesType = 0, + UseSceneNumbering = 0, + LastInfoSync = "2000-01-01 00:00:00" + }); + }); + + var jobs = Mocker.Resolve().All().ToList(); + + jobs.Should().OnlyContain(c => c.LastInfoSync.Value.Year == 2014); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 3653dfc5b..948ea9b6a 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -120,6 +120,7 @@ + diff --git a/src/NzbDrone.Core/Datastore/Migration/075_force_lib_update.cs b/src/NzbDrone.Core/Datastore/Migration/075_force_lib_update.cs new file mode 100644 index 000000000..f9f3d30af --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/075_force_lib_update.cs @@ -0,0 +1,22 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(75)] + public class force_lib_update : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Update.Table("ScheduledTasks") + .Set(new { LastExecution = "2014-01-01 00:00:00" }) + .Where(new { TypeName = "NzbDrone.Core.Tv.Commands.RefreshSeriesCommand" }); + + Update.Table("Series") + .Set(new { LastInfoSync = "2014-01-01 00:00:00" }) + .AllRows(); + } + } + + +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index dcf6713a4..d02981902 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -232,6 +232,7 @@ +