app / src /ClipForge.Infrastructure /Data /AppDbContext.cs
Vanderson da Silva Quintino
Initial deploy: ClipForge video generator
8fb6238
Raw History Blame Contribute Delete
4.97 kB
using ClipForge.Core.Entities;
using Microsoft.EntityFrameworkCore;
namespace ClipForge.Infrastructure.Data;
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
public DbSet<VideoIdea> VideoIdeas => Set<VideoIdea>();
public DbSet<VideoScript> VideoScripts => Set<VideoScript>();
public DbSet<VoiceAsset> VoiceAssets => Set<VoiceAsset>();
public DbSet<VideoAsset> VideoAssets => Set<VideoAsset>();
public DbSet<CaptionAsset> CaptionAssets => Set<CaptionAsset>();
public DbSet<PublishJob> PublishJobs => Set<PublishJob>();
public DbSet<SocialAccount> SocialAccounts => Set<SocialAccount>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<VideoIdea>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Topic).HasMaxLength(500).IsRequired();
entity.Property(e => e.Title).HasMaxLength(500).IsRequired();
entity.Property(e => e.Hook).HasMaxLength(1000).IsRequired();
entity.Property(e => e.TargetAudience).HasMaxLength(200);
entity.Property(e => e.Platform).HasMaxLength(50);
entity.Property(e => e.Status).HasMaxLength(50);
entity.Property(e => e.Niche).HasMaxLength(200);
entity.Property(e => e.Tags).HasMaxLength(1000);
entity.HasOne(e => e.Script).WithOne(s => s.VideoIdea).HasForeignKey<VideoScript>(s => s.VideoIdeaId);
});
modelBuilder.Entity<VideoScript>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.ScriptText).IsRequired();
entity.Property(e => e.Scenes).IsRequired();
entity.Property(e => e.Tone).HasMaxLength(50);
entity.Property(e => e.Language).HasMaxLength(10);
entity.HasOne(e => e.VoiceAsset).WithOne(v => v.VideoScript).HasForeignKey<VoiceAsset>(v => v.VideoScriptId);
entity.HasOne(e => e.VideoAsset).WithOne(v => v.VideoScript).HasForeignKey<VideoAsset>(v => v.VideoScriptId);
});
modelBuilder.Entity<VoiceAsset>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.FilePath).HasMaxLength(1000).IsRequired();
entity.Property(e => e.VoiceProvider).HasMaxLength(50);
entity.Property(e => e.VoiceId).HasMaxLength(100);
});
modelBuilder.Entity<VideoAsset>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.FilePath).HasMaxLength(1000).IsRequired();
entity.Property(e => e.ThumbnailPath).HasMaxLength(1000);
entity.Property(e => e.Format).HasMaxLength(10);
entity.Property(e => e.Status).HasMaxLength(50);
entity.HasOne(e => e.CaptionAsset).WithOne(c => c.VideoAsset).HasForeignKey<CaptionAsset>(c => c.VideoAssetId);
entity.HasMany(e => e.PublishJobs).WithOne(p => p.VideoAsset).HasForeignKey(p => p.VideoAssetId);
});
modelBuilder.Entity<CaptionAsset>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.SrtFilePath).HasMaxLength(1000).IsRequired();
entity.Property(e => e.CaptionStyle).HasMaxLength(50);
entity.Property(e => e.FontFamily).HasMaxLength(100);
entity.Property(e => e.FontColor).HasMaxLength(20);
entity.Property(e => e.StrokeColor).HasMaxLength(20);
});
modelBuilder.Entity<PublishJob>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Platform).HasMaxLength(50).IsRequired();
entity.Property(e => e.Status).HasMaxLength(50);
entity.Property(e => e.ExternalId).HasMaxLength(500);
entity.Property(e => e.ErrorMessage).HasMaxLength(2000);
entity.Property(e => e.Caption).HasMaxLength(2000);
entity.Property(e => e.Hashtags).HasMaxLength(1000);
entity.HasOne(e => e.SocialAccount).WithMany(s => s.PublishJobs).HasForeignKey(e => e.SocialAccountId);
});
modelBuilder.Entity<SocialAccount>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Platform).HasMaxLength(50).IsRequired();
entity.Property(e => e.AccountName).HasMaxLength(200).IsRequired();
entity.Property(e => e.AccessToken).HasMaxLength(2000);
entity.Property(e => e.RefreshToken).HasMaxLength(2000);
});
}
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
foreach (var entry in ChangeTracker.Entries<BaseEntity>())
{
if (entry.State == EntityState.Modified)
entry.Entity.UpdatedAt = DateTime.UtcNow;
}
return base.SaveChangesAsync(cancellationToken);
}
}