feat(replay): add ViewerBattleHistory entity + migration

New table backs /replay/info; composite PK (ViewerId, BattleId), index on
(ViewerId, CreateTime) for the newest-first list query. 50-row per-viewer
retention enforced by BattleHistoryWriter (next commit).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-10 07:32:05 -04:00
parent 2d65fcd91c
commit 0bb0f46abc
6 changed files with 4916 additions and 0 deletions

View File

@@ -115,6 +115,7 @@ public class SVSimDbContext : DbContext
public DbSet<ViewerFriend> ViewerFriends => Set<ViewerFriend>();
public DbSet<ViewerFriendApply> ViewerFriendApplies => Set<ViewerFriendApply>();
public DbSet<ViewerPlayedTogether> ViewerPlayedTogethers => Set<ViewerPlayedTogether>();
public DbSet<ViewerBattleHistory> ViewerBattleHistories => Set<ViewerBattleHistory>();
#endregion
@@ -484,6 +485,17 @@ public class SVSimDbContext : DbContext
// OpponentViewerId is NOT an FK — we want survivors' history to outlive a deleted opponent.
});
modelBuilder.Entity<ViewerBattleHistory>(b =>
{
b.HasKey(e => new { e.ViewerId, e.BattleId });
b.HasIndex(e => new { e.ViewerId, e.CreateTime })
.HasDatabaseName("IX_ViewerBattleHistories_ViewerId_CreateTime");
b.Property(e => e.SelfRotationId).IsRequired();
b.Property(e => e.OpponentName).IsRequired();
b.Property(e => e.OpponentCountryCode).IsRequired();
b.Property(e => e.OpponentRotationId).IsRequired();
});
base.OnModelCreating(modelBuilder);
}