Added configurations for entity builders. Also added VoiceWorkLocaalization entity.
This commit is contained in:
@@ -8,4 +8,6 @@ public class Circle
|
||||
public bool Blacklisted { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
public bool Spam { get; set; }
|
||||
|
||||
public virtual ICollection<VoiceWork> VoiceWorks { get; set; } = [];
|
||||
}
|
||||
@@ -9,4 +9,6 @@ public class Series
|
||||
|
||||
public required string Name { get; set; }
|
||||
public required string Identifier { get; set; }
|
||||
|
||||
public virtual ICollection<VoiceWork> VoiceWorks { get; set; } = [];
|
||||
}
|
||||
@@ -39,4 +39,5 @@ public class VoiceWork
|
||||
public virtual ICollection<VoiceWorkTag> VoiceWorkTags { get; set; } = [];
|
||||
public virtual ICollection<VoiceWorkCreator> VoiceWorkCreators { get; set; } = [];
|
||||
public virtual ICollection<EnglishVoiceWork> EnglishVoiceWorks { get; set; } = [];
|
||||
public virtual ICollection<VoiceWorkLocalization> Localizations { get; set; } = [];
|
||||
}
|
||||
13
JSMR.Domain/Entities/VoiceWorkLocalization.cs
Normal file
13
JSMR.Domain/Entities/VoiceWorkLocalization.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace JSMR.Domain.Entities;
|
||||
|
||||
public sealed class VoiceWorkLocalization
|
||||
{
|
||||
public int VoiceWorkLocalizationId { get; set; }
|
||||
public int VoiceWorkId { get; set; }
|
||||
public string Language { get; set; } = null!; // "ja-JP", "en", etc.
|
||||
public string? ProductName { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public bool IsOfficial { get; set; }
|
||||
|
||||
public VoiceWork VoiceWork { get; set; } = null!;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ public class AppDbContext : DbContext
|
||||
{
|
||||
public DbSet<VoiceWork> VoiceWorks { get; set; }
|
||||
public DbSet<EnglishVoiceWork> EnglishVoiceWorks { get; set; }
|
||||
public DbSet<VoiceWorkLocalization> VoiceWorkLocalizations { get; set; }
|
||||
public DbSet<Circle> Circles { get; set; }
|
||||
public DbSet<Tag> Tags { get; set; }
|
||||
public DbSet<EnglishTag> EnglishTags { get; set; }
|
||||
@@ -15,4 +16,9 @@ public class AppDbContext : DbContext
|
||||
public DbSet<VoiceWorkCreator> VoiceWorkCreators { get; set; }
|
||||
public DbSet<Series> Series { get; set; }
|
||||
public DbSet<VoiceWorkSearch> VoiceWorkSearches { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Configuration;
|
||||
|
||||
public sealed class CircleConfiguration : IEntityTypeConfiguration<Circle>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Circle> builder)
|
||||
{
|
||||
builder.ToTable("circles");
|
||||
builder.HasKey(x => x.CircleId);
|
||||
|
||||
builder.Property(x => x.Name).IsRequired().HasMaxLength(256);
|
||||
builder.Property(x => x.MakerId).IsRequired().HasMaxLength(16);
|
||||
|
||||
builder.HasIndex(x => x.Name);
|
||||
builder.HasIndex(x => x.MakerId).IsUnique();
|
||||
builder.HasIndex(x => x.Favorite);
|
||||
builder.HasIndex(x => x.Blacklisted);
|
||||
builder.HasIndex(x => x.Spam);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Configuration;
|
||||
|
||||
public sealed class CreatorConfiguration : IEntityTypeConfiguration<Creator>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Creator> builder)
|
||||
{
|
||||
builder.ToTable("creators");
|
||||
builder.HasKey(x => x.CreatorId);
|
||||
|
||||
builder.Property(x => x.Name).IsRequired().HasMaxLength(128);
|
||||
|
||||
builder.HasIndex(x => x.Name);
|
||||
builder.HasIndex(x => x.Favorite);
|
||||
builder.HasIndex(x => x.Blacklisted);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Configuration;
|
||||
|
||||
public sealed class EnglishTagConfiguration : IEntityTypeConfiguration<EnglishTag>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<EnglishTag> builder)
|
||||
{
|
||||
builder.ToTable("english_tags");
|
||||
builder.HasKey(x => x.EnglishTagId);
|
||||
|
||||
builder.Property(x => x.Name).IsRequired().HasMaxLength(128);
|
||||
|
||||
builder.HasOne(x => x.Tag)
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.TagId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasIndex(x => x.TagId).IsUnique();
|
||||
builder.HasIndex(x => x.Name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Configuration;
|
||||
|
||||
public sealed class EnglishVoiceWorkConfiguration : IEntityTypeConfiguration<EnglishVoiceWork>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<EnglishVoiceWork> builder)
|
||||
{
|
||||
builder.ToTable("english_voice_works");
|
||||
builder.HasKey(x => x.EnglishVoiceWorkId);
|
||||
|
||||
builder.Property(x => x.ProductName).HasMaxLength(256);
|
||||
builder.Property(x => x.Description).HasMaxLength(512);
|
||||
|
||||
builder.HasOne(x => x.VoiceWork)
|
||||
.WithMany(v => v.EnglishVoiceWorks)
|
||||
.HasForeignKey(x => x.VoiceWorkId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasIndex(x => x.VoiceWorkId).IsUnique();
|
||||
builder.HasIndex(x => x.IsValid);
|
||||
}
|
||||
}
|
||||
20
JSMR.Infrastructure/Data/Configuration/TagConfiguration.cs
Normal file
20
JSMR.Infrastructure/Data/Configuration/TagConfiguration.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Configuration;
|
||||
|
||||
public sealed class TagConfiguration : IEntityTypeConfiguration<Tag>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Tag> builder)
|
||||
{
|
||||
builder.ToTable("tags");
|
||||
builder.HasKey(x => x.TagId);
|
||||
|
||||
builder.Property(x => x.Name).IsRequired().HasMaxLength(128);
|
||||
|
||||
builder.HasIndex(x => x.Name).IsUnique();
|
||||
builder.HasIndex(x => x.Favorite);
|
||||
builder.HasIndex(x => x.Blacklisted);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Configuration;
|
||||
|
||||
public sealed class VoiceWorkConfiguration : IEntityTypeConfiguration<VoiceWork>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<VoiceWork> builder)
|
||||
{
|
||||
builder.ToTable("voice_works");
|
||||
builder.HasKey(x => x.VoiceWorkId);
|
||||
|
||||
builder.Property(x => x.ProductId)
|
||||
.IsRequired()
|
||||
.HasMaxLength(16);
|
||||
|
||||
builder.Property(x => x.OriginalProductId)
|
||||
.HasMaxLength(16);
|
||||
|
||||
builder.Property(x => x.ProductName)
|
||||
.IsRequired()
|
||||
.HasMaxLength(256);
|
||||
|
||||
builder.Property(x => x.Description)
|
||||
.HasMaxLength(512);
|
||||
|
||||
// Relationships
|
||||
builder.HasOne(x => x.Circle)
|
||||
.WithMany(c => c.VoiceWorks)
|
||||
.HasForeignKey(x => x.CircleId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(x => x.Series)
|
||||
.WithMany(s => s.VoiceWorks)
|
||||
.HasForeignKey(x => x.SeriesId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
// Indexes for common filters/sorts
|
||||
builder.HasIndex(x => x.ProductId).IsUnique();
|
||||
builder.HasIndex(x => x.CircleId);
|
||||
builder.HasIndex(x => x.SalesDate);
|
||||
builder.HasIndex(x => x.ExpectedDate);
|
||||
builder.HasIndex(x => x.Favorite);
|
||||
builder.HasIndex(x => x.IsValid);
|
||||
builder.HasIndex(x => x.SubtitleLanguage);
|
||||
builder.HasIndex(x => x.AIGeneration);
|
||||
builder.HasIndex(x => x.Downloads);
|
||||
builder.HasIndex(x => x.WishlistCount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Configuration;
|
||||
|
||||
public sealed class VoiceWorkCreatorConfiguration : IEntityTypeConfiguration<VoiceWorkCreator>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<VoiceWorkCreator> builder)
|
||||
{
|
||||
builder.ToTable("voice_work_creators");
|
||||
builder.HasKey(x => new { x.VoiceWorkId, x.CreatorId });
|
||||
|
||||
builder.HasOne(x => x.VoiceWork)
|
||||
.WithMany(v => v.VoiceWorkCreators)
|
||||
.HasForeignKey(x => x.VoiceWorkId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasOne(x => x.Creator)
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.CreatorId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasIndex(x => x.CreatorId);
|
||||
builder.HasIndex(x => new { x.VoiceWorkId, x.Position });
|
||||
builder.HasIndex(x => x.IsValid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Configuration;
|
||||
|
||||
public sealed class VoiceWorkLocalizationConfiguration : IEntityTypeConfiguration<VoiceWorkLocalization>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<VoiceWorkLocalization> builder)
|
||||
{
|
||||
builder.ToTable("voice_work_localizations");
|
||||
builder.HasKey(x => x.VoiceWorkLocalizationId);
|
||||
|
||||
builder.Property(x => x.Language).IsRequired().HasMaxLength(10);
|
||||
builder.Property(x => x.ProductName).HasMaxLength(256);
|
||||
builder.Property(x => x.Description).HasMaxLength(512);
|
||||
|
||||
builder.HasOne(x => x.VoiceWork)
|
||||
.WithMany(v => v.Localizations)
|
||||
.HasForeignKey(x => x.VoiceWorkId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasIndex(x => new { x.VoiceWorkId, x.Language }).IsUnique();
|
||||
builder.HasIndex(x => x.VoiceWorkId);
|
||||
builder.HasIndex(x => x.ProductName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Configuration;
|
||||
|
||||
public sealed class VoiceWorkSearchConfiguration : IEntityTypeConfiguration<VoiceWorkSearch>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<VoiceWorkSearch> builder)
|
||||
{
|
||||
builder.ToTable("voice_work_searches");
|
||||
builder.HasKey(x => x.VoiceWorkId); // also the FK
|
||||
|
||||
builder.Property(x => x.SearchText).IsRequired(); // TEXT/LONGTEXT
|
||||
|
||||
builder.HasOne(x => x.VoiceWork)
|
||||
.WithOne() // not navigated from VoiceWork in your model
|
||||
.HasForeignKey<VoiceWorkSearch>(x => x.VoiceWorkId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// MariaDB/MySQL (Pomelo) fulltext (BOOLEAN/NATURAL) — create an FT index
|
||||
// Pomelo supports .HasMethod("FULLTEXT"). If your version doesn't, add it in a migration SQL.
|
||||
//builder.HasIndex(x => x.SearchText)
|
||||
// .HasDatabaseName("FT_SearchText")
|
||||
// .HasMethod("FULLTEXT");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Configuration;
|
||||
|
||||
public sealed class VoiceWorkTagConfiguration : IEntityTypeConfiguration<VoiceWorkTag>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<VoiceWorkTag> builder)
|
||||
{
|
||||
builder.ToTable("voice_work_tags");
|
||||
builder.HasKey(x => new { x.VoiceWorkId, x.TagId });
|
||||
|
||||
builder.HasOne(x => x.VoiceWork)
|
||||
.WithMany(v => v.VoiceWorkTags)
|
||||
.HasForeignKey(x => x.VoiceWorkId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasOne(x => x.Tag)
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.TagId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// Helpful indexes
|
||||
builder.HasIndex(x => x.TagId);
|
||||
builder.HasIndex(x => new { x.VoiceWorkId, x.Position });
|
||||
builder.HasIndex(x => x.IsValid);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.8" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user