From 4bb4faf62671fb5aff033d35855256e0e4162cb8 Mon Sep 17 00:00:00 2001 From: markus101 Date: Sun, 24 Mar 2013 21:36:24 -0700 Subject: [PATCH] Migrations Still need to remove System.Data.Sqlite, prefer an option in OrmLite to pluralize table names. --- NzbDrone.Common/NzbDrone.Common.csproj | 2 +- .../{PathExtentions.cs => PathExtensions.cs} | 7 +- .../JobTests/JobControllerFixture.cs | 8 +- .../JobTests/JobRepositoryFixture.cs | 10 +- NzbDrone.Core/Configuration/Config.cs | 1 - NzbDrone.Core/ContainerExtensions.cs | 15 +- NzbDrone.Core/Datastore/DbFactory.cs | 2 + NzbDrone.Core/Datastore/MigrationHelper.cs | 38 ++++ NzbDrone.Core/Datastore/MigrationType.cs | 13 ++ .../Datastore/Migrations/Migration20130324.cs | 168 ++++++++++++++++++ .../Datastore/Migrations/NzbDroneMigration.cs | 43 +++++ NzbDrone.Core/Datastore/NlogAnnouncer.cs | 19 ++ NzbDrone.Core/Indexers/Indexer.cs | 2 + NzbDrone.Core/Indexers/NewznabDefinition.cs | 4 +- NzbDrone.Core/Indexers/NewznabRepository.cs | 2 +- NzbDrone.Core/Indexers/NewznabService.cs | 8 +- NzbDrone.Core/Jobs/JobController.cs | 5 +- NzbDrone.Core/Jobs/JobDefinition.cs | 9 +- NzbDrone.Core/Jobs/JobRepository.cs | 10 +- NzbDrone.Core/MetadataSource/TvDbProxy.cs | 2 +- NzbDrone.Core/NzbDrone.Core.csproj | 20 +++ NzbDrone.Core/Qualities/QualityProfile.cs | 2 + NzbDrone.Core/Qualities/QualitySize.cs | 2 + NzbDrone.Core/ReferenceData/SceneMapping.cs | 2 + NzbDrone.Core/Tv/Series.cs | 7 +- NzbDrone.Core/Tv/SeriesStatusType.cs | 13 ++ NzbDrone.Core/packages.config | 2 + NzbDrone/NzbDrone.csproj | 8 + NzbDrone/packages.config | 1 + 29 files changed, 375 insertions(+), 50 deletions(-) rename NzbDrone.Common/{PathExtentions.cs => PathExtensions.cs} (95%) create mode 100644 NzbDrone.Core/Datastore/MigrationHelper.cs create mode 100644 NzbDrone.Core/Datastore/MigrationType.cs create mode 100644 NzbDrone.Core/Datastore/Migrations/Migration20130324.cs create mode 100644 NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs create mode 100644 NzbDrone.Core/Datastore/NlogAnnouncer.cs create mode 100644 NzbDrone.Core/Tv/SeriesStatusType.cs diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index b82a5ab4f..43b983662 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -123,7 +123,7 @@ - + diff --git a/NzbDrone.Common/PathExtentions.cs b/NzbDrone.Common/PathExtensions.cs similarity index 95% rename from NzbDrone.Common/PathExtentions.cs rename to NzbDrone.Common/PathExtensions.cs index 3ab725f16..cacdf4f96 100644 --- a/NzbDrone.Common/PathExtentions.cs +++ b/NzbDrone.Common/PathExtensions.cs @@ -3,7 +3,7 @@ using System.IO; namespace NzbDrone.Common { - public static class PathExtentions + public static class PathExtensions { private const string WEB_FOLDER = "NzbDrone.Web\\"; private const string APP_DATA = "App_Data\\"; @@ -135,5 +135,10 @@ namespace NzbDrone.Common { return Path.Combine(environmentProvider.ApplicationPath, NZBDRONE_EXE); } + + public static string GetNzbDroneDatabase(this EnvironmentProvider environmentProvider) + { + return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB); + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs b/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs index b076f786c..5ad9f3999 100644 --- a/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs +++ b/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Test.JobTests [Test] public void running_scheduled_jobs_should_updates_last_execution_time() { - GivenPendingJob(new List { new JobDefinition { TypeName = _fakeJob.GetType().FullName } }); + GivenPendingJob(new List { new JobDefinition { Type = _fakeJob.GetType().FullName } }); Subject.EnqueueScheduled(); WaitForQueue(); @@ -91,7 +91,7 @@ namespace NzbDrone.Core.Test.JobTests [Test] public void failing_scheduled_job_should_mark_job_as_failed() { - GivenPendingJob(new List { new JobDefinition { TypeName = _brokenJob.GetType().FullName } }); + GivenPendingJob(new List { new JobDefinition { Type = _brokenJob.GetType().FullName } }); Subject.EnqueueScheduled(); WaitForQueue(); @@ -193,7 +193,7 @@ namespace NzbDrone.Core.Test.JobTests [Test] public void Item_added_to_queue_while_scheduler_runs_should_be_executed() { - GivenPendingJob(new List { new JobDefinition { TypeName = _slowJob.GetType().FullName } }); + GivenPendingJob(new List { new JobDefinition { Type = _slowJob.GetType().FullName } }); var jobThread = new Thread(Subject.EnqueueScheduled); jobThread.Start(); @@ -219,7 +219,7 @@ namespace NzbDrone.Core.Test.JobTests [Test] public void scheduled_job_should_have_scheduler_as_source() { - GivenPendingJob(new List { new JobDefinition { TypeName = _slowJob.GetType().FullName }, new JobDefinition { TypeName = _slowJob2.GetType().FullName } }); + GivenPendingJob(new List { new JobDefinition { Type = _slowJob.GetType().FullName }, new JobDefinition { Type = _slowJob2.GetType().FullName } }); Subject.EnqueueScheduled(); Subject.Queue.Should().OnlyContain(c => c.Source == JobQueueItem.JobSourceType.Scheduler); diff --git a/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs b/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs index c17774ec1..c1f98f1c1 100644 --- a/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs +++ b/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs @@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test.JobTests Storage.All().Should().HaveCount(1); StoredModel.Interval.Should().Be((Int32)_fakeJob.DefaultInterval.TotalMinutes); StoredModel.Name.Should().Be(_fakeJob.Name); - StoredModel.TypeName.Should().Be(_fakeJob.GetType().ToString()); + StoredModel.Type.Should().Be(_fakeJob.GetType().ToString()); StoredModel.LastExecution.Should().HaveYear(DateTime.Now.Year); StoredModel.LastExecution.Should().HaveMonth(DateTime.Now.Month); StoredModel.LastExecution.Should().HaveDay(DateTime.Today.Day); @@ -66,7 +66,7 @@ namespace NzbDrone.Core.Test.JobTests Subject.Init(); AllStoredModels.Should().HaveCount(1); - AllStoredModels.Should().NotContain(c => c.TypeName == deletedJob.TypeName); + AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type); } [Test] @@ -88,7 +88,7 @@ namespace NzbDrone.Core.Test.JobTests AllStoredModels.Should().HaveCount(1); - AllStoredModels.Should().NotContain(c => c.TypeName == deletedJob.TypeName); + AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type); } [Test] @@ -98,7 +98,7 @@ namespace NzbDrone.Core.Test.JobTests var oldJob = Builder.CreateNew() .With(c => c.Id = 0) .With(c => c.Name = "OldName") - .With(c => c.TypeName = typeof(FakeJob).ToString()) + .With(c => c.Type = typeof(FakeJob).ToString()) .With(c => c.Interval = 0) .With(c => c.Enable = true) .With(c => c.Success = true) @@ -116,7 +116,7 @@ namespace NzbDrone.Core.Test.JobTests AllStoredModels.Should().HaveCount(1); - StoredModel.TypeName.Should().Be(newJob.GetType().FullName); + StoredModel.Type.Should().Be(newJob.GetType().FullName); StoredModel.Name.Should().Be(newJob.Name); StoredModel.Interval.Should().Be((int)newJob.DefaultInterval.TotalMinutes); StoredModel.Enable.Should().Be(true); diff --git a/NzbDrone.Core/Configuration/Config.cs b/NzbDrone.Core/Configuration/Config.cs index bda68cb76..211d5055d 100644 --- a/NzbDrone.Core/Configuration/Config.cs +++ b/NzbDrone.Core/Configuration/Config.cs @@ -7,7 +7,6 @@ namespace NzbDrone.Core.Configuration { [Index(Unique = true)] public string Key { get; set; } - public string Value { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Core/ContainerExtensions.cs b/NzbDrone.Core/ContainerExtensions.cs index f9147ac34..fede47272 100644 --- a/NzbDrone.Core/ContainerExtensions.cs +++ b/NzbDrone.Core/ContainerExtensions.cs @@ -23,8 +23,7 @@ namespace NzbDrone.Core containerBuilder.RegisterAssembly("NzbDrone.Core"); containerBuilder.InitDatabase(); - - + containerBuilder.RegisterModule(); } @@ -53,22 +52,16 @@ namespace NzbDrone.Core { logger.Info("Registering Database..."); - var appDataPath = new EnvironmentProvider().GetAppDataPath(); + var environmentProvider = new EnvironmentProvider(); + var appDataPath = environmentProvider.GetAppDataPath(); if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath); container.Register(c => { - return c.Resolve().Create(); + return c.Resolve().Create(environmentProvider.GetNzbDroneDatabase()); }).As().SingleInstance(); - - container.Register(c => - { - return c.Resolve().Create(); - }).As().SingleInstance(); - container.RegisterGeneric(typeof(BasicRepository<>)).As(typeof(IBasicRepository<>)); - } } } \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/DbFactory.cs b/NzbDrone.Core/Datastore/DbFactory.cs index 17d14578c..171aec337 100644 --- a/NzbDrone.Core/Datastore/DbFactory.cs +++ b/NzbDrone.Core/Datastore/DbFactory.cs @@ -28,6 +28,8 @@ namespace NzbDrone.Core.Datastore connectionString = GetConnectionString(dbPath); } + MigrationHelper.MigrateToLatest(connectionString, MigrationType.Main); + OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider(); var dbFactory = new OrmLiteConnectionFactory(connectionString); var connection = dbFactory.Open(); diff --git a/NzbDrone.Core/Datastore/MigrationHelper.cs b/NzbDrone.Core/Datastore/MigrationHelper.cs new file mode 100644 index 000000000..f1209c891 --- /dev/null +++ b/NzbDrone.Core/Datastore/MigrationHelper.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using FluentMigrator; +using FluentMigrator.Runner; +using FluentMigrator.Runner.Initialization; + +namespace NzbDrone.Core.Datastore +{ + public static class MigrationHelper + { + public static void MigrateToLatest(string connectionString, MigrationType migrationType) + { + var announcer = new NlogAnnouncer(); + var assembly = Assembly.GetExecutingAssembly(); + + var migrationContext = new RunnerContext(announcer) + { + Namespace = "NzbDrone.Core.Datastore.Migrations", + ApplicationContext = migrationType + }; + + var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; + var factory = new FluentMigrator.Runner.Processors.Sqlite.SqliteProcessorFactory(); + var processor = factory.Create(connectionString, announcer, options); + var runner = new MigrationRunner(assembly, migrationContext, processor); + runner.MigrateUp(true); + } + } + + public class MigrationOptions : IMigrationProcessorOptions + { + public bool PreviewOnly { get; set; } + public int Timeout { get; set; } + } +} diff --git a/NzbDrone.Core/Datastore/MigrationType.cs b/NzbDrone.Core/Datastore/MigrationType.cs new file mode 100644 index 000000000..b9bd958ce --- /dev/null +++ b/NzbDrone.Core/Datastore/MigrationType.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core.Datastore +{ + public enum MigrationType + { + Main, + Log + } +} diff --git a/NzbDrone.Core/Datastore/Migrations/Migration20130324.cs b/NzbDrone.Core/Datastore/Migrations/Migration20130324.cs new file mode 100644 index 000000000..1911125df --- /dev/null +++ b/NzbDrone.Core/Datastore/Migrations/Migration20130324.cs @@ -0,0 +1,168 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentMigrator; + +namespace NzbDrone.Core.Datastore.Migrations +{ + [Tags("")] + [Migration(20130324)] + public class Migration20130324 : NzbDroneMigration + { + protected override void MainDbUpgrade() + { + Create.Table("Config") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("Key").AsString().PrimaryKey() + .WithColumn("Value").AsString().NotNullable(); + + Create.Table("EpisodeFiles") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("SeriesId").AsInt32().NotNullable() + .WithColumn("Path").AsString().NotNullable() + .WithColumn("Quality").AsInt32().NotNullable() + .WithColumn("Proper").AsBoolean().NotNullable() + .WithColumn("Size").AsInt64().NotNullable() + .WithColumn("DateAdded").AsDateTime().NotNullable() + .WithColumn("SeasonNumber").AsInt32().NotNullable() + .WithColumn("SceneName").AsString().Nullable() + .WithColumn("ReleaseGroup").AsString().Nullable(); + + Create.Table("Episodes") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("TvdbId").AsInt32().Nullable() + .WithColumn("SeriesId").AsInt32().NotNullable() + .WithColumn("SeasonNumber").AsInt32().NotNullable() + .WithColumn("EpisodeNumber").AsInt32().NotNullable() + .WithColumn("Title").AsString().Nullable() + .WithColumn("Overview").AsString().Nullable() + .WithColumn("Ignored").AsBoolean().Nullable() + .WithColumn("EpisodeFileId").AsInt32().Nullable() + .WithColumn("AirDate").AsDateTime().Nullable() + .WithColumn("GrabDate").AsDateTime().Nullable() + .WithColumn("PostDownloadStatus").AsInt32().Nullable() + .WithColumn("AbsoluteEpisodeNumber").AsInt32().Nullable() + .WithColumn("SceneAbsoluteEpisodeNumber").AsInt32().Nullable() + .WithColumn("SceneSeasonNumber").AsInt32().Nullable() + .WithColumn("SceneEpisodeNumber").AsInt32().Nullable(); + + Create.Table("ExternalNotificationDefinitions") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("Enable").AsBoolean().NotNullable() + .WithColumn("Type").AsString().NotNullable() + .WithColumn("Name").AsString().NotNullable(); + + Create.Table("History") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("EpisodeId").AsInt32().NotNullable() + .WithColumn("SeriesId").AsInt32().NotNullable() + .WithColumn("NzbTitle").AsString().NotNullable() + .WithColumn("Date").AsDateTime().NotNullable() + .WithColumn("Quality").AsInt32().NotNullable() + .WithColumn("Proper").AsBoolean().NotNullable() + .WithColumn("Indexer").AsString().NotNullable() + .WithColumn("NzbInfoUrl").AsString().Nullable() + .WithColumn("ReleaseGroup").AsString().Nullable(); + + Create.Table("IndexerDefinitions") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("Enable").AsBoolean().NotNullable() + .WithColumn("Type").AsString().NotNullable() + .WithColumn("Name").AsString().NotNullable(); + + Create.Table("JobDefinitions") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("Enable").AsBoolean().NotNullable() + .WithColumn("Type").AsString().NotNullable() + .WithColumn("Name").AsString().NotNullable() + .WithColumn("Interval").AsInt32().NotNullable() + .WithColumn("LastExecution").AsDateTime().NotNullable() + .WithColumn("Success").AsBoolean().NotNullable(); + + Create.Table("MetadataDefinitions") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("Enable").AsBoolean().NotNullable() + .WithColumn("Type").AsString().NotNullable() + .WithColumn("Name").AsString().NotNullable(); + + Create.Table("NewznabDefinitions") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("Enable").AsBoolean().NotNullable() + .WithColumn("Name").AsString().NotNullable() + .WithColumn("Url").AsString().NotNullable() + .WithColumn("ApiKey").AsString().Nullable() + .WithColumn("BuiltIn").AsBoolean().NotNullable(); + + Create.Table("QualityProfiles") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("Name").AsString().NotNullable() + .WithColumn("Cutoff").AsInt32().NotNullable() + .WithColumn("Allowed").AsString().NotNullable(); + + Create.Table("QualitySizes") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("QualityId").AsInt32().NotNullable().Unique() + .WithColumn("Name").AsString().NotNullable() + .WithColumn("MinSize").AsInt32().NotNullable() + .WithColumn("MaxSize").AsInt32().NotNullable(); + + Create.Table("RootFolders") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("Path").AsString().NotNullable(); + + Create.Table("SceneMappings") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("CleanTitle").AsString().NotNullable() + .WithColumn("SceneName").AsString().NotNullable() + .WithColumn("SeriesId").AsInt32().NotNullable() + .WithColumn("SeasonNumber").AsInt32().NotNullable(); + + Create.Table("Seasons") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("SeriesId").AsInt32().NotNullable() + .WithColumn("SeasonNumber").AsInt32().NotNullable() + .WithColumn("Ignored").AsBoolean().NotNullable(); + + Create.Table("Series") + .WithColumn("Id").AsInt32().PrimaryKey().Identity() + .WithColumn("TvdbId").AsInt32().NotNullable() + .WithColumn("Title").AsString().NotNullable() + .WithColumn("CleanTitle").AsString().NotNullable() + .WithColumn("Status").AsInt32().NotNullable() + .WithColumn("Overview").AsString().NotNullable() + .WithColumn("AirTime").AsString().Nullable() + .WithColumn("Language").AsString().NotNullable() + .WithColumn("Path").AsString().NotNullable() + .WithColumn("Monitored").AsBoolean().NotNullable() + .WithColumn("QualityProfileId").AsString().NotNullable() + .WithColumn("SeasonFolder").AsBoolean().NotNullable() + .WithColumn("LastInfoSync").AsDateTime().Nullable() + .WithColumn("LastDiskSync").AsDateTime().Nullable() + .WithColumn("Runtime").AsInt32().NotNullable() + .WithColumn("BannerUrl").AsString().NotNullable() + .WithColumn("SeriesType").AsInt32().NotNullable() + .WithColumn("BacklogSetting").AsInt32().NotNullable() + .WithColumn("Network").AsString().NotNullable() + .WithColumn("CustomStartDate").AsDateTime().Nullable() + .WithColumn("UseSceneNumbering").AsBoolean().NotNullable() + .WithColumn("TvRageId").AsInt32().Nullable() + .WithColumn("TvRageTitle").AsString().NotNullable() + .WithColumn("UtcOffSet").AsInt32().NotNullable() + .WithColumn("FirstAired").AsDateTime().Nullable(); + } + + protected override void LogDbUpgrade() + { + Create.Table("Logs") + .WithColumn("LogId").AsInt64().PrimaryKey().Identity() + .WithColumn("Message").AsString().NotNullable() + .WithColumn("Time").AsDateTime().NotNullable() + .WithColumn("Logger").AsString().NotNullable() + .WithColumn("Method").AsString().NotNullable() + .WithColumn("Exception").AsString().Nullable() + .WithColumn("ExceptionType").AsString().Nullable() + .WithColumn("Level").AsString().NotNullable(); + } + } +} diff --git a/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs b/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs new file mode 100644 index 000000000..a8ab45812 --- /dev/null +++ b/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentMigrator; +using NzbDrone.Common; + +namespace NzbDrone.Core.Datastore.Migrations +{ + public abstract class NzbDroneMigration : Migration + { + protected virtual void MainDbUpgrade() + { + } + + protected virtual void LogDbUpgrade() + { + } + + public override void Up() + { + if ((MigrationType)this.ApplicationContext == MigrationType.Main) + { + MainDbUpgrade(); + } + else if ((MigrationType)this.ApplicationContext == MigrationType.Log) + { + LogDbUpgrade(); + } + else + { + LogDbUpgrade(); + MainDbUpgrade(); + } + } + + + public override void Down() + { + throw new NotImplementedException(); + } + } +} diff --git a/NzbDrone.Core/Datastore/NlogAnnouncer.cs b/NzbDrone.Core/Datastore/NlogAnnouncer.cs new file mode 100644 index 000000000..3599266e3 --- /dev/null +++ b/NzbDrone.Core/Datastore/NlogAnnouncer.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentMigrator.Runner.Announcers; +using NLog; + +namespace NzbDrone.Core.Datastore +{ + public class NlogAnnouncer : Announcer + { + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + + public override void Write(string message, bool escaped) + { + logger.Info(message); + } + } +} diff --git a/NzbDrone.Core/Indexers/Indexer.cs b/NzbDrone.Core/Indexers/Indexer.cs index 45f60d89b..fe97b7ef9 100644 --- a/NzbDrone.Core/Indexers/Indexer.cs +++ b/NzbDrone.Core/Indexers/Indexer.cs @@ -1,9 +1,11 @@ using System; using NzbDrone.Core.Datastore; +using ServiceStack.DataAnnotations; namespace NzbDrone.Core.Indexers { + [Alias("IndexerDefinitions")] public class Indexer : ModelBase { public Boolean Enable { get; set; } diff --git a/NzbDrone.Core/Indexers/NewznabDefinition.cs b/NzbDrone.Core/Indexers/NewznabDefinition.cs index fecbd5f0b..2b52e2f78 100644 --- a/NzbDrone.Core/Indexers/NewznabDefinition.cs +++ b/NzbDrone.Core/Indexers/NewznabDefinition.cs @@ -1,12 +1,14 @@ using System; using NzbDrone.Core.Datastore; +using ServiceStack.DataAnnotations; namespace NzbDrone.Core.Indexers { + [Alias("NewznabDefinitions")] public class NewznabDefinition : ModelBase { - public Boolean Enabled { get; set; } + public Boolean Enable { get; set; } public String Name { get; set; } public String Url { get; set; } public String ApiKey { get; set; } diff --git a/NzbDrone.Core/Indexers/NewznabRepository.cs b/NzbDrone.Core/Indexers/NewznabRepository.cs index 9c4d67e2d..4f20cfc01 100644 --- a/NzbDrone.Core/Indexers/NewznabRepository.cs +++ b/NzbDrone.Core/Indexers/NewznabRepository.cs @@ -20,7 +20,7 @@ namespace NzbDrone.Core.Indexers public IEnumerable Enabled() { - return Where(n => n.Enabled); + return Where(n => n.Enable); } } } diff --git a/NzbDrone.Core/Indexers/NewznabService.cs b/NzbDrone.Core/Indexers/NewznabService.cs index 39d406ed0..d491f67e0 100644 --- a/NzbDrone.Core/Indexers/NewznabService.cs +++ b/NzbDrone.Core/Indexers/NewznabService.cs @@ -79,9 +79,9 @@ namespace NzbDrone.Core.Indexers { var newznabIndexers = new List { - new NewznabDefinition { Enabled = false, Name = "Nzbs.org", Url = "http://nzbs.org", BuiltIn = true }, - new NewznabDefinition { Enabled = false, Name = "Nzb.su", Url = "https://nzb.su", BuiltIn = true }, - new NewznabDefinition { Enabled = false, Name = "Dognzb.cr", Url = "https://dognzb.cr", BuiltIn = true } + new NewznabDefinition { Enable = false, Name = "Nzbs.org", Url = "http://nzbs.org", BuiltIn = true }, + new NewznabDefinition { Enable = false, Name = "Nzb.su", Url = "https://nzb.su", BuiltIn = true }, + new NewznabDefinition { Enable = false, Name = "Dognzb.cr", Url = "https://dognzb.cr", BuiltIn = true } }; _logger.Debug("Initializing Newznab indexers. Count {0}", newznabIndexers); @@ -108,7 +108,7 @@ namespace NzbDrone.Core.Indexers { var definition = new NewznabDefinition { - Enabled = false, + Enable = false, Name = indexerLocal.Name, Url = indexerLocal.Url, ApiKey = indexerLocal.ApiKey, diff --git a/NzbDrone.Core/Jobs/JobController.cs b/NzbDrone.Core/Jobs/JobController.cs index 7b26c19b4..6f0398ae2 100644 --- a/NzbDrone.Core/Jobs/JobController.cs +++ b/NzbDrone.Core/Jobs/JobController.cs @@ -42,10 +42,8 @@ namespace NzbDrone.Core.Jobs Task.Factory.StartNew(ProcessQueue, _cancellationTokenSource.Token); } - public bool IsProcessing { get; private set; } - public IEnumerable Queue { get @@ -63,7 +61,7 @@ namespace NzbDrone.Core.Jobs } var pendingJobs = _jobRepository.GetPendingJobs() - .Select(c => _jobs.Single(t => t.GetType().ToString() == c.TypeName) + .Select(c => _jobs.Single(t => t.GetType().ToString() == c.Type) .GetType()).ToList(); @@ -99,7 +97,6 @@ namespace NzbDrone.Core.Jobs } - public bool Enqueue(string jobTypeString) { var type = Type.GetType(jobTypeString); diff --git a/NzbDrone.Core/Jobs/JobDefinition.cs b/NzbDrone.Core/Jobs/JobDefinition.cs index 8f19e11a5..b17cc0f00 100644 --- a/NzbDrone.Core/Jobs/JobDefinition.cs +++ b/NzbDrone.Core/Jobs/JobDefinition.cs @@ -1,21 +1,18 @@ using System; using System.Linq; using NzbDrone.Core.Datastore; +using ServiceStack.DataAnnotations; namespace NzbDrone.Core.Jobs { + [Alias("JobDefinitions")] public class JobDefinition : ModelBase { public Boolean Enable { get; set; } - - public String TypeName { get; set; } - + public String Type { get; set; } public String Name { get; set; } - public Int32 Interval { get; set; } - public DateTime LastExecution { get; set; } - public Boolean Success { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/JobRepository.cs b/NzbDrone.Core/Jobs/JobRepository.cs index 52fc0be6e..3094d74df 100644 --- a/NzbDrone.Core/Jobs/JobRepository.cs +++ b/NzbDrone.Core/Jobs/JobRepository.cs @@ -28,7 +28,7 @@ namespace NzbDrone.Core.Jobs public JobDefinition GetDefinition(Type type) { - return Single(c => c.TypeName == type.FullName); + return Single(c => c.Type == type.FullName); } @@ -39,12 +39,12 @@ namespace NzbDrone.Core.Jobs public void Init() { - var currentJobs = All(); + var currentJobs = All().ToList(); _logger.Debug("Initializing jobs. Available: {0} Existing:{1}", _jobs.Count(), currentJobs.Count()); foreach (var currentJob in currentJobs) { - if (_jobs.All(c => c.GetType().ToString() != currentJob.TypeName)) + if (_jobs.All(c => c.GetType().ToString() != currentJob.Type)) { _logger.Debug("Removing job from database '{0}'", currentJob.Name); Delete(currentJob.Id); @@ -53,13 +53,13 @@ namespace NzbDrone.Core.Jobs foreach (var job in _jobs) { - var jobDefinition = currentJobs.SingleOrDefault(c => c.TypeName == job.GetType().ToString()); + var jobDefinition = currentJobs.SingleOrDefault(c => c.Type == job.GetType().ToString()); if (jobDefinition == null) { jobDefinition = new JobDefinition { - TypeName = job.GetType().ToString(), + Type = job.GetType().ToString(), LastExecution = DateTime.Now }; } diff --git a/NzbDrone.Core/MetadataSource/TvDbProxy.cs b/NzbDrone.Core/MetadataSource/TvDbProxy.cs index 0a22dc79c..cb1af57e0 100644 --- a/NzbDrone.Core/MetadataSource/TvDbProxy.cs +++ b/NzbDrone.Core/MetadataSource/TvDbProxy.cs @@ -55,7 +55,7 @@ namespace NzbDrone.Core.MetadataSource series.Title = tvDbSeries.SeriesName; series.AirTime = CleanAirsTime(tvDbSeries.Airs_Time); series.Overview = tvDbSeries.Overview; - series.Status = tvDbSeries.Status; + series.Status = tvDbSeries.Status == "Continuing" ? SeriesStatusType.Continuing : SeriesStatusType.Ended ; series.Language = tvDbSeries.Language ?? string.Empty; series.CleanTitle = Parser.NormalizeTitle(tvDbSeries.SeriesName); series.LastInfoSync = DateTime.Now; diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index e3c36e5ec..fce2e8096 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -127,6 +127,12 @@ False ..\packages\Autofac.3.0.1\lib\net40\Autofac.dll + + ..\packages\FluentMigrator.1.0.6.0\lib\40\FluentMigrator.dll + + + ..\packages\FluentMigrator.1.0.6.0\tools\FluentMigrator.Runner.dll + ..\packages\Growl.0.6\lib\Growl.Connector.dll @@ -181,6 +187,14 @@ + + False + ..\packages\System.Data.SQLite.x64.1.0.84.0\lib\net40\System.Data.SQLite.dll + + + False + ..\packages\System.Data.SQLite.x64.1.0.84.0\lib\net40\System.Data.SQLite.Linq.dll + @@ -201,9 +215,14 @@ + + + + + @@ -530,6 +549,7 @@ + diff --git a/NzbDrone.Core/Qualities/QualityProfile.cs b/NzbDrone.Core/Qualities/QualityProfile.cs index 5ec6f799f..b33a6c8fa 100644 --- a/NzbDrone.Core/Qualities/QualityProfile.cs +++ b/NzbDrone.Core/Qualities/QualityProfile.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Core.Datastore; +using ServiceStack.DataAnnotations; namespace NzbDrone.Core.Qualities { + [Alias("QualityProfiles")] public class QualityProfile : ModelBase { public string Name { get; set; } diff --git a/NzbDrone.Core/Qualities/QualitySize.cs b/NzbDrone.Core/Qualities/QualitySize.cs index 3e9e31032..b8521f2f1 100644 --- a/NzbDrone.Core/Qualities/QualitySize.cs +++ b/NzbDrone.Core/Qualities/QualitySize.cs @@ -1,9 +1,11 @@ using System.Linq; using NzbDrone.Core.Datastore; +using ServiceStack.DataAnnotations; namespace NzbDrone.Core.Qualities { + [Alias("QualitySizes")] public class QualitySize : ModelBase { public int QualityId { get; set; } diff --git a/NzbDrone.Core/ReferenceData/SceneMapping.cs b/NzbDrone.Core/ReferenceData/SceneMapping.cs index e92d9b260..de3ab5c92 100644 --- a/NzbDrone.Core/ReferenceData/SceneMapping.cs +++ b/NzbDrone.Core/ReferenceData/SceneMapping.cs @@ -1,8 +1,10 @@ using System.Linq; using NzbDrone.Core.Datastore; +using ServiceStack.DataAnnotations; namespace NzbDrone.Core.ReferenceData { + [Alias("SceneMappings")] public class SceneMapping : ModelBase { public string CleanTitle { get; set; } diff --git a/NzbDrone.Core/Tv/Series.cs b/NzbDrone.Core/Tv/Series.cs index a29df6b5c..4f900e05d 100644 --- a/NzbDrone.Core/Tv/Series.cs +++ b/NzbDrone.Core/Tv/Series.cs @@ -4,7 +4,7 @@ using System; using NzbDrone.Core.Datastore; using NzbDrone.Core.Model; using NzbDrone.Core.Qualities; - +using ServiceStack.DataAnnotations; namespace NzbDrone.Core.Tv @@ -21,11 +21,8 @@ namespace NzbDrone.Core.Tv public int TvDbId { get; set; } public string Title { get; set; } public string CleanTitle { get; set; } - public string Status { get; set; } - - + public SeriesStatusType Status { get; set; } public string Overview { get; set; } - public String AirTime { get; set; } public string Language { get; set; } public string Path { get; set; } diff --git a/NzbDrone.Core/Tv/SeriesStatusType.cs b/NzbDrone.Core/Tv/SeriesStatusType.cs new file mode 100644 index 000000000..1b9381d21 --- /dev/null +++ b/NzbDrone.Core/Tv/SeriesStatusType.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core.Tv +{ + public enum SeriesStatusType + { + Continuing = 0, + Ended = 1 + } +} diff --git a/NzbDrone.Core/packages.config b/NzbDrone.Core/packages.config index 14799a275..4a760c222 100644 --- a/NzbDrone.Core/packages.config +++ b/NzbDrone.Core/packages.config @@ -2,6 +2,7 @@ + @@ -14,5 +15,6 @@ + \ No newline at end of file diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index 36c51b16c..807829a60 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -89,6 +89,14 @@ + + False + ..\packages\System.Data.SQLite.x86.1.0.84.0\lib\net40\System.Data.SQLite.dll + + + False + ..\packages\System.Data.SQLite.x86.1.0.84.0\lib\net40\System.Data.SQLite.Linq.dll + diff --git a/NzbDrone/packages.config b/NzbDrone/packages.config index bcfe36c81..baccdcc0c 100644 --- a/NzbDrone/packages.config +++ b/NzbDrone/packages.config @@ -9,4 +9,5 @@ + \ No newline at end of file