refactor(bootstrap): migrate default decks to seed file

Extracts /deck/info's default_deck_list into seeds/default-decks.json
via the new extract-default-decks.ps1 PowerShell script and imports
through DefaultDeckImporter. The importer carries the same orphan-
card-id warning the old GlobalsImporter path emitted; production cards
yield 0 orphans. WarnOrphans stays inside GlobalsImporter for now —
SpotCards/ReprintedCards/UnlimitedRestrictions/LoadingExclusionCards
still use it until Task 9.

Part of the bootstrap seed refactor (Task 6).
This commit is contained in:
gamer147
2026-05-26 14:44:21 -04:00
parent a5e4f35c32
commit 83298a2d47
8 changed files with 593 additions and 530 deletions

View File

@@ -1,484 +0,0 @@
{
"data_headers": {
"sid": "ac631c29b5f5d07ed5fb6712ad8623c31779553958",
"short_udid": 411054851,
"viewer_id": 906243102,
"servertime": 1779553958,
"result_code": 1
},
"data": {
"user_deck_rotation": [],
"user_deck_unlimited": [],
"maintenance_card_list": [],
"user_deck_my_rotation": [],
"trial_deck_list": [],
"default_deck_list": {
"91": {
"null": 1,
"deck_no": 91,
"class_id": 1,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100111010,
100111010,
100111010,
100011020,
100011020,
100011020,
100012010,
100111020,
100111020,
100111020,
100111040,
100111040,
100111040,
100114010,
100114010,
100114010,
100011030,
100011030,
100011030,
100111060,
100111060,
100111060,
100011040,
100011040,
100011040,
100111030,
100111030,
100111030,
100111050,
100111050,
100111050,
100011050,
100011050,
100011050,
100111070,
100111070,
100111070,
100121010,
100121010,
100121010
],
"is_complete_deck": 1,
"is_available_deck": 1,
"maintenance_card_ids": []
},
"92": {
"null": 1,
"deck_no": 92,
"class_id": 2,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100211010,
100211010,
100211010,
100011020,
100011020,
100011020,
100012010,
100211020,
100211020,
100211020,
100211060,
100211060,
100211060,
100214010,
100214010,
100214010,
100011030,
100011030,
100011030,
100211030,
100211030,
100211030,
100214020,
100214020,
100214020,
100011040,
100011040,
100011040,
100211040,
100211040,
100211040,
100011050,
100011050,
100011050,
100211050,
100211050,
100211050,
100221020,
100221020,
100221020
],
"is_complete_deck": 1,
"is_available_deck": 1,
"maintenance_card_ids": []
},
"93": {
"null": 1,
"deck_no": 93,
"class_id": 3,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100314010,
100314010,
100314010,
100011020,
100011020,
100011020,
100012010,
100311010,
100311010,
100311010,
100314030,
100314030,
100314030,
100314020,
100314020,
100314020,
100314040,
100314040,
100314040,
100011030,
100011030,
100011030,
100314050,
100314050,
100314050,
100011040,
100011040,
100011040,
100314060,
100314060,
100314060,
100011050,
100011050,
100011050,
100314070,
100314070,
100314070,
100321010,
100321010,
100321010
],
"is_complete_deck": 1,
"is_available_deck": 1,
"maintenance_card_ids": []
},
"94": {
"null": 1,
"deck_no": 94,
"class_id": 4,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100414020,
100414020,
100414020,
100011020,
100011020,
100011020,
100012010,
100411010,
100411010,
100411010,
100414010,
100414010,
100414010,
100011030,
100011030,
100011030,
100411050,
100411050,
100411050,
100011040,
100011040,
100011040,
100411030,
100411030,
100411030,
100414030,
100414030,
100414030,
100011050,
100011050,
100011050,
100411020,
100411020,
100411020,
100411040,
100411040,
100411040,
100421020,
100421020,
100421020
],
"is_complete_deck": 1,
"is_available_deck": 1,
"maintenance_card_ids": []
},
"95": {
"null": 1,
"deck_no": 95,
"class_id": 5,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100011020,
100011020,
100011020,
100012010,
100511010,
100511010,
100511010,
100511020,
100511020,
100511020,
100514010,
100514010,
100514010,
100011030,
100011030,
100011030,
100511030,
100511030,
100511030,
100011040,
100011040,
100011040,
100511040,
100511040,
100511040,
100011050,
100011050,
100011050,
100511050,
100511050,
100511050,
100514020,
100514020,
100514020,
100511060,
100511060,
100511060,
100521030,
100521030,
100521030
],
"is_complete_deck": 1,
"is_available_deck": 1,
"maintenance_card_ids": []
},
"96": {
"null": 1,
"deck_no": 96,
"class_id": 6,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100011020,
100011020,
100011020,
100012010,
100611010,
100611010,
100611010,
100611020,
100611020,
100611020,
100614010,
100614010,
100614010,
100614020,
100614020,
100614020,
100011030,
100011030,
100011030,
100611030,
100611030,
100611030,
100011040,
100011040,
100011040,
100611050,
100611050,
100611050,
100614030,
100614030,
100614030,
100011050,
100011050,
100011050,
100611040,
100611040,
100611040,
100621010,
100621010,
100621010
],
"is_complete_deck": 1,
"is_available_deck": 1,
"maintenance_card_ids": []
},
"97": {
"null": 1,
"deck_no": 97,
"class_id": 7,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100713020,
100713020,
100713020,
100011020,
100011020,
100011020,
100012010,
100713010,
100713010,
100713010,
100711010,
100711010,
100711010,
100714010,
100714010,
100714010,
100714020,
100714020,
100714020,
100011030,
100011030,
100011030,
100713030,
100713030,
100713030,
100011040,
100011040,
100011040,
100011050,
100011050,
100011050,
100723010,
100723010,
100723010,
100714030,
100714030,
100714030,
100711020,
100711020,
100711020
],
"is_complete_deck": 1,
"is_available_deck": 1,
"maintenance_card_ids": []
},
"98": {
"null": 1,
"deck_no": 98,
"class_id": 8,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100011020,
100011020,
100011020,
100012010,
100811020,
100811020,
100811020,
100811060,
100811060,
100811060,
100811070,
100811070,
100811070,
100814010,
100814010,
100814010,
100011030,
100011030,
100011030,
100811010,
100811010,
100811010,
100811030,
100811030,
100811030,
100011040,
100011040,
100011040,
100811040,
100811040,
100811040,
100824010,
100824010,
100824010,
100011050,
100011050,
100011050,
100811050,
100811050,
100811050
],
"is_complete_deck": 1,
"is_available_deck": 1,
"maintenance_card_ids": []
}
},
"user_leader_skin_setting_list": {
"1": {
"class_id": 1,
"is_random_leader_skin": 0,
"leader_skin_id": 1
},
"2": {
"class_id": 2,
"is_random_leader_skin": 0,
"leader_skin_id": 2
},
"3": {
"class_id": 3,
"is_random_leader_skin": 0,
"leader_skin_id": 3
},
"4": {
"class_id": 4,
"is_random_leader_skin": 0,
"leader_skin_id": 4
},
"5": {
"class_id": 5,
"is_random_leader_skin": 0,
"leader_skin_id": 5
},
"6": {
"class_id": 6,
"is_random_leader_skin": 0,
"leader_skin_id": 6
},
"7": {
"class_id": 7,
"is_random_leader_skin": 0,
"leader_skin_id": 7
},
"8": {
"class_id": 8,
"is_random_leader_skin": 0,
"leader_skin_id": 8
}
}
}
}

