From b69b322bd5544d1d2d9ed3f69fccbe5d17d81a32 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Mon, 3 Jul 2017 14:44:08 +0100 Subject: [PATCH] Added Migrations rather than a manual DB Script #865 --- .../Engine/Interfaces/IRequestEngine.cs | 6 +- src/Ombi.Core/Engine/TvRequestEngine.cs | 38 +- src/Ombi.Store/Context/OmbiContext.cs | 14 - .../20170703134019_Initial.Designer.cs | 393 +++++++++++++++++ .../Migrations/20170703134019_Initial.cs | 396 ++++++++++++++++++ .../Migrations/OmbiContextModelSnapshot.cs | 392 +++++++++++++++++ src/Ombi.Store/Migrations/OmbiMigrations.bat | 1 + src/Ombi.Store/Ombi.Store.csproj | 9 - src/Ombi.Store/Sql.Designer.cs | 89 ---- src/Ombi.Store/Sql.resx | 124 ------ src/Ombi.Store/SqlTables.sql | 175 -------- src/Ombi/Controllers/SettingsController.cs | 1 + src/Ombi/Ombi.csproj | 1 + 13 files changed, 1206 insertions(+), 433 deletions(-) create mode 100644 src/Ombi.Store/Migrations/20170703134019_Initial.Designer.cs create mode 100644 src/Ombi.Store/Migrations/20170703134019_Initial.cs create mode 100644 src/Ombi.Store/Migrations/OmbiContextModelSnapshot.cs create mode 100644 src/Ombi.Store/Migrations/OmbiMigrations.bat delete mode 100644 src/Ombi.Store/Sql.Designer.cs delete mode 100644 src/Ombi.Store/Sql.resx delete mode 100644 src/Ombi.Store/SqlTables.sql diff --git a/src/Ombi.Core/Engine/Interfaces/IRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/IRequestEngine.cs index 2a9598634..90a6b0011 100644 --- a/src/Ombi.Core/Engine/Interfaces/IRequestEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/IRequestEngine.cs @@ -7,9 +7,9 @@ namespace Ombi.Core.Engine.Interfaces public interface IRequestEngine { - Task> GetApprovedRequests(); - Task> GetNewRequests(); - Task> GetAvailableRequests(); + //Task> GetApprovedRequests(); + //Task> GetNewRequests(); + //Task> GetAvailableRequests(); RequestCountModel RequestCount(); Task> GetRequests(int count, int position); Task> GetRequests(); diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index c6d672628..bc63d2a16 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -248,7 +248,7 @@ namespace Ombi.Core.Engine public async Task> SearchTvRequest(string search) { var allRequests = TvRepository.Get(); - var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)); + var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync(); return results; } @@ -325,25 +325,25 @@ namespace Ombi.Core.Engine return Task.FromResult(new RequestEngineResult { RequestAdded = true }); } - public async Task> GetApprovedRequests() - { - //var allRequests = TvRepository.Get(); - //return await allRequests.Where(x => x.Approved && !x.Available).ToListAsync(); - return null; - } + //public async Task> GetApprovedRequests() + //{ + // var allRequests = TvRepository.Get(); + + + //} - public async Task> GetNewRequests() - { - //var allRequests = await TvRepository.GetAllAsync(); - //return allRequests.Where(x => !x.Approved && !x.Available); - return null; - } + //public async Task> GetNewRequests() + //{ + // //var allRequests = await TvRepository.GetAllAsync(); + // //return allRequests.Where(x => !x.Approved && !x.Available); + // return null; + //} - public async Task> GetAvailableRequests() - { - //var allRequests = await TvRepository.GetAllAsync(); - //return allRequests.Where(x => x.Available); - return null; - } + //public async Task> GetAvailableRequests() + //{ + // //var allRequests = await TvRepository.GetAllAsync(); + // //return allRequests.Where(x => x.Available); + // return null; + //} } } \ No newline at end of file diff --git a/src/Ombi.Store/Context/OmbiContext.cs b/src/Ombi.Store/Context/OmbiContext.cs index 3835bd75e..0330443a6 100644 --- a/src/Ombi.Store/Context/OmbiContext.cs +++ b/src/Ombi.Store/Context/OmbiContext.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Linq; using Microsoft.EntityFrameworkCore; using Ombi.Helpers; @@ -16,20 +15,7 @@ namespace Ombi.Store.Context if (_created) return; _created = true; - Database.EnsureCreated(); Database.Migrate(); - -#if DEBUG - var location = System.Reflection.Assembly.GetEntryAssembly().Location; - var directory = System.IO.Path.GetDirectoryName(location); - var file = File.ReadAllText(Path.Combine(directory,"SqlTables.sql")); -#else - - var file = File.ReadAllText("SqlTables.sql"); -#endif - // Run Script - - Database.ExecuteSqlCommand(file, 0); // Add the notifcation templates AddAllTemplates(); diff --git a/src/Ombi.Store/Migrations/20170703134019_Initial.Designer.cs b/src/Ombi.Store/Migrations/20170703134019_Initial.Designer.cs new file mode 100644 index 000000000..78e6f1172 --- /dev/null +++ b/src/Ombi.Store/Migrations/20170703134019_Initial.Designer.cs @@ -0,0 +1,393 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Ombi.Store.Context; +using Ombi.Helpers; +using Ombi.Store.Entities; + +namespace Ombi.Store.Migrations +{ + [DbContext(typeof(OmbiContext))] + [Migration("20170703134019_Initial")] + partial class Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.1"); + + modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Content"); + + b.Property("SettingsName"); + + b.HasKey("Id"); + + b.ToTable("GlobalSettings"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.NotificationTemplates", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Agent"); + + b.Property("Enabled"); + + b.Property("Message"); + + b.Property("NotificationType"); + + b.Property("Subject"); + + b.HasKey("Id"); + + b.ToTable("NotificationTemplates"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("Key"); + + b.Property("ProviderId"); + + b.Property("ReleaseYear"); + + b.Property("Title"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("PlexContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ParentKey"); + + b.Property("PlexContentId"); + + b.Property("SeasonKey"); + + b.Property("SeasonNumber"); + + b.HasKey("Id"); + + b.HasIndex("PlexContentId"); + + b.ToTable("PlexSeasonsContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.RadarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("RadarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.ChildRequests", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Approved"); + + b.Property("Available"); + + b.Property("Denied"); + + b.Property("DeniedReason"); + + b.Property("IssueId"); + + b.Property("ParentRequestId"); + + b.Property("RequestType"); + + b.Property("RequestedDate"); + + b.Property("RequestedUserId"); + + b.HasKey("Id"); + + b.HasIndex("ParentRequestId"); + + b.HasIndex("RequestedUserId"); + + b.ToTable("ChildRequests"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieIssues", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("IssueId"); + + b.Property("MovieId"); + + b.Property("Subect"); + + b.HasKey("Id"); + + b.HasIndex("IssueId"); + + b.HasIndex("MovieId"); + + b.ToTable("MovieIssues"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieRequests", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Approved"); + + b.Property("Available"); + + b.Property("Denied"); + + b.Property("DeniedReason"); + + b.Property("ImdbId"); + + b.Property("IssueId"); + + b.Property("Overview"); + + b.Property("PosterPath"); + + b.Property("ReleaseDate"); + + b.Property("RequestType"); + + b.Property("RequestedDate"); + + b.Property("RequestedUserId"); + + b.Property("Status"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.HasKey("Id"); + + b.HasIndex("RequestedUserId"); + + b.ToTable("MovieRequests"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.TvIssues", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("IssueId"); + + b.Property("Subect"); + + b.Property("TvId"); + + b.HasKey("Id"); + + b.HasIndex("IssueId"); + + b.HasIndex("TvId"); + + b.ToTable("TvIssues"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.TvRequests", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ImdbId"); + + b.Property("Overview"); + + b.Property("PosterPath"); + + b.Property("ReleaseDate"); + + b.Property("RootFolder"); + + b.Property("Status"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("TvRequests"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Alias"); + + b.Property("ClaimsSerialized"); + + b.Property("EmailAddress"); + + b.Property("Password"); + + b.Property("Salt"); + + b.Property("UserType"); + + b.Property("Username"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Ombi.Store.Repository.Requests.EpisodeRequests", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AirDate"); + + b.Property("Approved"); + + b.Property("Available"); + + b.Property("EpisodeNumber"); + + b.Property("Requested"); + + b.Property("SeasonId"); + + b.Property("Title"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.HasIndex("SeasonId"); + + b.ToTable("EpisodeRequests"); + }); + + modelBuilder.Entity("Ombi.Store.Repository.Requests.SeasonRequests", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChildRequestId"); + + b.Property("SeasonNumber"); + + b.HasKey("Id"); + + b.HasIndex("ChildRequestId"); + + b.ToTable("SeasonRequests"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.HasOne("Ombi.Store.Entities.PlexContent") + .WithMany("Seasons") + .HasForeignKey("PlexContentId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.ChildRequests", b => + { + b.HasOne("Ombi.Store.Entities.Requests.TvRequests", "ParentRequest") + .WithMany("ChildRequests") + .HasForeignKey("ParentRequestId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Ombi.Store.Entities.User", "RequestedUser") + .WithMany() + .HasForeignKey("RequestedUserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieIssues", b => + { + b.HasOne("Ombi.Store.Entities.Requests.MovieRequests") + .WithMany("Issues") + .HasForeignKey("IssueId"); + + b.HasOne("Ombi.Store.Entities.Requests.MovieRequests", "Movie") + .WithMany() + .HasForeignKey("MovieId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieRequests", b => + { + b.HasOne("Ombi.Store.Entities.User", "RequestedUser") + .WithMany() + .HasForeignKey("RequestedUserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.TvIssues", b => + { + b.HasOne("Ombi.Store.Entities.Requests.ChildRequests") + .WithMany("Issues") + .HasForeignKey("IssueId"); + + b.HasOne("Ombi.Store.Entities.Requests.ChildRequests", "Child") + .WithMany() + .HasForeignKey("TvId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Repository.Requests.EpisodeRequests", b => + { + b.HasOne("Ombi.Store.Repository.Requests.SeasonRequests", "Season") + .WithMany("Episodes") + .HasForeignKey("SeasonId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Repository.Requests.SeasonRequests", b => + { + b.HasOne("Ombi.Store.Entities.Requests.ChildRequests", "ChildRequest") + .WithMany("SeasonRequests") + .HasForeignKey("ChildRequestId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Ombi.Store/Migrations/20170703134019_Initial.cs b/src/Ombi.Store/Migrations/20170703134019_Initial.cs new file mode 100644 index 000000000..7931e4083 --- /dev/null +++ b/src/Ombi.Store/Migrations/20170703134019_Initial.cs @@ -0,0 +1,396 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Ombi.Store.Migrations +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "GlobalSettings", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Content = table.Column(nullable: true), + SettingsName = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_GlobalSettings", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "NotificationTemplates", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Agent = table.Column(nullable: false), + Enabled = table.Column(nullable: false), + Message = table.Column(nullable: true), + NotificationType = table.Column(nullable: false), + Subject = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_NotificationTemplates", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "PlexContent", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + AddedAt = table.Column(nullable: false), + Key = table.Column(nullable: true), + ProviderId = table.Column(nullable: true), + ReleaseYear = table.Column(nullable: true), + Title = table.Column(nullable: true), + Type = table.Column(nullable: false), + Url = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PlexContent", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "RadarrCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + TheMovieDbId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RadarrCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "TvRequests", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ImdbId = table.Column(nullable: true), + Overview = table.Column(nullable: true), + PosterPath = table.Column(nullable: true), + ReleaseDate = table.Column(nullable: false), + RootFolder = table.Column(nullable: true), + Status = table.Column(nullable: true), + Title = table.Column(nullable: true), + TvDbId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TvRequests", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Alias = table.Column(nullable: true), + ClaimsSerialized = table.Column(nullable: true), + EmailAddress = table.Column(nullable: true), + Password = table.Column(nullable: true), + Salt = table.Column(nullable: true), + UserType = table.Column(nullable: false), + Username = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "PlexSeasonsContent", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ParentKey = table.Column(nullable: false), + PlexContentId = table.Column(nullable: false), + SeasonKey = table.Column(nullable: false), + SeasonNumber = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PlexSeasonsContent", x => x.Id); + table.ForeignKey( + name: "FK_PlexSeasonsContent_PlexContent_PlexContentId", + column: x => x.PlexContentId, + principalTable: "PlexContent", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ChildRequests", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Approved = table.Column(nullable: false), + Available = table.Column(nullable: false), + Denied = table.Column(nullable: true), + DeniedReason = table.Column(nullable: true), + IssueId = table.Column(nullable: true), + ParentRequestId = table.Column(nullable: false), + RequestType = table.Column(nullable: false), + RequestedDate = table.Column(nullable: false), + RequestedUserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ChildRequests", x => x.Id); + table.ForeignKey( + name: "FK_ChildRequests_TvRequests_ParentRequestId", + column: x => x.ParentRequestId, + principalTable: "TvRequests", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ChildRequests_Users_RequestedUserId", + column: x => x.RequestedUserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "MovieRequests", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Approved = table.Column(nullable: false), + Available = table.Column(nullable: false), + Denied = table.Column(nullable: true), + DeniedReason = table.Column(nullable: true), + ImdbId = table.Column(nullable: true), + IssueId = table.Column(nullable: true), + Overview = table.Column(nullable: true), + PosterPath = table.Column(nullable: true), + ReleaseDate = table.Column(nullable: false), + RequestType = table.Column(nullable: false), + RequestedDate = table.Column(nullable: false), + RequestedUserId = table.Column(nullable: false), + Status = table.Column(nullable: true), + TheMovieDbId = table.Column(nullable: false), + Title = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_MovieRequests", x => x.Id); + table.ForeignKey( + name: "FK_MovieRequests_Users_RequestedUserId", + column: x => x.RequestedUserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "TvIssues", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Description = table.Column(nullable: true), + IssueId = table.Column(nullable: true), + Subect = table.Column(nullable: true), + TvId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TvIssues", x => x.Id); + table.ForeignKey( + name: "FK_TvIssues_ChildRequests_IssueId", + column: x => x.IssueId, + principalTable: "ChildRequests", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_TvIssues_ChildRequests_TvId", + column: x => x.TvId, + principalTable: "ChildRequests", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SeasonRequests", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ChildRequestId = table.Column(nullable: false), + SeasonNumber = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SeasonRequests", x => x.Id); + table.ForeignKey( + name: "FK_SeasonRequests_ChildRequests_ChildRequestId", + column: x => x.ChildRequestId, + principalTable: "ChildRequests", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "MovieIssues", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Description = table.Column(nullable: true), + IssueId = table.Column(nullable: true), + MovieId = table.Column(nullable: false), + Subect = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_MovieIssues", x => x.Id); + table.ForeignKey( + name: "FK_MovieIssues_MovieRequests_IssueId", + column: x => x.IssueId, + principalTable: "MovieRequests", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_MovieIssues_MovieRequests_MovieId", + column: x => x.MovieId, + principalTable: "MovieRequests", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "EpisodeRequests", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + AirDate = table.Column(nullable: false), + Approved = table.Column(nullable: false), + Available = table.Column(nullable: false), + EpisodeNumber = table.Column(nullable: false), + Requested = table.Column(nullable: false), + SeasonId = table.Column(nullable: false), + Title = table.Column(nullable: true), + Url = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_EpisodeRequests", x => x.Id); + table.ForeignKey( + name: "FK_EpisodeRequests_SeasonRequests_SeasonId", + column: x => x.SeasonId, + principalTable: "SeasonRequests", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_PlexSeasonsContent_PlexContentId", + table: "PlexSeasonsContent", + column: "PlexContentId"); + + migrationBuilder.CreateIndex( + name: "IX_ChildRequests_ParentRequestId", + table: "ChildRequests", + column: "ParentRequestId"); + + migrationBuilder.CreateIndex( + name: "IX_ChildRequests_RequestedUserId", + table: "ChildRequests", + column: "RequestedUserId"); + + migrationBuilder.CreateIndex( + name: "IX_MovieIssues_IssueId", + table: "MovieIssues", + column: "IssueId"); + + migrationBuilder.CreateIndex( + name: "IX_MovieIssues_MovieId", + table: "MovieIssues", + column: "MovieId"); + + migrationBuilder.CreateIndex( + name: "IX_MovieRequests_RequestedUserId", + table: "MovieRequests", + column: "RequestedUserId"); + + migrationBuilder.CreateIndex( + name: "IX_TvIssues_IssueId", + table: "TvIssues", + column: "IssueId"); + + migrationBuilder.CreateIndex( + name: "IX_TvIssues_TvId", + table: "TvIssues", + column: "TvId"); + + migrationBuilder.CreateIndex( + name: "IX_EpisodeRequests_SeasonId", + table: "EpisodeRequests", + column: "SeasonId"); + + migrationBuilder.CreateIndex( + name: "IX_SeasonRequests_ChildRequestId", + table: "SeasonRequests", + column: "ChildRequestId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "GlobalSettings"); + + migrationBuilder.DropTable( + name: "NotificationTemplates"); + + migrationBuilder.DropTable( + name: "PlexSeasonsContent"); + + migrationBuilder.DropTable( + name: "RadarrCache"); + + migrationBuilder.DropTable( + name: "MovieIssues"); + + migrationBuilder.DropTable( + name: "TvIssues"); + + migrationBuilder.DropTable( + name: "EpisodeRequests"); + + migrationBuilder.DropTable( + name: "PlexContent"); + + migrationBuilder.DropTable( + name: "MovieRequests"); + + migrationBuilder.DropTable( + name: "SeasonRequests"); + + migrationBuilder.DropTable( + name: "ChildRequests"); + + migrationBuilder.DropTable( + name: "TvRequests"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/src/Ombi.Store/Migrations/OmbiContextModelSnapshot.cs b/src/Ombi.Store/Migrations/OmbiContextModelSnapshot.cs new file mode 100644 index 000000000..7b7237f35 --- /dev/null +++ b/src/Ombi.Store/Migrations/OmbiContextModelSnapshot.cs @@ -0,0 +1,392 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Ombi.Store.Context; +using Ombi.Helpers; +using Ombi.Store.Entities; + +namespace Ombi.Store.Migrations +{ + [DbContext(typeof(OmbiContext))] + partial class OmbiContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.1"); + + modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Content"); + + b.Property("SettingsName"); + + b.HasKey("Id"); + + b.ToTable("GlobalSettings"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.NotificationTemplates", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Agent"); + + b.Property("Enabled"); + + b.Property("Message"); + + b.Property("NotificationType"); + + b.Property("Subject"); + + b.HasKey("Id"); + + b.ToTable("NotificationTemplates"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("Key"); + + b.Property("ProviderId"); + + b.Property("ReleaseYear"); + + b.Property("Title"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("PlexContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ParentKey"); + + b.Property("PlexContentId"); + + b.Property("SeasonKey"); + + b.Property("SeasonNumber"); + + b.HasKey("Id"); + + b.HasIndex("PlexContentId"); + + b.ToTable("PlexSeasonsContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.RadarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("RadarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.ChildRequests", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Approved"); + + b.Property("Available"); + + b.Property("Denied"); + + b.Property("DeniedReason"); + + b.Property("IssueId"); + + b.Property("ParentRequestId"); + + b.Property("RequestType"); + + b.Property("RequestedDate"); + + b.Property("RequestedUserId"); + + b.HasKey("Id"); + + b.HasIndex("ParentRequestId"); + + b.HasIndex("RequestedUserId"); + + b.ToTable("ChildRequests"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieIssues", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("IssueId"); + + b.Property("MovieId"); + + b.Property("Subect"); + + b.HasKey("Id"); + + b.HasIndex("IssueId"); + + b.HasIndex("MovieId"); + + b.ToTable("MovieIssues"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieRequests", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Approved"); + + b.Property("Available"); + + b.Property("Denied"); + + b.Property("DeniedReason"); + + b.Property("ImdbId"); + + b.Property("IssueId"); + + b.Property("Overview"); + + b.Property("PosterPath"); + + b.Property("ReleaseDate"); + + b.Property("RequestType"); + + b.Property("RequestedDate"); + + b.Property("RequestedUserId"); + + b.Property("Status"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.HasKey("Id"); + + b.HasIndex("RequestedUserId"); + + b.ToTable("MovieRequests"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.TvIssues", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("IssueId"); + + b.Property("Subect"); + + b.Property("TvId"); + + b.HasKey("Id"); + + b.HasIndex("IssueId"); + + b.HasIndex("TvId"); + + b.ToTable("TvIssues"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.TvRequests", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ImdbId"); + + b.Property("Overview"); + + b.Property("PosterPath"); + + b.Property("ReleaseDate"); + + b.Property("RootFolder"); + + b.Property("Status"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("TvRequests"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Alias"); + + b.Property("ClaimsSerialized"); + + b.Property("EmailAddress"); + + b.Property("Password"); + + b.Property("Salt"); + + b.Property("UserType"); + + b.Property("Username"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Ombi.Store.Repository.Requests.EpisodeRequests", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AirDate"); + + b.Property("Approved"); + + b.Property("Available"); + + b.Property("EpisodeNumber"); + + b.Property("Requested"); + + b.Property("SeasonId"); + + b.Property("Title"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.HasIndex("SeasonId"); + + b.ToTable("EpisodeRequests"); + }); + + modelBuilder.Entity("Ombi.Store.Repository.Requests.SeasonRequests", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChildRequestId"); + + b.Property("SeasonNumber"); + + b.HasKey("Id"); + + b.HasIndex("ChildRequestId"); + + b.ToTable("SeasonRequests"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.HasOne("Ombi.Store.Entities.PlexContent") + .WithMany("Seasons") + .HasForeignKey("PlexContentId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.ChildRequests", b => + { + b.HasOne("Ombi.Store.Entities.Requests.TvRequests", "ParentRequest") + .WithMany("ChildRequests") + .HasForeignKey("ParentRequestId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Ombi.Store.Entities.User", "RequestedUser") + .WithMany() + .HasForeignKey("RequestedUserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieIssues", b => + { + b.HasOne("Ombi.Store.Entities.Requests.MovieRequests") + .WithMany("Issues") + .HasForeignKey("IssueId"); + + b.HasOne("Ombi.Store.Entities.Requests.MovieRequests", "Movie") + .WithMany() + .HasForeignKey("MovieId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.MovieRequests", b => + { + b.HasOne("Ombi.Store.Entities.User", "RequestedUser") + .WithMany() + .HasForeignKey("RequestedUserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.Requests.TvIssues", b => + { + b.HasOne("Ombi.Store.Entities.Requests.ChildRequests") + .WithMany("Issues") + .HasForeignKey("IssueId"); + + b.HasOne("Ombi.Store.Entities.Requests.ChildRequests", "Child") + .WithMany() + .HasForeignKey("TvId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Repository.Requests.EpisodeRequests", b => + { + b.HasOne("Ombi.Store.Repository.Requests.SeasonRequests", "Season") + .WithMany("Episodes") + .HasForeignKey("SeasonId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Repository.Requests.SeasonRequests", b => + { + b.HasOne("Ombi.Store.Entities.Requests.ChildRequests", "ChildRequest") + .WithMany("SeasonRequests") + .HasForeignKey("ChildRequestId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Ombi.Store/Migrations/OmbiMigrations.bat b/src/Ombi.Store/Migrations/OmbiMigrations.bat new file mode 100644 index 000000000..27f625bbb --- /dev/null +++ b/src/Ombi.Store/Migrations/OmbiMigrations.bat @@ -0,0 +1 @@ +dotnet ef migrations add MIGRATIONNAME --context OmbiContext --startup-project ../Ombi/Ombi.csproj \ No newline at end of file diff --git a/src/Ombi.Store/Ombi.Store.csproj b/src/Ombi.Store/Ombi.Store.csproj index 2824f10b4..4ebe158cc 100644 --- a/src/Ombi.Store/Ombi.Store.csproj +++ b/src/Ombi.Store/Ombi.Store.csproj @@ -4,10 +4,6 @@ netstandard1.6 - - - - @@ -18,11 +14,6 @@ - - - PreserveNewest - - diff --git a/src/Ombi.Store/Sql.Designer.cs b/src/Ombi.Store/Sql.Designer.cs deleted file mode 100644 index 86551871e..000000000 --- a/src/Ombi.Store/Sql.Designer.cs +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Ombi.Store { - using System; - using System.Reflection; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - public class Sql { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Sql() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - public static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Ombi.Store.Sql", typeof(Sql).GetTypeInfo().Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - public static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to CREATE TABLE IF NOT EXISTS GlobalSettings - ///( - /// Id INTEGER PRIMARY KEY AUTOINCREMENT, - /// SettingsName varchar(50) NOT NULL, - /// Content BLOB NOT NULL - ///); - /// - ///CREATE TABLE IF NOT EXISTS PlexContent - ///( - /// Id INTEGER PRIMARY KEY AUTOINCREMENT, - /// Title varchar(50) NOT NULL, - /// ProviderId varchar(50) NOT NULL, - /// Url varchar(100) NOT NULL, - /// Key varchar(50) NOT NULL, - /// AddedAt varchar(50) NOT NULL, - /// Type INTEGER NOT NULL, - /// Relea [rest of string was truncated]";. - /// - public static string SqlTables { - get { - return ResourceManager.GetString("SqlTables", resourceCulture); - } - } - } -} diff --git a/src/Ombi.Store/Sql.resx b/src/Ombi.Store/Sql.resx deleted file mode 100644 index 08548bd87..000000000 --- a/src/Ombi.Store/Sql.resx +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - SqlTables.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - - \ No newline at end of file diff --git a/src/Ombi.Store/SqlTables.sql b/src/Ombi.Store/SqlTables.sql deleted file mode 100644 index 4c3cd80e4..000000000 --- a/src/Ombi.Store/SqlTables.sql +++ /dev/null @@ -1,175 +0,0 @@ -CREATE TABLE IF NOT EXISTS GlobalSettings -( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - SettingsName varchar(50) NOT NULL, - Content BLOB NOT NULL -); - -CREATE TABLE IF NOT EXISTS PlexContent -( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - Title varchar(50) NOT NULL, - ProviderId varchar(50) NOT NULL, - Url varchar(100) NOT NULL, - Key varchar(50) NOT NULL, - AddedAt varchar(50) NOT NULL, - Type INTEGER NOT NULL, - ReleaseYear varchar(100) NOT NULL -); - -CREATE TABLE IF NOT EXISTS RadarrCache -( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - TheMovieDbId INTEGER NOT NULL -); - -CREATE TABLE IF NOT EXISTS PlexSeasonsContent -( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - PlexContentId integer not null, - SeasonNumber INTEGER NOT NULL, - SeasonKey INTEGER NOT NULL, - ParentKey INTEGER NOT NULL - -); - -CREATE TABLE IF NOT EXISTS RequestBlobs -( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - ProviderId INTEGER NOT NULL, - Content BLOB NOT NULL, - Type INTEGER NOT NULL - -); - -CREATE TABLE IF NOT EXISTS Users -( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - Username VARCHAR(100) NOT NULL, - Alias VARCHAR(100) NULL, - ClaimsSerialized BLOB NOT NULL, - EmailAddress VARCHAR(100) NULL, - Password VARCHAR(100) NULL, - Salt BLOB NULL, - UserType INTEGER NOT NULL - -); - -CREATE TABLE IF NOT EXISTS RequestHistory -( - - Id INTEGER PRIMARY KEY AUTOINCREMENT, - Type INTEGER NOT NULL, - RequestedDate varchar(50) NOT NULL, - RequestId INTEGER NOT NULL - -); - -CREATE TABLE IF NOT EXISTS NotificationTemplates -( - - Id INTEGER PRIMARY KEY AUTOINCREMENT, - NotificationType INTEGER NOT NULL, - Agent INTEGER NOT NULL, - Subject BLOB NULL, - Message BLOB NULL, - Enabled INTEGER NOT NULL - -); - -CREATE TABLE IF NOT EXISTS MovieIssues -( - - Id INTEGER PRIMARY KEY AUTOINCREMENT, - Subject INTEGER NOT NULL, - Description INTEGER NOT NULL, - MovieId INTEGER NOT NULL, - - FOREIGN KEY (MovieId) REFERENCES MovieRequests(Id) -); - -CREATE TABLE IF NOT EXISTS TvIssues -( - - Id INTEGER PRIMARY KEY AUTOINCREMENT, - Subject INTEGER NOT NULL, - Description INTEGER NOT NULL, - ChildId INTEGER NOT NULL, - - FOREIGN KEY (ChildId) REFERENCES TvChildRequests(ChildId) -); - - -CREATE TABLE IF NOT EXISTS MovieRequests ( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - ImdbId VARCHAR(20) NOT NULL, - TheMovieDbId INTEGER NOT NULL, - Overview VARCHAR(100) NOT NULL, - Title VARCHAR(50) NOT NULL, - PosterPath VARCHAR(100) NOT NULL, - ReleaseDate VARCHAR(100) NOT NULL, - Status VARCHAR(100) NOT NULL, - Approved INTEGER NOT NULL, - Available INTEGER NOT NULL, - RequestedDate VARCHAR(100) NOT NULL, - RequestedUserId INTEGER NOT NULL, - IssueId INTEGER NULL, - Denied INTEGER NULL, - DeniedReason VARCHAR(100) NULL, - RequestType INTEGER NOT NULL, - - FOREIGN KEY (IssueId) REFERENCES MovieIssues(Id), - FOREIGN KEY (RequestedUserId) REFERENCES Users(Id) -); - -CREATE TABLE IF NOT EXISTS TvRequests ( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - ImdbId VARCHAR(20) NOT NULL, - TvDbId INTEGER NOT NULL, - Overview VARCHAR(100) NOT NULL, - Title VARCHAR(50) NOT NULL, - PosterPath VARCHAR(100) NOT NULL, - ReleaseDate VARCHAR(100) NOT NULL, - Status VARCHAR(100) NULL, - RootFolder INTEGER NULL -); - -CREATE TABLE IF NOT EXISTS ChildRequests ( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - Approved INTEGER NOT NULL, - Available INTEGER NOT NULL, - RequestedDate VARCHAR(100) NOT NULL, - RequestedUserId INTEGER NOT NULL, - IssueId INTEGER NULL, - Denied INTEGER NULL, - DeniedReason VARCHAR(100) NULL, - ParentRequestId INTEGER NOT NULL, - RequestType INTEGER NOT NULL, - - FOREIGN KEY (IssueId) REFERENCES TvIssues(Id), - FOREIGN KEY (ParentRequestId) REFERENCES TvRequests(Id), - FOREIGN KEY (RequestedUserId) REFERENCES Users(Id) -); - -CREATE TABLE IF NOT EXISTS SeasonRequests ( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - SeasonNumber INTEGER NOT NULL, - ChildRequestId INTEGER NOT NULL, - - FOREIGN KEY (ChildRequestId) REFERENCES ChildRequests(Id) -); - -CREATE TABLE IF NOT EXISTS EpisodeRequests ( - Id INTEGER PRIMARY KEY AUTOINCREMENT, - EpisodeNumber INTEGER NOT NULL, - Title VARCHAR(100) NOT NULL, - AirDate VARCHAR(100) NOT NULL, - Url VARCHAR(100) NOT NULL, - SeasonId INTEGER NOT NULL, - Available INTEGER NOT NULL, - Requested INTEGER NOT NULL, - Approved INTEGER NOT NULL, - - - FOREIGN KEY (SeasonId) REFERENCES SeasonRequests(Id) -); diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index 1926fcf4c..fce4d15fa 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -31,6 +31,7 @@ namespace Ombi.Controllers /// /// The resolver. /// The mapper. + /// The templateRepo. public SettingsController(ISettingsResolver resolver, IMapper mapper, INotificationTemplatesRepository templateRepo) { SettingsResolver = resolver; diff --git a/src/Ombi/Ombi.csproj b/src/Ombi/Ombi.csproj index dd0ecf234..d8ef4e8c4 100644 --- a/src/Ombi/Ombi.csproj +++ b/src/Ombi/Ombi.csproj @@ -10,6 +10,7 @@ bin\Debug\netcoreapp1.1\Swagger.xml + 1701;1702;1705;1591;