Files
SVSimServer/SVSim.Database/Migrations/20260528030221_AddSpotCardExchange.cs
gamer147 7ef5f03eb3 feat(spot-card-exchange): /spot_card_exchange/{top,exchange} + SpotPoints currency
Final shop family. Schema additions:
- ViewerCurrency.SpotPoints (ulong) — new currency column on Viewers.
- SpotCardExchangeEntry — catalog (distinct from the pre-existing
  SpotCardEntry, which is the /load/index rental-cost concept).
- ViewerSpotCardExchange — standalone composite-PK table tracking
  (viewer, card, exchanged_at, is_pre_release_snapshot). Standalone
  avoids cartesian-explode on viewer-graph reads.

RewardGrantService gains a SpotCardPoint=12 currency case mirroring
the RedEther/Crystal pattern. Doc comment refreshed; SpotCard=11 and
SpotCardOnlyLatestCardPack=13 remain unimplemented with explanatory
NotSupportedException — captures show emitters always use Card=5 with
the spot-card-specific id.

Controller:
- /top: emits exactly 9 clan buckets [{"1": [cards]}, ...] matching
  prod's arbitrary single-key shape. exchange_status per-card (0=
  available, 1=already-exchanged, 2=LimitOver after pre-release cap).
  pre_relase_info WIRE TYPO PRESERVED ("relase" not "release").
- /exchange: server-authoritative price (client-supplied
  exchange_point ignored); debits SpotPoints with post-state-total
  reward_list entry; grants card via RewardGrantService.ApplyAsync
  (cosmetic cascade included); persists ViewerSpotCardExchange row.
  Insufficient points / already-exchanged / pre-release-limit all
  return 400 without partial state.

LoadController now populates /load/index spot_point from
viewer.Currency.SpotPoints (was always 0).

PreReleaseLimit hardcoded to 2 matching capture; promote to GameConfig
when captures show variance.

504 tests pass (was 496; +8 spot-card-exchange tests).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 23:23:07 -04:00

75 lines
3.0 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SVSim.Database.Migrations
{
/// <inheritdoc />
public partial class AddSpotCardExchange : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<decimal>(
name: "Currency_SpotPoints",
table: "Viewers",
type: "numeric(20,0)",
nullable: false,
defaultValue: 0m);
migrationBuilder.CreateTable(
name: "SpotCardExchangeCatalog",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
CardId = table.Column<long>(type: "bigint", nullable: false),
ClassId = table.Column<int>(type: "integer", nullable: false),
ExchangePoint = table.Column<int>(type: "integer", nullable: false),
TsRotationId = table.Column<long>(type: "bigint", nullable: false),
IsPreRelease = table.Column<bool>(type: "boolean", nullable: false),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateUpdated = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SpotCardExchangeCatalog", x => x.Id);
});
migrationBuilder.CreateTable(
name: "ViewerSpotCardExchanges",
columns: table => new
{
ViewerId = table.Column<long>(type: "bigint", nullable: false),
CardId = table.Column<long>(type: "bigint", nullable: false),
IsPreRelease = table.Column<bool>(type: "boolean", nullable: false),
ExchangedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ViewerSpotCardExchanges", x => new { x.ViewerId, x.CardId });
});
migrationBuilder.CreateIndex(
name: "IX_ViewerSpotCardExchanges_ViewerId",
table: "ViewerSpotCardExchanges",
column: "ViewerId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "SpotCardExchangeCatalog");
migrationBuilder.DropTable(
name: "ViewerSpotCardExchanges");
migrationBuilder.DropColumn(
name: "Currency_SpotPoints",
table: "Viewers");
}
}
}