View File

@@ -0,0 +1,394 @@
[
{
"id": 91,
"class_id": 1,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100111010,
100111010,
100111010,
100011020,
100011020,
100011020,
100012010,
100111020,
100111020,
100111020,
100111040,
100111040,
100111040,
100114010,
100114010,
100114010,
100011030,
100011030,
100011030,
100111060,
100111060,
100111060,
100011040,
100011040,
100011040,
100111030,
100111030,
100111030,
100111050,
100111050,
100111050,
100011050,
100011050,
100011050,
100111070,
100111070,
100111070,
100121010,
100121010,
100121010
]
},
{
"id": 92,
"class_id": 2,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100211010,
100211010,
100211010,
100011020,
100011020,
100011020,
100012010,
100211020,
100211020,
100211020,
100211060,
100211060,
100211060,
100214010,
100214010,
100214010,
100011030,
100011030,
100011030,
100211030,
100211030,
100211030,
100214020,
100214020,
100214020,
100011040,
100011040,
100011040,
100211040,
100211040,
100211040,
100011050,
100011050,
100011050,
100211050,
100211050,
100211050,
100221020,
100221020,
100221020
]
},
{
"id": 93,
"class_id": 3,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100314010,
100314010,
100314010,
100011020,
100011020,
100011020,
100012010,
100311010,
100311010,
100311010,
100314030,
100314030,
100314030,
100314020,
100314020,
100314020,
100314040,
100314040,
100314040,
100011030,
100011030,
100011030,
100314050,
100314050,
100314050,
100011040,
100011040,
100011040,
100314060,
100314060,
100314060,
100011050,
100011050,
100011050,
100314070,
100314070,
100314070,
100321010,
100321010,
100321010
]
},
{
"id": 94,
"class_id": 4,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100414020,
100414020,
100414020,
100011020,
100011020,
100011020,
100012010,
100411010,
100411010,
100411010,
100414010,
100414010,
100414010,
100011030,
100011030,
100011030,
100411050,
100411050,
100411050,
100011040,
100011040,
100011040,
100411030,
100411030,
100411030,
100414030,
100414030,
100414030,
100011050,
100011050,
100011050,
100411020,
100411020,
100411020,
100411040,
100411040,
100411040,
100421020,
100421020,
100421020
]
},
{
"id": 95,
"class_id": 5,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100011020,
100011020,
100011020,
100012010,
100511010,
100511010,
100511010,
100511020,
100511020,
100511020,
100514010,
100514010,
100514010,
100011030,
100011030,
100011030,
100511030,
100511030,
100511030,
100011040,
100011040,
100011040,
100511040,
100511040,
100511040,
100011050,
100011050,
100011050,
100511050,
100511050,
100511050,
100514020,
100514020,
100514020,
100511060,
100511060,
100511060,
100521030,
100521030,
100521030
]
},
{
"id": 96,
"class_id": 6,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100011020,
100011020,
100011020,
100012010,
100611010,
100611010,
100611010,
100611020,
100611020,
100611020,
100614010,
100614010,
100614010,
100614020,
100614020,
100614020,
100011030,
100011030,
100011030,
100611030,
100611030,
100611030,
100011040,
100011040,
100011040,
100611050,
100611050,
100611050,
100614030,
100614030,
100614030,
100011050,
100011050,
100011050,
100611040,
100611040,
100611040,
100621010,
100621010,
100621010
]
},
{
"id": 97,
"class_id": 7,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100713020,
100713020,
100713020,
100011020,
100011020,
100011020,
100012010,
100713010,
100713010,
100713010,
100711010,
100711010,
100711010,
100714010,
100714010,
100714010,
100714020,
100714020,
100714020,
100011030,
100011030,
100011030,
100713030,
100713030,
100713030,
100011040,
100011040,
100011040,
100011050,
100011050,
100011050,
100723010,
100723010,
100723010,
100714030,
100714030,
100714030,
100711020,
100711020,
100711020
]
},
{
"id": 98,
"class_id": 8,
"sleeve_id": 3000011,
"leader_skin_id": 0,
"deck_name": "Default",
"card_id_array": [
100011020,
100011020,
100011020,
100012010,
100811020,
100811020,
100811020,
100811060,
100811060,
100811060,
100811070,
100811070,
100811070,
100814010,
100814010,
100814010,
100011030,
100011030,
100011030,
100811010,
100811010,
100811010,
100811030,
100811030,
100811030,
100011040,
100011040,
100011040,
100811040,
100811040,
100811040,
100824010,
100824010,
100824010,
100011050,
100011050,
100011050,
100811050,
100811050,
100811050
]
}
]

