Add 'backend/' from commit '040cfd7a75423d4e6136e58a67b40579af4ee966'

git-subtree-dir: backend
git-subtree-mainline: ab911955ed
git-subtree-split: 040cfd7a75
This commit is contained in:
2025-01-15 15:24:30 -05:00
179 changed files with 14349 additions and 0 deletions

View 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));
}
}