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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SVSim.Database.Migrations
{
/// <inheritdoc />
public partial class AddOwnedEntryUniqueIndexes : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_OwnedItemEntry_ViewerId_ItemId",
table: "OwnedItemEntry",
columns: new[] { "ViewerId", "ItemId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_OwnedCardEntry_ViewerId_CardId",
table: "OwnedCardEntry",
columns: new[] { "ViewerId", "CardId" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_OwnedItemEntry_ViewerId_ItemId",
table: "OwnedItemEntry");
migrationBuilder.DropIndex(
name: "IX_OwnedCardEntry_ViewerId_CardId",
table: "OwnedCardEntry");
}
}
}

View File

@@ -2228,6 +2228,9 @@ namespace SVSim.Database.Migrations
b1.HasIndex("CardId");
b1.HasIndex("ViewerId", "CardId")
.IsUnique();
b1.ToTable("OwnedCardEntry");
b1.HasOne("SVSim.Database.Models.ShadowverseCardEntry", "Card")
@@ -2263,6 +2266,9 @@ namespace SVSim.Database.Migrations
b1.HasIndex("ItemId");
b1.HasIndex("ViewerId", "ItemId")
.IsUnique();
b1.ToTable("OwnedItemEntry");
b1.HasOne("SVSim.Database.Models.ItemEntry", "Item")

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 });