View File

@@ -0,0 +1,60 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using SVSim.Bootstrap.Models.Seed;
using SVSim.Database;
using SVSim.Database.Models;
namespace SVSim.Bootstrap.Importers;
/// <summary>
/// Idempotent upsert of default decks from <c>seeds/default-decks.json</c>. Warns on orphan card
/// references (card_id not in Cards table) but never fails — CardImporter must run first for a
/// clean warning-free run. Rows missing from the seed are LEFT INTACT.
/// </summary>
public class DefaultDeckImporter
{
public async Task<int> ImportAsync(SVSimDbContext context, string seedDir)
{
var seed = SeedLoader.LoadList<DefaultDeckSeed>(Path.Combine(seedDir, "default-decks.json"));
if (seed.Count == 0)
{
Console.WriteLine("[DefaultDeckImporter] No seed rows; skipping.");
return 0;
}
var existing = await context.DefaultDecks.ToDictionaryAsync(e => e.Id);
var knownCards = new HashSet<long>(await context.Cards.Select(c => c.Id).ToListAsync());
int created = 0, updated = 0, orphans = 0;
foreach (var s in seed)
{
if (s.Id == 0) continue;
var entry = existing.TryGetValue(s.Id, out var ex) ? ex : new DefaultDeckEntry { Id = s.Id };
entry.ClassId = s.ClassId;
entry.SleeveId = s.SleeveId;
entry.LeaderSkinId = s.LeaderSkinId;
entry.DeckName = s.DeckName;
entry.CardIdArray = JsonSerializer.Serialize(s.CardIdArray);
// Orphan count against card master — informational, never throws.
foreach (var cardId in s.CardIdArray)
{
if (!knownCards.Contains(cardId)) orphans++;
}
if (ex is null) { context.DefaultDecks.Add(entry); existing[s.Id] = entry; created++; }
else updated++;
}
await context.SaveChangesAsync();
WarnOrphans("DefaultDecks.card_id_array", orphans);
Console.WriteLine($"[DefaultDeckImporter] +{created}/~{updated}");
return created + updated;
}
private static void WarnOrphans(string label, int count)
{
if (count > 0)
Console.Error.WriteLine($"[DefaultDeckImporter] Warning: {label} has {count} orphan card_id(s) — run CardImporter first for clean references.");
}
}

