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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,58 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SVSim.Database.Migrations
{
/// <inheritdoc />
public partial class AddViewerBattleHistory : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ViewerBattleHistories",
columns: table => new
{
ViewerId = table.Column<long>(type: "bigint", nullable: false),
BattleId = table.Column<long>(type: "bigint", nullable: false),
BattleType = table.Column<int>(type: "integer", nullable: false),
DeckFormat = table.Column<int>(type: "integer", nullable: false),
TwoPickType = table.Column<int>(type: "integer", nullable: false),
IsLimitTurn = table.Column<int>(type: "integer", nullable: false),
SelfClassId = table.Column<int>(type: "integer", nullable: false),
SelfSubClassId = table.Column<int>(type: "integer", nullable: false),
SelfCharaId = table.Column<int>(type: "integer", nullable: false),
SelfRotationId = table.Column<string>(type: "text", nullable: false),
OpponentClassId = table.Column<int>(type: "integer", nullable: false),
OpponentSubClassId = table.Column<int>(type: "integer", nullable: false),
OpponentCharaId = table.Column<int>(type: "integer", nullable: false),
OpponentName = table.Column<string>(type: "text", nullable: false),
OpponentCountryCode = table.Column<string>(type: "text", nullable: false),
OpponentEmblemId = table.Column<long>(type: "bigint", nullable: false),
OpponentDegreeId = table.Column<long>(type: "bigint", nullable: false),
OpponentRotationId = table.Column<string>(type: "text", nullable: false),
IsWin = table.Column<bool>(type: "boolean", nullable: false),
BattleStartTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
CreateTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ViewerBattleHistories", x => new { x.ViewerId, x.BattleId });
});
migrationBuilder.CreateIndex(
name: "IX_ViewerBattleHistories_ViewerId_CreateTime",
table: "ViewerBattleHistories",
columns: new[] { "ViewerId", "CreateTime" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ViewerBattleHistories");
}
}
}

View File

@@ -2843,6 +2843,83 @@ namespace SVSim.Database.Migrations
b.ToTable("ViewerArenaTwoPickRuns");
});
modelBuilder.Entity("SVSim.Database.Models.ViewerBattleHistory", b =>
{
b.Property<long>("ViewerId")
.HasColumnType("bigint");
b.Property<long>("BattleId")
.HasColumnType("bigint");
b.Property<DateTime>("BattleStartTime")
.HasColumnType("timestamp with time zone");
b.Property<int>("BattleType")
.HasColumnType("integer");
b.Property<DateTime>("CreateTime")
.HasColumnType("timestamp with time zone");
b.Property<int>("DeckFormat")
.HasColumnType("integer");
b.Property<int>("IsLimitTurn")
.HasColumnType("integer");
b.Property<bool>("IsWin")
.HasColumnType("boolean");
b.Property<int>("OpponentCharaId")
.HasColumnType("integer");
b.Property<int>("OpponentClassId")
.HasColumnType("integer");
b.Property<string>("OpponentCountryCode")
.IsRequired()
.HasColumnType("text");
b.Property<long>("OpponentDegreeId")
.HasColumnType("bigint");
b.Property<long>("OpponentEmblemId")
.HasColumnType("bigint");
b.Property<string>("OpponentName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("OpponentRotationId")
.IsRequired()
.HasColumnType("text");
b.Property<int>("OpponentSubClassId")
.HasColumnType("integer");
b.Property<int>("SelfCharaId")
.HasColumnType("integer");
b.Property<int>("SelfClassId")
.HasColumnType("integer");
b.Property<string>("SelfRotationId")
.IsRequired()
.HasColumnType("text");
b.Property<int>("SelfSubClassId")
.HasColumnType("integer");
b.Property<int>("TwoPickType")
.HasColumnType("integer");
b.HasKey("ViewerId", "BattleId");
b.HasIndex("ViewerId", "CreateTime")
.HasDatabaseName("IX_ViewerBattleHistories_ViewerId_CreateTime");
b.ToTable("ViewerBattleHistories");
});
modelBuilder.Entity("SVSim.Database.Models.ViewerBattlePassClaimEntry", b =>
{
b.Property<long>("Id")