feat(bootstrap): StoryDeckImporter + seed model, wired after BuildDeck

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-29 10:32:12 -04:00
parent e0da7f09ca
commit e792e8d79d
4 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
using Microsoft.EntityFrameworkCore;
using SVSim.Bootstrap.Models.Seed;
using SVSim.Database;
using SVSim.Database.Enums;
using SVSim.Database.Models;
namespace SVSim.Bootstrap.Importers;
/// <summary>
/// Idempotent upsert of story-deck presentation rows from <c>seeds/story-decks.json</c>.
/// Card lists are NOT imported here — they belong to BuildDeckProductEntry (deck_no == product_id),
/// so this importer should run AFTER BuildDeckImporter.ImportPackageAsync. Rows missing from the
/// seed are left intact.
/// </summary>
public class StoryDeckImporter
{
public async Task<int> ImportAsync(SVSimDbContext context, string seedDir)
{
var seed = SeedLoader.LoadList<StoryDeckSeed>(Path.Combine(seedDir, "story-decks.json"));
if (seed.Count == 0)
{
Console.WriteLine("[StoryDeckImporter] No seed rows; skipping.");
return 0;
}
var existing = await context.StoryDecks.ToDictionaryAsync(e => e.Id);
int created = 0, updated = 0;
foreach (var s in seed)
{
if (s.DeckNo == 0) continue;
var entry = existing.TryGetValue(s.DeckNo, out var ex) ? ex : new StoryDeckEntry { DeckNo = s.DeckNo };
entry.Kind = string.Equals(s.Kind, "trial", StringComparison.OrdinalIgnoreCase)
? StoryDeckKind.Trial : StoryDeckKind.Build;
entry.ClassId = s.ClassId;
entry.DeckName = s.DeckName;
entry.SleeveId = s.SleeveId;
entry.LeaderSkinId = s.LeaderSkinId;
entry.IsRecommend = s.IsRecommend;
entry.OrderNum = s.OrderNum;
entry.EntryNo = s.EntryNo;
entry.DeckFormat = s.DeckFormat;
if (ex is null) { context.StoryDecks.Add(entry); existing[s.DeckNo] = entry; created++; }
else updated++;
}
await context.SaveChangesAsync();
Console.WriteLine($"[StoryDeckImporter] +{created}/~{updated}");
return created + updated;
}
}

View File

@@ -0,0 +1,17 @@
using System.Text.Json.Serialization;
namespace SVSim.Bootstrap.Models.Seed;
public sealed class StoryDeckSeed
{
[JsonPropertyName("deck_no")] public int DeckNo { get; set; }
[JsonPropertyName("kind")] public string Kind { get; set; } = "build";
[JsonPropertyName("class_id")] public int ClassId { get; set; }
[JsonPropertyName("deck_name")] public string DeckName { get; set; } = "";
[JsonPropertyName("sleeve_id")] public int SleeveId { get; set; }
[JsonPropertyName("leader_skin_id")] public int LeaderSkinId { get; set; }
[JsonPropertyName("is_recommend")] public int IsRecommend { get; set; }
[JsonPropertyName("order_num")] public int OrderNum { get; set; }
[JsonPropertyName("entry_no")] public int EntryNo { get; set; }
[JsonPropertyName("deck_format")] public int? DeckFormat { get; set; }
}

View File

@@ -124,6 +124,7 @@ public static class Program
await buildDeck.ImportSeriesAsync(context, opts.ReferenceDataDir);
await buildDeck.ImportCatalogAsync(context, opts.SeedDir);
await buildDeck.ImportPackageAsync(context, opts.ReferenceDataDir);
await new StoryDeckImporter().ImportAsync(context, opts.SeedDir);
}
else
{