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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user