From 9e0caf34d662fff8e7216757ce0208d0cfd2d40f Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Thu, 2 Sep 2021 15:26:20 -0400 Subject: [PATCH] Rename db table Library => LibraryBooks --- ApplicationServices/LibraryCommands.cs | 2 +- DataLayer/LibationContext.cs | 2 +- ...10902192153_RenameLibraryBooks.Designer.cs | 390 ++++++++++++++++++ .../20210902192153_RenameLibraryBooks.cs | 63 +++ .../LibationContextModelSnapshot.cs | 2 +- DataLayer/QueryObjects/LibraryQueries.cs | 4 +- DtoImporterService/LibraryImporter.cs | 6 +- 7 files changed, 461 insertions(+), 8 deletions(-) create mode 100644 DataLayer/Migrations/20210902192153_RenameLibraryBooks.Designer.cs create mode 100644 DataLayer/Migrations/20210902192153_RenameLibraryBooks.cs diff --git a/ApplicationServices/LibraryCommands.cs b/ApplicationServices/LibraryCommands.cs index 683559da..b0ad1de9 100644 --- a/ApplicationServices/LibraryCommands.cs +++ b/ApplicationServices/LibraryCommands.cs @@ -162,7 +162,7 @@ namespace ApplicationServices var libBooks = context.GetLibrary_Flat_NoTracking(); var removeLibraryBooks = libBooks.Where(lb => idsToRemove.Contains(lb.Book.AudibleProductId)).ToList(); - context.Library.RemoveRange(removeLibraryBooks); + context.LibraryBooks.RemoveRange(removeLibraryBooks); var qtyChanges = context.SaveChanges(); if (qtyChanges > 0) diff --git a/DataLayer/LibationContext.cs b/DataLayer/LibationContext.cs index db80bfce..7b27ba9d 100644 --- a/DataLayer/LibationContext.cs +++ b/DataLayer/LibationContext.cs @@ -19,7 +19,7 @@ namespace DataLayer // // overwrite collection // Entry(product).Collection(x => x.Narrators).Load(); // product.Narrators = narrators; - public DbSet Library { get; private set; } + public DbSet LibraryBooks { get; private set; } public DbSet Books { get; private set; } public DbSet Contributors { get; private set; } public DbSet Series { get; private set; } diff --git a/DataLayer/Migrations/20210902192153_RenameLibraryBooks.Designer.cs b/DataLayer/Migrations/20210902192153_RenameLibraryBooks.Designer.cs new file mode 100644 index 00000000..72d7ad3a --- /dev/null +++ b/DataLayer/Migrations/20210902192153_RenameLibraryBooks.Designer.cs @@ -0,0 +1,390 @@ +// +using System; +using DataLayer; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace DataLayer.Migrations +{ + [DbContext(typeof(LibationContext))] + [Migration("20210902192153_RenameLibraryBooks")] + partial class RenameLibraryBooks + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.9"); + + modelBuilder.Entity("DataLayer.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AudibleProductId") + .HasColumnType("TEXT"); + + b.Property("CategoryId") + .HasColumnType("INTEGER"); + + b.Property("ContentType") + .HasColumnType("INTEGER"); + + b.Property("DatePublished") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("IsAbridged") + .HasColumnType("INTEGER"); + + b.Property("LengthInMinutes") + .HasColumnType("INTEGER"); + + b.Property("Locale") + .HasColumnType("TEXT"); + + b.Property("PictureId") + .HasColumnType("TEXT"); + + b.Property("Title") + .HasColumnType("TEXT"); + + b.HasKey("BookId"); + + b.HasIndex("AudibleProductId"); + + b.HasIndex("CategoryId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("DataLayer.BookContributor", b => + { + b.Property("BookId") + .HasColumnType("INTEGER"); + + b.Property("ContributorId") + .HasColumnType("INTEGER"); + + b.Property("Role") + .HasColumnType("INTEGER"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.HasKey("BookId", "ContributorId", "Role"); + + b.HasIndex("BookId"); + + b.HasIndex("ContributorId"); + + b.ToTable("BookContributor"); + }); + + modelBuilder.Entity("DataLayer.Category", b => + { + b.Property("CategoryId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AudibleCategoryId") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("ParentCategoryCategoryId") + .HasColumnType("INTEGER"); + + b.HasKey("CategoryId"); + + b.HasIndex("AudibleCategoryId"); + + b.HasIndex("ParentCategoryCategoryId"); + + b.ToTable("Categories"); + + b.HasData( + new + { + CategoryId = -1, + AudibleCategoryId = "", + Name = "" + }); + }); + + modelBuilder.Entity("DataLayer.Contributor", b => + { + b.Property("ContributorId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AudibleContributorId") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("ContributorId"); + + b.HasIndex("Name"); + + b.ToTable("Contributors"); + + b.HasData( + new + { + ContributorId = -1, + Name = "" + }); + }); + + modelBuilder.Entity("DataLayer.LibraryBook", b => + { + b.Property("BookId") + .HasColumnType("INTEGER"); + + b.Property("Account") + .HasColumnType("TEXT"); + + b.Property("DateAdded") + .HasColumnType("TEXT"); + + b.HasKey("BookId"); + + b.ToTable("LibraryBooks"); + }); + + modelBuilder.Entity("DataLayer.Series", b => + { + b.Property("SeriesId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AudibleSeriesId") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("SeriesId"); + + b.HasIndex("AudibleSeriesId"); + + b.ToTable("Series"); + }); + + modelBuilder.Entity("DataLayer.SeriesBook", b => + { + b.Property("SeriesId") + .HasColumnType("INTEGER"); + + b.Property("BookId") + .HasColumnType("INTEGER"); + + b.Property("Index") + .HasColumnType("REAL"); + + b.HasKey("SeriesId", "BookId"); + + b.HasIndex("BookId"); + + b.HasIndex("SeriesId"); + + b.ToTable("SeriesBook"); + }); + + modelBuilder.Entity("DataLayer.Book", b => + { + b.HasOne("DataLayer.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("DataLayer.Rating", "Rating", b1 => + { + b1.Property("BookId") + .HasColumnType("INTEGER"); + + b1.Property("OverallRating") + .HasColumnType("REAL"); + + b1.Property("PerformanceRating") + .HasColumnType("REAL"); + + b1.Property("StoryRating") + .HasColumnType("REAL"); + + b1.HasKey("BookId"); + + b1.ToTable("Books"); + + b1.WithOwner() + .HasForeignKey("BookId"); + }); + + b.OwnsMany("DataLayer.Supplement", "Supplements", b1 => + { + b1.Property("SupplementId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b1.Property("BookId") + .HasColumnType("INTEGER"); + + b1.Property("Url") + .HasColumnType("TEXT"); + + b1.HasKey("SupplementId"); + + b1.HasIndex("BookId"); + + b1.ToTable("Supplement"); + + b1.WithOwner("Book") + .HasForeignKey("BookId"); + + b1.Navigation("Book"); + }); + + b.OwnsOne("DataLayer.UserDefinedItem", "UserDefinedItem", b1 => + { + b1.Property("BookId") + .HasColumnType("INTEGER"); + + b1.Property("BookStatus") + .HasColumnType("INTEGER"); + + b1.Property("PdfStatus") + .HasColumnType("INTEGER"); + + b1.Property("Tags") + .HasColumnType("TEXT"); + + b1.HasKey("BookId"); + + b1.ToTable("UserDefinedItem"); + + b1.WithOwner("Book") + .HasForeignKey("BookId"); + + b1.OwnsOne("DataLayer.Rating", "Rating", b2 => + { + b2.Property("UserDefinedItemBookId") + .HasColumnType("INTEGER"); + + b2.Property("OverallRating") + .HasColumnType("REAL"); + + b2.Property("PerformanceRating") + .HasColumnType("REAL"); + + b2.Property("StoryRating") + .HasColumnType("REAL"); + + b2.HasKey("UserDefinedItemBookId"); + + b2.ToTable("UserDefinedItem"); + + b2.WithOwner() + .HasForeignKey("UserDefinedItemBookId"); + }); + + b1.Navigation("Book"); + + b1.Navigation("Rating"); + }); + + b.Navigation("Category"); + + b.Navigation("Rating"); + + b.Navigation("Supplements"); + + b.Navigation("UserDefinedItem"); + }); + + modelBuilder.Entity("DataLayer.BookContributor", b => + { + b.HasOne("DataLayer.Book", "Book") + .WithMany("ContributorsLink") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DataLayer.Contributor", "Contributor") + .WithMany("BooksLink") + .HasForeignKey("ContributorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Book"); + + b.Navigation("Contributor"); + }); + + modelBuilder.Entity("DataLayer.Category", b => + { + b.HasOne("DataLayer.Category", "ParentCategory") + .WithMany() + .HasForeignKey("ParentCategoryCategoryId"); + + b.Navigation("ParentCategory"); + }); + + modelBuilder.Entity("DataLayer.LibraryBook", b => + { + b.HasOne("DataLayer.Book", "Book") + .WithOne() + .HasForeignKey("DataLayer.LibraryBook", "BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Book"); + }); + + modelBuilder.Entity("DataLayer.SeriesBook", b => + { + b.HasOne("DataLayer.Book", "Book") + .WithMany("SeriesLink") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DataLayer.Series", "Series") + .WithMany("BooksLink") + .HasForeignKey("SeriesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Book"); + + b.Navigation("Series"); + }); + + modelBuilder.Entity("DataLayer.Book", b => + { + b.Navigation("ContributorsLink"); + + b.Navigation("SeriesLink"); + }); + + modelBuilder.Entity("DataLayer.Contributor", b => + { + b.Navigation("BooksLink"); + }); + + modelBuilder.Entity("DataLayer.Series", b => + { + b.Navigation("BooksLink"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DataLayer/Migrations/20210902192153_RenameLibraryBooks.cs b/DataLayer/Migrations/20210902192153_RenameLibraryBooks.cs new file mode 100644 index 00000000..df8e28fd --- /dev/null +++ b/DataLayer/Migrations/20210902192153_RenameLibraryBooks.cs @@ -0,0 +1,63 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DataLayer.Migrations +{ + public partial class RenameLibraryBooks : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Library_Books_BookId", + table: "Library"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Library", + table: "Library"); + + migrationBuilder.RenameTable( + name: "Library", + newName: "LibraryBooks"); + + migrationBuilder.AddPrimaryKey( + name: "PK_LibraryBooks", + table: "LibraryBooks", + column: "BookId"); + + migrationBuilder.AddForeignKey( + name: "FK_LibraryBooks_Books_BookId", + table: "LibraryBooks", + column: "BookId", + principalTable: "Books", + principalColumn: "BookId", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_LibraryBooks_Books_BookId", + table: "LibraryBooks"); + + migrationBuilder.DropPrimaryKey( + name: "PK_LibraryBooks", + table: "LibraryBooks"); + + migrationBuilder.RenameTable( + name: "LibraryBooks", + newName: "Library"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Library", + table: "Library", + column: "BookId"); + + migrationBuilder.AddForeignKey( + name: "FK_Library_Books_BookId", + table: "Library", + column: "BookId", + principalTable: "Books", + principalColumn: "BookId", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/DataLayer/Migrations/LibationContextModelSnapshot.cs b/DataLayer/Migrations/LibationContextModelSnapshot.cs index ffe5b201..4fde45e5 100644 --- a/DataLayer/Migrations/LibationContextModelSnapshot.cs +++ b/DataLayer/Migrations/LibationContextModelSnapshot.cs @@ -155,7 +155,7 @@ namespace DataLayer.Migrations b.HasKey("BookId"); - b.ToTable("Library"); + b.ToTable("LibraryBooks"); }); modelBuilder.Entity("DataLayer.Series", b => diff --git a/DataLayer/QueryObjects/LibraryQueries.cs b/DataLayer/QueryObjects/LibraryQueries.cs index 269ef0a5..573c282d 100644 --- a/DataLayer/QueryObjects/LibraryQueries.cs +++ b/DataLayer/QueryObjects/LibraryQueries.cs @@ -17,14 +17,14 @@ namespace DataLayer public static List GetLibrary_Flat_NoTracking(this LibationContext context) => context - .Library + .LibraryBooks .AsNoTrackingWithIdentityResolution() .GetLibrary() .ToList(); public static LibraryBook GetLibraryBook_Flat_NoTracking(this LibationContext context, string productId) => context - .Library + .LibraryBooks .AsNoTrackingWithIdentityResolution() .GetLibraryBook(productId); diff --git a/DtoImporterService/LibraryImporter.cs b/DtoImporterService/LibraryImporter.cs index bbf78ec5..30e586ae 100644 --- a/DtoImporterService/LibraryImporter.cs +++ b/DtoImporterService/LibraryImporter.cs @@ -34,7 +34,7 @@ namespace DtoImporterService // // CURRENT SOLUTION: don't re-insert - var currentLibraryProductIds = DbContext.Library.Select(l => l.Book.AudibleProductId).ToList(); + var currentLibraryProductIds = DbContext.LibraryBooks.Select(l => l.Book.AudibleProductId).ToList(); var newItems = importItems.Where(dto => !currentLibraryProductIds.Contains(dto.DtoItem.ProductId)).ToList(); foreach (var newItem in newItems) @@ -43,11 +43,11 @@ namespace DtoImporterService DbContext.Books.Local.Single(b => b.AudibleProductId == newItem.DtoItem.ProductId), newItem.DtoItem.DateAdded, newItem.AccountId); - DbContext.Library.Add(libraryBook); + DbContext.LibraryBooks.Add(libraryBook); } // needed for v3 => v4 upgrade - var toUpdate = DbContext.Library.Where(l => l.Account == null); + var toUpdate = DbContext.LibraryBooks.Where(l => l.Account == null); foreach (var u in toUpdate) { var item = importItems.FirstOrDefault(ii => ii.DtoItem.ProductId == u.Book.AudibleProductId);