feat(rank): add ViewerRankProgress owned entity + migration

One row per (viewer, format) tracking accumulated Point + MasterPoint.
Unique index on (ViewerId, Format) enforces one row per format per viewer
(mirrors owned-collection precedent per project_owned_collection_unique_index).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-07-04 10:13:50 -04:00
parent 94ed6734c7
commit 9f97837211
5 changed files with 5184 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace SVSim.Database.Migrations
{
/// <inheritdoc />
public partial class AddViewerRankProgress : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ViewerRankProgress",
columns: table => new
{
ViewerId = table.Column<long>(type: "bigint", nullable: false),
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Format = table.Column<int>(type: "integer", nullable: false),
Point = table.Column<int>(type: "integer", nullable: false),
MasterPoint = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ViewerRankProgress", x => new { x.ViewerId, x.Id });
table.ForeignKey(
name: "FK_ViewerRankProgress_Viewers_ViewerId",
column: x => x.ViewerId,
principalTable: "Viewers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ViewerRankProgress_ViewerId_Format",
table: "ViewerRankProgress",
columns: new[] { "ViewerId", "Format" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_ViewerRankProgress_ViewerId_Format",
table: "ViewerRankProgress");
migrationBuilder.DropTable(
name: "ViewerRankProgress");
}
}
}

View File

@@ -4837,6 +4837,34 @@ namespace SVSim.Database.Migrations
.HasForeignKey("ViewerId");
});
b.OwnsMany("SVSim.Database.Models.ViewerRankProgress", "RankProgress", b1 =>
{
b1.Property<long>("ViewerId")
.HasColumnType("bigint");
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property<int>("Id"));
b1.Property<int>("Format")
.HasColumnType("integer");
b1.Property<int>("MasterPoint")
.HasColumnType("integer");
b1.Property<int>("Point")
.HasColumnType("integer");
b1.HasKey("ViewerId", "Id");
b1.ToTable("ViewerRankProgress");
b1.WithOwner()
.HasForeignKey("ViewerId");
});
b.Navigation("BuildDeckPurchases");
b.Navigation("Cards");
@@ -4868,6 +4896,8 @@ namespace SVSim.Database.Migrations
b.Navigation("PackStarterClasses");
b.Navigation("RankProgress");
b.Navigation("SocialAccountConnections");
});

View File

@@ -87,6 +87,8 @@ public class Viewer : BaseEntity<long>
public List<ViewerFreePackClaim> FreePackClaims { get; set; } = new List<ViewerFreePackClaim>();
public List<ViewerRankProgress> RankProgress { get; set; } = new List<ViewerRankProgress>();
public List<MyPageBgRotationEntry> MyPageBgRotation { get; set; } = new List<MyPageBgRotationEntry>();
public List<ViewerGachaPointBalance> GachaPointBalances { get; set; } = new List<ViewerGachaPointBalance>();

View File

@@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
using SVSim.Database.Enums;
namespace SVSim.Database.Models;
/// <summary>
/// One row per (viewer, format) tracking accumulated rank points and master points.
/// Point is 0-based cumulative; the current rank_id is derived at read time from Point
/// (and MasterPoint once past 50000). Owned collection on <see cref="Viewer"/>.
/// </summary>
[Owned]
public class ViewerRankProgress
{
public Format Format { get; set; }
public int Point { get; set; }
public int MasterPoint { get; set; }
}