Implements Data Access Layer

This commit is contained in:
BinaryAlley committed 2024-08-26 23:32:29 +03:00
1 parent b69e59a3d8
commit 8b729cc16c
24 files changed
+1721 -9

No files matched your search

@@ -0,0 +1,181 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Models.Books;
using Lumina.Application.Common.Models.Common;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
#endregion
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="BookDto"/> aggregate root.
/// </summary>
public class BookConfiguration : IEntityTypeConfiguration<BookDto>
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Configures the <see cref="Book"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<BookDto> builder)
{
builder.ToTable("Books");
builder.HasKey(book => book.Id);
builder.Property(book => book.Id)
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
.HasColumnOrder(0);
builder.Property(book => book.Title).IsRequired().HasMaxLength(255).HasColumnOrder(1);
builder.Property(book => book.OriginalTitle).HasMaxLength(255).HasColumnOrder(2);
builder.Property(book => book.Description).HasMaxLength(2000).HasColumnOrder(3);
builder.Property(book => book.OriginalReleaseDate).HasColumnOrder(4);
builder.Property(book => book.OriginalReleaseYear).HasColumnOrder(5);
builder.Property(book => book.ReReleaseDate).HasColumnOrder(6);
builder.Property(book => book.ReReleaseYear).HasColumnOrder(7);
builder.Property(book => book.ReleaseCountry).HasColumnOrder(8);
builder.Property(book => book.ReleaseVersion).HasColumnOrder(9);
builder.Property(book => book.LanguageCode).HasColumnOrder(10);
builder.Property(book => book.LanguageName).HasColumnOrder(11);
builder.Property(book => book.LanguageNativeName).HasColumnOrder(12);
builder.Property(book => book.OriginalLanguageCode).HasColumnOrder(13);
builder.Property(book => book.OriginalLanguageName).HasColumnOrder(14);
builder.Property(book => book.OriginalLanguageNativeName).HasColumnOrder(15);
// since Tag is a Domain ValueObject (no identity), we need to configure it as a many-to-many relationship
builder.HasMany(book => book.Tags)
.WithMany()
.UsingEntity<Dictionary<string, object>>(
"BookTags",
j => j.HasOne<TagDto>().WithMany().HasForeignKey("TagId"),
j => j.HasOne<BookDto>().WithMany().HasForeignKey("BookId"),
j =>
{
j.HasKey("BookId", "TagId");
j.ToTable("BookTags");
});
builder.HasMany(book => book.Genres)
.WithMany()
.UsingEntity<Dictionary<string, object>>(
"BookGenres",
j => j.HasOne<GenreDto>().WithMany().HasForeignKey("GenreId"),
j => j.HasOne<BookDto>().WithMany().HasForeignKey("BookId"),
j =>
{
j.HasKey("BookId", "GenreId");
j.ToTable("BookGenres");
});
builder.Property(book => book.Publisher).HasMaxLength(100).HasColumnOrder(16);
builder.Property(book => book.PageCount).HasColumnOrder(17);
builder.Property(book => book.Format).HasColumnOrder(18);
builder.Property(book => book.Edition).HasMaxLength(50).HasColumnOrder(19);
builder.Property(book => book.VolumeNumber).HasColumnOrder(20);
builder.Property(book => book.ASIN).HasMaxLength(10).HasColumnOrder(21);
builder.Property(book => book.GoodreadsId).HasColumnOrder(22);
builder.Property(book => book.LCCN).HasColumnOrder(23);
builder.Property(book => book.OCLCNumber).HasColumnOrder(24);
builder.Property(book => book.OpenLibraryId).HasMaxLength(50).HasColumnOrder(25);
builder.Property(book => book.LibraryThingId).HasMaxLength(50).HasColumnOrder(26);
builder.Property(book => book.GoogleBooksId).HasMaxLength(12).HasColumnOrder(27);
builder.Property(book => book.BarnesAndNobleId).HasMaxLength(10).HasColumnOrder(28);
builder.Property(book => book.AppleBooksId).HasColumnOrder(29);
builder.Property(book => book.Created).HasColumnOrder(30);
builder.Property(book => book.Updated).HasColumnOrder(31);
//builder.HasMany<ContributorIdDto>()
//.WithMany()
//.UsingEntity<Dictionary<string, object>>(
// "BookContributors",
// j => j.HasOne<ContributorIdDto>().WithMany().HasForeignKey("ContributorId"),
// j => j.HasOne<BookDto>().WithMany().HasForeignKey("BookId"),
// j =>
// {
// j.HasKey("BookId", "ContributorId");
// j.ToTable("BookContributors");
// });
//builder.OwnsMany(book => book.ContributorIds, ownedBuilder =>
//{
// ownedBuilder.ToTable("BookContributors");
// ownedBuilder.WithOwner().HasForeignKey("BookId");
// ownedBuilder.Property(c => c.Id)
// .HasColumnName("ContributorId")
// .HasColumnType("uniqueidentifier");
// ownedBuilder.HasKey("BookId", "Id"); // Use the actual property name 'Id' here
//});
builder.OwnsMany(book => book.Ratings, ratingBuilder =>
{
ratingBuilder.ToTable("BookRatings");
ratingBuilder.WithOwner().HasForeignKey("BookId");
ratingBuilder.Property<int>("Id").ValueGeneratedOnAdd();
ratingBuilder.HasKey("Id");
ratingBuilder.Property(r => r.Value)
.HasColumnType("decimal(3,2)")
.IsRequired();
ratingBuilder.Property(r => r.MaxValue)
.HasColumnType("decimal(3,2)")
.IsRequired();
ratingBuilder.Property(r => r.VoteCount)
.IsRequired(false);
ratingBuilder.Property(r => r.Source)
.HasConversion<string>()
.HasMaxLength(50)
.IsRequired();
});
builder.OwnsMany(book => book.ISBNs, isbnBuilder =>
{
isbnBuilder.ToTable("BookISBNs");
isbnBuilder.WithOwner().HasForeignKey("BookId");
isbnBuilder.Property<int>("Id").ValueGeneratedOnAdd();
isbnBuilder.HasKey("Id");
isbnBuilder.Property(isbn => isbn.Value)
.HasColumnName("ISBN")
.HasMaxLength(13)
.IsRequired();
isbnBuilder.Property(isbn => isbn.Format)
.HasConversion<string>()
.HasMaxLength(6)
.IsRequired();
});
}
#endregion
}
public class TagConfiguration : IEntityTypeConfiguration<TagDto>
{
public void Configure(EntityTypeBuilder<TagDto> builder)
{
builder.ToTable("Tags");
builder.HasKey(t => t.Name);
builder.Property(t => t.Name).IsRequired().HasMaxLength(50);
}
}
public class GenreConfiguration : IEntityTypeConfiguration<GenreDto>
{
public void Configure(EntityTypeBuilder<GenreDto> builder)
{
builder.ToTable("Genres");
builder.HasKey(g => g.Name);
builder.Property(g => g.Name).IsRequired().HasMaxLength(50);
}
}
//public class ContributorConfiguration : IEntityTypeConfiguration<ContributorIdDto>
//{
// public void Configure(EntityTypeBuilder<ContributorIdDto> builder)
// {
// builder.ToTable("Contributors");
// builder.HasKey(c => c.Id);
// builder.Property(c => c.Id).ValueGeneratedNever();
// }
//}
@@ -0,0 +1,58 @@
#region ========================================================================= USING =====================================================================================
using Lumina.DataAccess.Core.UoW;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using System.Reflection;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.DataAccess.Core.Repositories.Common.Factory;
using Lumina.Application.Common.DataAccess.UoW;
#endregion
namespace Lumina.DataAccess.Common.DependencyInjection;
/// <summary>
/// Contains all services of the DataAccess layer.
/// </summary>
public static class DataAccessLayerServices
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Extension method for adding the DataAccess layer services to the DI container.
/// </summary>
/// <param name="services">The service collection to add the services to.</param>
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
public static void AddDataAccessLayerServices(this IServiceCollection services)
{
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (!Directory.Exists(basePath))
throw new DirectoryNotFoundException($"The base path '{basePath}' does not exist.");
services.AddDbContext<LuminaDbContext>(options =>
{
options.UseSqlite($"Data Source={Path.Combine(basePath, "Lumina.db")}");
});
services.AddScoped<IUnitOfWork, UnitOfWork>();
Type[]? dataAccessLayerTypes = Assembly.GetExecutingAssembly().GetTypes();
Type? genericRepositoryType = typeof(IRepository<>);
Type? repositoryFactoryType = typeof(RepositoryFactory);
Type? iRepositoryFactoryType = typeof(IRepositoryFactory);
services.AddScoped(iRepositoryFactoryType!, repositoryFactoryType!);
// get all classes implementing IRepository (all repository classes) and register them as their corresponding repository interface
IEnumerable<Type> repositoryTypes = dataAccessLayerTypes.Where(t => !t.IsInterface &&
t.GetInterfaces()
.Any(i => i.IsGenericType &&
i.GetGenericTypeDefinition() == genericRepositoryType));
foreach (Type type in repositoryTypes)
{
services.AddScoped(type.GetInterfaces() // TODO: change to scoped when DbContext is implemented
.Where(i => !i.IsGenericType &&
i.GetInterfaces()
.Any(j => j.GetGenericTypeDefinition() == genericRepositoryType))
.First(), type);
}
}
#endregion
}
@@ -0,0 +1,324 @@
// <auto-generated />
using System;
using Lumina.DataAccess.Core.UoW;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Lumina.DataAccess.Common.Migrations
{
[DbContext(typeof(LuminaDbContext))]
[Migration("20240826201057_InitialMigration")]
partial class InitialMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.8");
modelBuilder.Entity("BookGenres", b =>
{
b.Property<Guid>("BookId")
.HasColumnType("TEXT");
b.Property<string>("GenreId")
.HasColumnType("TEXT");
b.HasKey("BookId", "GenreId");
b.HasIndex("GenreId");
b.ToTable("BookGenres", (string)null);
});
modelBuilder.Entity("BookTags", b =>
{
b.Property<Guid>("BookId")
.HasColumnType("TEXT");
b.Property<string>("TagId")
.HasColumnType("TEXT");
b.HasKey("BookId", "TagId");
b.HasIndex("TagId");
b.ToTable("BookTags", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
{
b.Property<Guid>("Id")
.HasColumnType("TEXT")
.HasColumnOrder(0);
b.Property<string>("ASIN")
.HasMaxLength(10)
.HasColumnType("TEXT")
.HasColumnOrder(21);
b.Property<string>("AppleBooksId")
.HasColumnType("TEXT")
.HasColumnOrder(29);
b.Property<string>("BarnesAndNobleId")
.HasMaxLength(10)
.HasColumnType("TEXT")
.HasColumnOrder(28);
b.Property<DateTime>("Created")
.HasColumnType("TEXT")
.HasColumnOrder(30);
b.Property<string>("Description")
.HasMaxLength(2000)
.HasColumnType("TEXT")
.HasColumnOrder(3);
b.Property<string>("Edition")
.HasMaxLength(50)
.HasColumnType("TEXT")
.HasColumnOrder(19);
b.Property<string>("Format")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnOrder(18);
b.Property<string>("GoodreadsId")
.HasColumnType("TEXT")
.HasColumnOrder(22);
b.Property<string>("GoogleBooksId")
.HasMaxLength(12)
.HasColumnType("TEXT")
.HasColumnOrder(27);
b.Property<string>("LCCN")
.HasColumnType("TEXT")
.HasColumnOrder(23);
b.Property<string>("LanguageCode")
.HasColumnType("TEXT")
.HasColumnOrder(10);
b.Property<string>("LanguageName")
.HasColumnType("TEXT")
.HasColumnOrder(11);
b.Property<string>("LanguageNativeName")
.HasColumnType("TEXT")
.HasColumnOrder(12);
b.Property<string>("LibraryThingId")
.HasMaxLength(50)
.HasColumnType("TEXT")
.HasColumnOrder(26);
b.Property<string>("OCLCNumber")
.HasColumnType("TEXT")
.HasColumnOrder(24);
b.Property<string>("OpenLibraryId")
.HasMaxLength(50)
.HasColumnType("TEXT")
.HasColumnOrder(25);
b.Property<string>("OriginalLanguageCode")
.HasColumnType("TEXT")
.HasColumnOrder(13);
b.Property<string>("OriginalLanguageName")
.HasColumnType("TEXT")
.HasColumnOrder(14);
b.Property<string>("OriginalLanguageNativeName")
.HasColumnType("TEXT")
.HasColumnOrder(15);
b.Property<DateOnly?>("OriginalReleaseDate")
.HasColumnType("TEXT")
.HasColumnOrder(4);
b.Property<int?>("OriginalReleaseYear")
.HasColumnType("INTEGER")
.HasColumnOrder(5);
b.Property<string>("OriginalTitle")
.HasMaxLength(255)
.HasColumnType("TEXT")
.HasColumnOrder(2);
b.Property<int?>("PageCount")
.HasColumnType("INTEGER")
.HasColumnOrder(17);
b.Property<string>("Publisher")
.HasMaxLength(100)
.HasColumnType("TEXT")
.HasColumnOrder(16);
b.Property<DateOnly?>("ReReleaseDate")
.HasColumnType("TEXT")
.HasColumnOrder(6);
b.Property<int?>("ReReleaseYear")
.HasColumnType("INTEGER")
.HasColumnOrder(7);
b.Property<string>("ReleaseCountry")
.HasColumnType("TEXT")
.HasColumnOrder(8);
b.Property<string>("ReleaseVersion")
.HasColumnType("TEXT")
.HasColumnOrder(9);
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT")
.HasColumnOrder(1);
b.Property<DateTime?>("Updated")
.HasColumnType("TEXT")
.HasColumnOrder(31);
b.Property<int?>("VolumeNumber")
.HasColumnType("INTEGER")
.HasColumnOrder(20);
b.HasKey("Id");
b.ToTable("Books", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreDto", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Genres", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagDto", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Tags", (string)null);
});
modelBuilder.Entity("BookGenres", b =>
{
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Lumina.Application.Common.Models.Common.GenreDto", null)
.WithMany()
.HasForeignKey("GenreId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("BookTags", b =>
{
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Lumina.Application.Common.Models.Common.TagDto", null)
.WithMany()
.HasForeignKey("TagId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
{
b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingDto", "Ratings", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b1.Property<Guid>("BookId")
.HasColumnType("TEXT");
b1.Property<decimal>("MaxValue")
.HasColumnType("decimal(3,2)");
b1.Property<string>("Source")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b1.Property<decimal>("Value")
.HasColumnType("decimal(3,2)");
b1.Property<int?>("VoteCount")
.HasColumnType("INTEGER");
b1.HasKey("Id");
b1.HasIndex("BookId");
b1.ToTable("BookRatings", (string)null);
b1.WithOwner()
.HasForeignKey("BookId");
});
b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnDto", "ISBNs", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b1.Property<Guid>("BookId")
.HasColumnType("TEXT");
b1.Property<string>("Format")
.IsRequired()
.HasMaxLength(6)
.HasColumnType("TEXT");
b1.Property<string>("Value")
.IsRequired()
.HasMaxLength(13)
.HasColumnType("TEXT")
.HasColumnName("ISBN");
b1.HasKey("Id");
b1.HasIndex("BookId");
b1.ToTable("BookISBNs", (string)null);
b1.WithOwner()
.HasForeignKey("BookId");
});
b.Navigation("ISBNs");
b.Navigation("Ratings");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,216 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Lumina.DataAccess.Common.Migrations
{
/// <inheritdoc />
public partial class InitialMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Books",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Title = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
OriginalTitle = table.Column<string>(type: "TEXT", maxLength: 255, nullable: true),
Description = table.Column<string>(type: "TEXT", maxLength: 2000, nullable: true),
OriginalReleaseDate = table.Column<DateOnly>(type: "TEXT", nullable: true),
OriginalReleaseYear = table.Column<int>(type: "INTEGER", nullable: true),
ReReleaseDate = table.Column<DateOnly>(type: "TEXT", nullable: true),
ReReleaseYear = table.Column<int>(type: "INTEGER", nullable: true),
ReleaseCountry = table.Column<string>(type: "TEXT", nullable: true),
ReleaseVersion = table.Column<string>(type: "TEXT", nullable: true),
LanguageCode = table.Column<string>(type: "TEXT", nullable: true),
LanguageName = table.Column<string>(type: "TEXT", nullable: true),
LanguageNativeName = table.Column<string>(type: "TEXT", nullable: true),
OriginalLanguageCode = table.Column<string>(type: "TEXT", nullable: true),
OriginalLanguageName = table.Column<string>(type: "TEXT", nullable: true),
OriginalLanguageNativeName = table.Column<string>(type: "TEXT", nullable: true),
Publisher = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
PageCount = table.Column<int>(type: "INTEGER", nullable: true),
Format = table.Column<string>(type: "TEXT", nullable: false),
Edition = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
VolumeNumber = table.Column<int>(type: "INTEGER", nullable: true),
ASIN = table.Column<string>(type: "TEXT", maxLength: 10, nullable: true),
GoodreadsId = table.Column<string>(type: "TEXT", nullable: true),
LCCN = table.Column<string>(type: "TEXT", nullable: true),
OCLCNumber = table.Column<string>(type: "TEXT", nullable: true),
OpenLibraryId = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
LibraryThingId = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
GoogleBooksId = table.Column<string>(type: "TEXT", maxLength: 12, nullable: true),
BarnesAndNobleId = table.Column<string>(type: "TEXT", maxLength: 10, nullable: true),
AppleBooksId = table.Column<string>(type: "TEXT", nullable: true),
Created = table.Column<DateTime>(type: "TEXT", nullable: false),
Updated = table.Column<DateTime>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Books", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Genres",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Genres", x => x.Name);
});
migrationBuilder.CreateTable(
name: "Tags",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tags", x => x.Name);
});
migrationBuilder.CreateTable(
name: "BookISBNs",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
ISBN = table.Column<string>(type: "TEXT", maxLength: 13, nullable: false),
Format = table.Column<string>(type: "TEXT", maxLength: 6, nullable: false),
BookId = table.Column<Guid>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BookISBNs", x => x.Id);
table.ForeignKey(
name: "FK_BookISBNs_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "BookRatings",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Source = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
BookId = table.Column<Guid>(type: "TEXT", nullable: false),
Value = table.Column<decimal>(type: "decimal(3,2)", nullable: false),
MaxValue = table.Column<decimal>(type: "decimal(3,2)", nullable: false),
VoteCount = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_BookRatings", x => x.Id);
table.ForeignKey(
name: "FK_BookRatings_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "BookGenres",
columns: table => new
{
BookId = table.Column<Guid>(type: "TEXT", nullable: false),
GenreId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BookGenres", x => new { x.BookId, x.GenreId });
table.ForeignKey(
name: "FK_BookGenres_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_BookGenres_Genres_GenreId",
column: x => x.GenreId,
principalTable: "Genres",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "BookTags",
columns: table => new
{
BookId = table.Column<Guid>(type: "TEXT", nullable: false),
TagId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BookTags", x => new { x.BookId, x.TagId });
table.ForeignKey(
name: "FK_BookTags_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_BookTags_Tags_TagId",
column: x => x.TagId,
principalTable: "Tags",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_BookGenres_GenreId",
table: "BookGenres",
column: "GenreId");
migrationBuilder.CreateIndex(
name: "IX_BookISBNs_BookId",
table: "BookISBNs",
column: "BookId");
migrationBuilder.CreateIndex(
name: "IX_BookRatings_BookId",
table: "BookRatings",
column: "BookId");
migrationBuilder.CreateIndex(
name: "IX_BookTags_TagId",
table: "BookTags",
column: "TagId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BookGenres");
migrationBuilder.DropTable(
name: "BookISBNs");
migrationBuilder.DropTable(
name: "BookRatings");
migrationBuilder.DropTable(
name: "BookTags");
migrationBuilder.DropTable(
name: "Genres");
migrationBuilder.DropTable(
name: "Books");
migrationBuilder.DropTable(
name: "Tags");
}
}
}
@@ -0,0 +1,321 @@
// <auto-generated />
using System;
using Lumina.DataAccess.Core.UoW;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Lumina.DataAccess.Common.Migrations
{
[DbContext(typeof(LuminaDbContext))]
partial class LuminaDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.8");
modelBuilder.Entity("BookGenres", b =>
{
b.Property<Guid>("BookId")
.HasColumnType("TEXT");
b.Property<string>("GenreId")
.HasColumnType("TEXT");
b.HasKey("BookId", "GenreId");
b.HasIndex("GenreId");
b.ToTable("BookGenres", (string)null);
});
modelBuilder.Entity("BookTags", b =>
{
b.Property<Guid>("BookId")
.HasColumnType("TEXT");
b.Property<string>("TagId")
.HasColumnType("TEXT");
b.HasKey("BookId", "TagId");
b.HasIndex("TagId");
b.ToTable("BookTags", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
{
b.Property<Guid>("Id")
.HasColumnType("TEXT")
.HasColumnOrder(0);
b.Property<string>("ASIN")
.HasMaxLength(10)
.HasColumnType("TEXT")
.HasColumnOrder(21);
b.Property<string>("AppleBooksId")
.HasColumnType("TEXT")
.HasColumnOrder(29);
b.Property<string>("BarnesAndNobleId")
.HasMaxLength(10)
.HasColumnType("TEXT")
.HasColumnOrder(28);
b.Property<DateTime>("Created")
.HasColumnType("TEXT")
.HasColumnOrder(30);
b.Property<string>("Description")
.HasMaxLength(2000)
.HasColumnType("TEXT")
.HasColumnOrder(3);
b.Property<string>("Edition")
.HasMaxLength(50)
.HasColumnType("TEXT")
.HasColumnOrder(19);
b.Property<string>("Format")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnOrder(18);
b.Property<string>("GoodreadsId")
.HasColumnType("TEXT")
.HasColumnOrder(22);
b.Property<string>("GoogleBooksId")
.HasMaxLength(12)
.HasColumnType("TEXT")
.HasColumnOrder(27);
b.Property<string>("LCCN")
.HasColumnType("TEXT")
.HasColumnOrder(23);
b.Property<string>("LanguageCode")
.HasColumnType("TEXT")
.HasColumnOrder(10);
b.Property<string>("LanguageName")
.HasColumnType("TEXT")
.HasColumnOrder(11);
b.Property<string>("LanguageNativeName")
.HasColumnType("TEXT")
.HasColumnOrder(12);
b.Property<string>("LibraryThingId")
.HasMaxLength(50)
.HasColumnType("TEXT")
.HasColumnOrder(26);
b.Property<string>("OCLCNumber")
.HasColumnType("TEXT")
.HasColumnOrder(24);
b.Property<string>("OpenLibraryId")
.HasMaxLength(50)
.HasColumnType("TEXT")
.HasColumnOrder(25);
b.Property<string>("OriginalLanguageCode")
.HasColumnType("TEXT")
.HasColumnOrder(13);
b.Property<string>("OriginalLanguageName")
.HasColumnType("TEXT")
.HasColumnOrder(14);
b.Property<string>("OriginalLanguageNativeName")
.HasColumnType("TEXT")
.HasColumnOrder(15);
b.Property<DateOnly?>("OriginalReleaseDate")
.HasColumnType("TEXT")
.HasColumnOrder(4);
b.Property<int?>("OriginalReleaseYear")
.HasColumnType("INTEGER")
.HasColumnOrder(5);
b.Property<string>("OriginalTitle")
.HasMaxLength(255)
.HasColumnType("TEXT")
.HasColumnOrder(2);
b.Property<int?>("PageCount")
.HasColumnType("INTEGER")
.HasColumnOrder(17);
b.Property<string>("Publisher")
.HasMaxLength(100)
.HasColumnType("TEXT")
.HasColumnOrder(16);
b.Property<DateOnly?>("ReReleaseDate")
.HasColumnType("TEXT")
.HasColumnOrder(6);
b.Property<int?>("ReReleaseYear")
.HasColumnType("INTEGER")
.HasColumnOrder(7);
b.Property<string>("ReleaseCountry")
.HasColumnType("TEXT")
.HasColumnOrder(8);
b.Property<string>("ReleaseVersion")
.HasColumnType("TEXT")
.HasColumnOrder(9);
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT")
.HasColumnOrder(1);
b.Property<DateTime?>("Updated")
.HasColumnType("TEXT")
.HasColumnOrder(31);
b.Property<int?>("VolumeNumber")
.HasColumnType("INTEGER")
.HasColumnOrder(20);
b.HasKey("Id");
b.ToTable("Books", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreDto", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Genres", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagDto", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Tags", (string)null);
});
modelBuilder.Entity("BookGenres", b =>
{
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Lumina.Application.Common.Models.Common.GenreDto", null)
.WithMany()
.HasForeignKey("GenreId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("BookTags", b =>
{
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Lumina.Application.Common.Models.Common.TagDto", null)
.WithMany()
.HasForeignKey("TagId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
{
b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingDto", "Ratings", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b1.Property<Guid>("BookId")
.HasColumnType("TEXT");
b1.Property<decimal>("MaxValue")
.HasColumnType("decimal(3,2)");
b1.Property<string>("Source")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b1.Property<decimal>("Value")
.HasColumnType("decimal(3,2)");
b1.Property<int?>("VoteCount")
.HasColumnType("INTEGER");
b1.HasKey("Id");
b1.HasIndex("BookId");
b1.ToTable("BookRatings", (string)null);
b1.WithOwner()
.HasForeignKey("BookId");
});
b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnDto", "ISBNs", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b1.Property<Guid>("BookId")
.HasColumnType("TEXT");
b1.Property<string>("Format")
.IsRequired()
.HasMaxLength(6)
.HasColumnType("TEXT");
b1.Property<string>("Value")
.IsRequired()
.HasMaxLength(13)
.HasColumnType("TEXT")
.HasColumnName("ISBN");
b1.HasKey("Id");
b1.HasIndex("BookId");
b1.ToTable("BookISBNs", (string)null);
b1.WithOwner()
.HasForeignKey("BookId");
});
b.Navigation("ISBNs");
b.Navigation("Ratings");
});
#pragma warning restore 612, 618
}
}
}