diff --git a/src/NzbDrone.Core.Test/Datastore/SQLiteMigrationHelperTests/AlterFixture.cs b/src/NzbDrone.Core.Test/Datastore/SQLiteMigrationHelperTests/AlterFixture.cs index 7e1510259..aa07e1028 100644 --- a/src/NzbDrone.Core.Test/Datastore/SQLiteMigrationHelperTests/AlterFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/SQLiteMigrationHelperTests/AlterFixture.cs @@ -97,10 +97,8 @@ namespace NzbDrone.Core.Test.Datastore.SQLiteMigrationHelperTests var columns = _subject.GetColumns("QualitySizes"); var indexes = _subject.GetIndexes("QualitySizes"); - _subject.CreateTable("QualityB", columns.Values, indexes); - var newIndexes = _subject.GetIndexes("QualityB"); newIndexes.Should().HaveSameCount(indexes); @@ -122,6 +120,5 @@ namespace NzbDrone.Core.Test.Datastore.SQLiteMigrationHelperTests newColumns.Values.Should().HaveSameCount(columns.Values); newIndexes.Should().Contain(i=>i.Column == "AirTime"); } - } } \ No newline at end of file diff --git a/src/NzbDrone.Core.Test/EpisodeParseResultTest.cs b/src/NzbDrone.Core.Test/EpisodeParseResultTest.cs deleted file mode 100644 index 4d14a77af..000000000 --- a/src/NzbDrone.Core.Test/EpisodeParseResultTest.cs +++ /dev/null @@ -1,258 +0,0 @@ -/* -using System; -using System.Collections.Generic; -using System.Linq; -using FizzWare.NBuilder; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Qualities; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Model; -using NzbDrone.Core.Test.Framework; - -namespace NzbDrone.Core.Test -{ - [TestFixture] - - public class EpisodeParseResultTest : CoreTest - { - [Test] - public void tostring_single_season_episode() - { - var parseResult = new RemoteEpisode(); - parseResult.SeriesTitle = "My Series"; - parseResult.SeasonNumber = 12; - parseResult.EpisodeNumbers = new List { 3 }; - parseResult.FullSeason = false; - parseResult.AirDate = null; - parseResult.Quality = new QualityModel(Quality.HDTV720p, false); - - - parseResult.ToString().Should().Be("My Series - S12E03 HDTV-720p"); - } - - [Test] - public void tostring_single_season_episode_proper() - { - var parseResult = new RemoteEpisode(); - parseResult.SeriesTitle = "My Series"; - parseResult.SeasonNumber = 12; - parseResult.EpisodeNumbers = new List { 3 }; - parseResult.FullSeason = false; - parseResult.AirDate = null; - parseResult.Quality = new QualityModel(Quality.HDTV720p, true); - - - parseResult.ToString().Should().Be("My Series - S12E03 HDTV-720p [proper]"); - } - - [Test] - public void tostring_multi_season_episode() - { - var parseResult = new RemoteEpisode(); - parseResult.SeriesTitle = "My Series"; - parseResult.SeasonNumber = 12; - parseResult.EpisodeNumbers = new List { 3, 4, 5 }; - parseResult.FullSeason = false; - parseResult.AirDate = null; - parseResult.Quality = new QualityModel(Quality.HDTV720p, false); - - - parseResult.ToString().Should().Be("My Series - S12E03-04-05 HDTV-720p"); - } - - [Test] - public void tostring_multi_season_episode_proper() - { - var parseResult = new RemoteEpisode(); - parseResult.SeriesTitle = "My Series"; - parseResult.SeasonNumber = 12; - parseResult.EpisodeNumbers = new List { 3, 4, 5 }; - parseResult.FullSeason = false; - parseResult.AirDate = null; - parseResult.Quality = new QualityModel(Quality.HDTV720p, true); - - - parseResult.ToString().Should().Be("My Series - S12E03-04-05 HDTV-720p [proper]"); - } - - - [Test] - public void tostring_full_season() - { - var parseResult = new RemoteEpisode(); - parseResult.SeriesTitle = "My Series"; - parseResult.SeasonNumber = 12; - parseResult.FullSeason = true; - parseResult.AirDate = null; - parseResult.Quality = new QualityModel(Quality.HDTV720p, false); - - - parseResult.ToString().Should().Be("My Series - Season 12 HDTV-720p"); - } - - - [Test] - public void tostring_full_season_proper() - { - var parseResult = new RemoteEpisode(); - parseResult.SeriesTitle = "My Series"; - parseResult.SeasonNumber = 12; - parseResult.FullSeason = true; - parseResult.AirDate = null; - parseResult.Quality = new QualityModel(Quality.HDTV720p, true); - - - parseResult.ToString().Should().Be("My Series - Season 12 HDTV-720p [proper]"); - } - - [Test] - public void tostring_daily_show() - { - var parseResult = new RemoteEpisode(); - parseResult.SeriesTitle = "My Series"; - parseResult.SeasonNumber = 12; - parseResult.FullSeason = true; - parseResult.AirDate = new DateTime(2010, 12, 30); - parseResult.Quality = new QualityModel(Quality.HDTV720p, false); - - - parseResult.ToString().Should().Be("My Series - 2010-12-30 HDTV-720p"); - } - - [Test] - public void tostring_daily_show_proper() - { - var parseResult = new RemoteEpisode(); - parseResult.SeriesTitle = "My Series"; - parseResult.SeasonNumber = 12; - parseResult.FullSeason = true; - parseResult.AirDate = new DateTime(2010, 12, 30); - parseResult.Quality = new QualityModel(Quality.HDTV720p, true); - - - parseResult.ToString().Should().Be("My Series - 2010-12-30 HDTV-720p [proper]"); - } - - - - public static readonly object[] SabNamingCases = - { - new object[] { 1, new[] { 2 }, "My Episode Title", Quality.DVD, false, "My Series Name - 1x02 - My Episode Title [DVD]" }, - new object[] { 1, new[] { 2 }, "My Episode Title", Quality.DVD, true, "My Series Name - 1x02 - My Episode Title [DVD] [Proper]" }, - new object[] { 1, new[] { 2 }, "", Quality.DVD, true, "My Series Name - 1x02 - [DVD] [Proper]" }, - new object[] { 1, new[] { 2, 4 }, "My Episode Title", Quality.HDTV720p, false, "My Series Name - 1x02-1x04 - My Episode Title [HDTV-720p]" }, - new object[] { 1, new[] { 2, 4 }, "My Episode Title", Quality.HDTV720p, true, "My Series Name - 1x02-1x04 - My Episode Title [HDTV-720p] [Proper]" }, - new object[] { 1, new[] { 2, 4 }, "", Quality.HDTV720p, true, "My Series Name - 1x02-1x04 - [HDTV-720p] [Proper]" }, - }; - - - [Test, TestCaseSource("SabNamingCases")] - public void create_proper_sab_titles(int seasons, int[] episodes, string title, Quality quality, bool proper, string expected) - { - var series = Builder.CreateNew() - .With(c => c.Title = "My Series Name") - .Build(); - - var fakeEpisodes = new List(); - - foreach (var episode in episodes) - fakeEpisodes.Add(Builder - .CreateNew() - .With(e => e.EpisodeNumber = episode) - .With(e => e.Title = title) - .Build()); - - var parsResult = new RemoteEpisode() - { - AirDate = DateTime.Now, - EpisodeNumbers = episodes.ToList(), - Quality = new QualityModel(quality, proper), - SeasonNumber = seasons, - Series = series, - EpisodeTitle = title, - Episodes = fakeEpisodes - }; - - parsResult.GetDownloadTitle().Should().Be(expected); - } - - [TestCase(true, Result = "My Series Name - Season 1 [Bluray720p] [Proper]")] - [TestCase(false, Result = "My Series Name - Season 1 [Bluray720p]")] - public string create_proper_sab_season_title(bool proper) - { - var series = Builder.CreateNew() - .With(c => c.Title = "My Series Name") - .Build(); - - var parsResult = new RemoteEpisode() - { - AirDate = DateTime.Now, - Quality = new QualityModel(Quality.Bluray720p, proper), - SeasonNumber = 1, - Series = series, - EpisodeTitle = "My Episode Title", - FullSeason = true - }; - - return parsResult.GetDownloadTitle(); - } - - [TestCase(true, Result = "My Series Name - 2011-12-01 - My Episode Title [Bluray720p] [Proper]")] - [TestCase(false, Result = "My Series Name - 2011-12-01 - My Episode Title [Bluray720p]")] - public string create_proper_sab_daily_titles(bool proper) - { - var series = Builder.CreateNew() - .With(c => c.SeriesType = SeriesTypes.Daily) - .With(c => c.Title = "My Series Name") - .Build(); - - var episode = Builder.CreateNew() - .With(e => e.Title = "My Episode Title") - .Build(); - - var parsResult = new RemoteEpisode - { - AirDate = new DateTime(2011, 12, 1), - Quality = new QualityModel(Quality.Bluray720p, proper), - Series = series, - EpisodeTitle = "My Episode Title", - Episodes = new List { episode } - }; - - return parsResult.GetDownloadTitle(); - } - - [Test] - public void should_not_repeat_the_same_episode_title() - { - var series = Builder.CreateNew() - .With(c => c.Title = "My Series Name") - .Build(); - - var fakeEpisodes = Builder.CreateListOfSize(2) - .All() - .With(e => e.SeasonNumber = 5) - .TheFirst(1) - .With(e => e.Title = "My Episode Title (1)") - .TheLast(1) - .With(e => e.Title = "My Episode Title (2)") - .Build(); - - var parsResult = new RemoteEpisode - { - AirDate = DateTime.Now, - EpisodeNumbers = new List { 10, 11 }, - Quality = new QualityModel(Quality.HDTV720p, false), - SeasonNumber = 35, - Series = series, - Episodes = fakeEpisodes - }; - - parsResult.GetDownloadTitle().Should().Be("My Series Name - 5x01-5x02 - My Episode Title [HDTV-720p]"); - } - - } -} -*/ diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index d1da02111..f4a352f2e 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -185,7 +185,6 @@ - diff --git a/src/NzbDrone.Core/Datastore/Migration/034_remove_series_contraints.cs b/src/NzbDrone.Core/Datastore/Migration/034_remove_series_contraints.cs new file mode 100644 index 000000000..7874e9c38 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/034_remove_series_contraints.cs @@ -0,0 +1,14 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(34)] + public class remove_series_contraints : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + SqLiteAlter.Nullify("Series", new[] { "ImdbId", "TitleSlug" }); + } + } +} diff --git a/src/NzbDrone.Core/Datastore/Migration/Framework/SqliteAlter.cs b/src/NzbDrone.Core/Datastore/Migration/Framework/SqliteAlter.cs index c22670588..c8d423a1c 100644 --- a/src/NzbDrone.Core/Datastore/Migration/Framework/SqliteAlter.cs +++ b/src/NzbDrone.Core/Datastore/Migration/Framework/SqliteAlter.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; namespace NzbDrone.Core.Datastore.Migration.Framework @@ -7,6 +8,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework { void DropColumns(string tableName, IEnumerable columns); void AddIndexes(string tableName, params SQLiteIndex[] indexes); + void Nullify(string tableName, IEnumerable columns); } public class SQLiteAlter : ISQLiteAlter @@ -50,6 +52,44 @@ namespace NzbDrone.Core.Datastore.Migration.Framework } } + public void Nullify(string tableName, IEnumerable columns) + { + using (var transaction = _sqLiteMigrationHelper.BeginTransaction()) + { + var originalColumns = _sqLiteMigrationHelper.GetColumns(tableName); + var originalIndexes = _sqLiteMigrationHelper.GetIndexes(tableName); + + var newColumns = originalColumns.Select(c => + { + if (!columns.Contains(c.Key)) + { + return c.Value; + } + + if (!c.Value.Schema.Contains("NOT NULL") && c.Value.Schema.Contains("NULL")) + { + return c.Value; + } + + if (c.Value.Schema.Contains("NOT NULL")) + { + c.Value.Schema = c.Value.Schema.Replace("NOT NULL", "NULL"); + return c.Value; + } + + c.Value.Schema += " NULL"; + + return c.Value; + }).ToList(); + + var newIndexes = originalIndexes; + + CreateTable(tableName, newColumns, newIndexes); + + transaction.Commit(); + } + } + private void CreateTable(string tableName, List newColumns, IEnumerable newIndexes) { var tempTableName = tableName + "_temp"; diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 7967454d8..4567bc73a 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -189,6 +189,7 @@ +