View File

@@ -10,7 +10,8 @@ namespace SVSim.Bootstrap.Importers;
/// <summary>
/// Imports prod-captured globals from <c>{capturesDir}/{endpoint}-*.json</c> snapshots into the
/// DB via idempotent upserts. Source endpoints: <c>load-index</c>, <c>mypage-index</c>, <c>deck-info</c>.
/// DB via idempotent upserts. Source endpoints: <c>load-index</c>, <c>pack-info</c>. Per-endpoint
/// seed-file importers (DefaultDeckImporter, MyPageGlobalsImporter, etc.) cover the rest.
///
/// Topological order: GameConfiguration extensions → standalone tables → card-referencing tables →
/// rotation CardSet flag update. Card-referencing importers warn on orphans (missing card rows)
@@ -27,7 +28,6 @@ public class GlobalsImporter
Console.WriteLine($"[GlobalsImporter] Loading captures from {capturesDir}...");
JsonElement? loadIndex = LoadCapture(capturesDir, "load-index");
JsonElement? deckInfo = LoadCapture(capturesDir, "deck-info");
JsonElement? packInfo = LoadCapture(capturesDir, "pack-info");
int total = 0;
@@ -50,11 +50,6 @@ public class GlobalsImporter
total += await UpdateRotationCardSetFlags(context, loadIndex.Value);
}
if (deckInfo.HasValue)
{
total += await ImportDefaultDecks(context, deckInfo.Value);
}
if (packInfo.HasValue)
{
total += await ImportPacks(context, packInfo.Value);
@@ -511,45 +506,6 @@ public class GlobalsImporter
return updated;
}
// ---------- Deck/info: Default Decks ----------
private async Task<int> ImportDefaultDecks(SVSimDbContext context, JsonElement deckInfo)
{
if (!deckInfo.TryGetProperty("default_deck_list", out var info) || info.ValueKind != JsonValueKind.Object) return 0;
var existing = await context.DefaultDecks.ToDictionaryAsync(e => e.Id);
var knownSet = new HashSet<long>(await context.Cards.Select(c => c.Id).ToListAsync());
int created = 0, updated = 0, orphans = 0;
foreach (var kv in info.EnumerateObject())
{
if (!int.TryParse(kv.Name, out int deckNo)) continue;
var v = kv.Value;
var entry = existing.TryGetValue(deckNo, out var ex) ? ex : new DefaultDeckEntry { Id = deckNo };
entry.ClassId = GetInt(v, "class_id");
entry.SleeveId = GetLong(v, "sleeve_id");
entry.LeaderSkinId = GetInt(v, "leader_skin_id");
entry.DeckName = GetString(v, "deck_name");
entry.CardIdArray = v.TryGetProperty("card_id_array", out var arr) ? Serialize(arr) : "[]";
// Count orphans against card master
if (arr.ValueKind == JsonValueKind.Array)
{
foreach (var c in arr.EnumerateArray())
{
if (c.ValueKind != JsonValueKind.Number) continue;
if (!knownSet.Contains(c.GetInt64())) orphans++;
}
}
if (ex is null) { context.DefaultDecks.Add(entry); created++; }
else updated++;
}
WarnOrphans("DefaultDecks.card_id_array", orphans);
Console.WriteLine($"[GlobalsImporter] DefaultDecks: +{created}/~{updated}");
return created + updated;
}
// ---------- Pack catalog ----------
/// <summary>

View File

@@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
namespace SVSim.Bootstrap.Models.Seed;
public sealed class DefaultDeckSeed
{
[JsonPropertyName("id")] public int Id { get; set; }
[JsonPropertyName("class_id")] public int ClassId { get; set; }
[JsonPropertyName("sleeve_id")] public long SleeveId { get; set; }
[JsonPropertyName("leader_skin_id")] public int LeaderSkinId { get; set; }
[JsonPropertyName("deck_name")] public string DeckName { get; set; } = "";
[JsonPropertyName("card_id_array")] public List<long> CardIdArray { get; set; } = new();
}

View File

@@ -90,6 +90,8 @@ public static class Program
await mypage.ImportMasterPointRankingPeriodAsync(context, opts.SeedDir);
await mypage.ImportSpecialDeckFormatsAsync(context, opts.SeedDir);
await new DefaultDeckImporter().ImportAsync(context, opts.SeedDir);
// BuildDeck pipeline: series CSV → catalog JSON → package CSV. Catalog must run after
// series CSV (FK on products → series) and before package CSV (so the catalog-side
// enriched rows take precedence over stub creation).