using FictionArchive.Service.ReportingService.Models.Database; using FictionArchive.Service.Shared.Services.Database; using Microsoft.EntityFrameworkCore; namespace FictionArchive.Service.ReportingService.Services; public class ReportingServiceDbContext : FictionArchiveDbContext { public ReportingServiceDbContext(DbContextOptions options, ILogger logger) : base(options, logger) { } public DbSet Jobs => Set(); public DbSet JobHistoryEntries => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity(entity => { entity.HasKey(e => e.Id); entity.HasIndex(e => e.JobType); entity.HasIndex(e => e.Status); entity.HasIndex(e => e.CreatedTime); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.Id); entity.HasOne(e => e.Job) .WithMany(j => j.History) .HasForeignKey(e => e.JobId) .OnDelete(DeleteBehavior.Cascade); }); } }