[FA-misc] Add Job entity and ReportingDbContext

This commit is contained in:
gamer147
2026-01-30 16:38:46 -05:00
parent 9577aa996a
commit 3c835d9cc3
2 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
using FictionArchive.Common.Enums;
using FictionArchive.Service.Shared.Models;
namespace FictionArchive.Service.ReportingService.Models;
public class Job : BaseEntity<Guid>
{
public Guid? ParentJobId { get; set; }
public string JobType { get; set; } = null!;
public string DisplayName { get; set; } = null!;
public JobStatus Status { get; set; }
public string? ErrorMessage { get; set; }
public Dictionary<string, string>? Metadata { get; set; }
// Navigation
public Job? ParentJob { get; set; }
public List<Job> ChildJobs { get; set; } = [];
}

View File

@@ -0,0 +1,32 @@
using FictionArchive.Service.ReportingService.Models;
using FictionArchive.Service.Shared.Services.Database;
using Microsoft.EntityFrameworkCore;
namespace FictionArchive.Service.ReportingService.Services;
public class ReportingDbContext : FictionArchiveDbContext
{
public DbSet<Job> Jobs { get; set; }
public ReportingDbContext(DbContextOptions options, ILogger<ReportingDbContext> logger) : base(options, logger)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Job>(entity =>
{
entity.HasIndex(j => j.ParentJobId);
entity.Property(j => j.Metadata)
.HasColumnType("jsonb");
entity.HasOne(j => j.ParentJob)
.WithMany(j => j.ChildJobs)
.HasForeignKey(j => j.ParentJobId)
.OnDelete(DeleteBehavior.SetNull);
});
}
}