DB Cleanup
This commit is contained in:
2576
SVSim.Database/Migrations/20260525203838_AddOwnedEntryUniqueIndexes.Designer.cs
generated
Normal file
2576
SVSim.Database/Migrations/20260525203838_AddOwnedEntryUniqueIndexes.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user