Add 'backend/' from commit '040cfd7a75423d4e6136e58a67b40579af4ee966'
git-subtree-dir: backend git-subtree-mainline:ab911955edgit-subtree-split:040cfd7a75
This commit is contained in:
68
backend/src/Web/Features/Contents/Data/ContentDbContext.cs
Normal file
68
backend/src/Web/Features/Contents/Data/ContentDbContext.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
namespace Hutopy.Web.Features.Contents.Data;
|
||||
|
||||
public class ContentDbContext(
|
||||
DbContextOptions<ContentDbContext> options)
|
||||
: DbContext(options)
|
||||
{
|
||||
public const string SchemaName = "Content";
|
||||
|
||||
public DbSet<Content> Contents => Set<Content>();
|
||||
public DbSet<Creator> Creators => Set<Creator>();
|
||||
|
||||
protected override void OnModelCreating(
|
||||
ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.HasDefaultSchema(SchemaName);
|
||||
|
||||
modelBuilder
|
||||
.Entity<Content>()
|
||||
.Property(c => c.CreatedAt)
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
|
||||
modelBuilder
|
||||
.Entity<Content>()
|
||||
.HasOne(c => c.Creator)
|
||||
.WithMany()
|
||||
.HasForeignKey(c => c.CreatedBy);
|
||||
|
||||
modelBuilder
|
||||
.Entity<Content>()
|
||||
.OwnsMany(c => c.Reactions)
|
||||
.ToTable("Reactions");
|
||||
|
||||
modelBuilder
|
||||
.Entity<Content>()
|
||||
.Property(c => c.ThumbnailUrl);
|
||||
|
||||
modelBuilder
|
||||
.Entity<Creator>()
|
||||
.Property(x => x.NormalizedName)
|
||||
.HasComputedColumnSql("LOWER( \"Content\".\"Creators\".\"Name\")", stored: true);
|
||||
|
||||
modelBuilder
|
||||
.Entity<Creator>()
|
||||
.HasIndex(x => x.NormalizedName)
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder
|
||||
.Entity<Creator>()
|
||||
.OwnsOne<Socials>(x => x.Socials)
|
||||
.ToTable(nameof(Socials));
|
||||
|
||||
modelBuilder
|
||||
.Entity<Creator>()
|
||||
.OwnsOne<Colors>(x => x.Colors)
|
||||
.ToTable(nameof(Colors));
|
||||
|
||||
modelBuilder
|
||||
.Entity<Creator>()
|
||||
.OwnsOne<Images>(x => x.Images)
|
||||
.ToTable(nameof(Images));
|
||||
|
||||
modelBuilder
|
||||
.Entity<Creator>()
|
||||
.OwnsOne<PresentationInfos>(x => x.PresentationInfos)
|
||||
.ToTable(nameof(PresentationInfos));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user