DB Cleanup

This commit is contained in:
gamer147
2026-05-25 16:45:02 -04:00
parent 8e913578ff
commit 016efeea2c
5 changed files with 2664 additions and 0 deletions

View File

@@ -126,6 +126,21 @@ public class SVSimDbContext : DbContext
modelBuilder.Entity<PackConfigEntry>().OwnsMany(p => p.Banners);
modelBuilder.Entity<Viewer>().OwnsMany(v => v.PackOpenCounts);
// OwnedCardEntry and OwnedItemEntry use composite PK (ViewerId, Id) where Id is auto-
// generated, which silently permits multiple rows per (Viewer, Card) or (Viewer, Item).
// The intended semantic is one row per pair with Count as multiplicity — enforce that as
// a unique index so any future find-or-add that forgets to .Include the collection (and
// therefore re-creates a row that already exists in the DB) crashes loudly at SaveChanges
// instead of silently duplicating ownership rows.
modelBuilder.Entity<Viewer>().OwnsMany(v => v.Cards, b =>
{
b.HasIndex("ViewerId", "CardId").IsUnique();
});
modelBuilder.Entity<Viewer>().OwnsMany(v => v.Items, b =>
{
b.HasIndex("ViewerId", "ItemId").IsUnique();
});
modelBuilder.Entity<CardCosmeticReward>(b =>
{
b.HasKey(r => new { r.CardId, r.Type, r.CosmeticId });