feat(db): wire ViewerPresent into SVSimDbContext with indexes

This commit is contained in:
gamer147
2026-06-08 20:33:50 -04:00
parent a6a8c6b1a4
commit eea596c6ec

View File

@@ -102,6 +102,7 @@ public class SVSimDbContext : DbContext
public DbSet<ViewerStoryBranchUnlock> ViewerStoryBranchUnlocks => Set<ViewerStoryBranchUnlock>();
public DbSet<ViewerClaimedTutorialGift> ViewerClaimedTutorialGifts => Set<ViewerClaimedTutorialGift>();
public DbSet<ViewerPresent> ViewerPresents => Set<ViewerPresent>();
public DbSet<ArenaTwoPickReward> ArenaTwoPickRewards { get; set; } = null!;
public DbSet<ViewerArenaTwoPickRun> ViewerArenaTwoPickRuns { get; set; } = null!;
@@ -373,6 +374,25 @@ public class SVSimDbContext : DbContext
b.Property(g => g.PresentId).HasMaxLength(64);
});
modelBuilder.Entity<ViewerPresent>(b =>
{
b.HasKey(p => p.Id);
b.Property(p => p.PresentId).HasMaxLength(64);
b.Property(p => p.Source).HasMaxLength(64);
b.HasOne(p => p.Viewer)
.WithMany()
.HasForeignKey(p => p.ViewerId)
.OnDelete(DeleteBehavior.Cascade);
// Drives /gift/top — partition by status, then chronological.
b.HasIndex(p => new { p.ViewerId, p.Status, p.CreatedAt });
// One row per (viewer, present_id) — backstop against double-seeding and
// double-enqueue from future producers.
b.HasIndex(p => new { p.ViewerId, p.PresentId }).IsUnique();
});
base.OnModelCreating(modelBuilder);
}