Skip to content

feat(scryfall): ingest curated Japanese collector printings#66

Merged
jcserv merged 2 commits into
mainfrom
feat-add-jp-collector-printings
Jun 9, 2026
Merged

feat(scryfall): ingest curated Japanese collector printings#66
jcserv merged 2 commits into
mainfrom
feat-add-jp-collector-printings

Conversation

@jcserv

@jcserv jcserv commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Description

Adds a post-bulk enrichment step that pulls curated Japanese collector printings from the Scryfall /cards/search API and upserts them as Printings against the already-ingested English Cards. Japanese printings keep their English name (the new printed_name column holds the Japanese title), so each links to its existing Card by name — no new Card rows, no oracle/legality drift.

The set of queries lives in lib/scryfall/jp-collector-queries.ts as the single source of truth. The art:japanese-exclusive-art tag isolates exclusive-art printings across every set with no per-set maintenance; NEO is a named supplement because its soft-glow / ukiyo-e treatments reuse the English art and fall outside that tag.

Also fixes a latent bug: token upsert targeted card_token (singular) but the CardToken model is @@map'd to card_tokens — a singular target throws 42P01 in prod. Now guarded by a test asserting the table name.

Fixes: #62

Checklist

  • Tests pass (pnpm test) and lint is clean
  • New behavior is covered by tests
  • No revalidate / dynamic / unstable_cache — used 'use cache' + cacheLife/cacheTag
  • <Link> imported from app/_components/link.tsx, not next/link
  • Suspense fallbacks reserve layout space (explicit heights)

Screenshots / notes

graph TD
    Q[jp-collector-queries.ts] --> ICP[ingestCollectorPrintings 'use step']
    ICP --> FSS[fetchScryfallSearch<br/>paginate + 404 = empty]
    FSS --> SC[Scryfall /cards/search<br/>unique=prints]
    ICP --> DEDUPE[dedupe by scryfallId]
    DEDUPE --> NAMES[resolve cardId by English name]
    NAMES --> DIFF[buildPrintings → diffPrintings]
    DIFF --> WRITE[applyPrintingWrites<br/>lang + printed_name]
    WF[scryfallIngestWorkflow] -->|after bulk upsert,<br/>before checkpoint| ICP
Loading

Schema

  • prisma/schema.prisma, prisma/migrations/.../migration.sql — add lang (NOT NULL DEFAULT 'en') and nullable printed_name to Printing.

Mapping

  • lib/scryfall/schema.ts — accept optional printed_name from Scryfall payloads.
  • lib/scryfall/map.ts — map lang and printed_name into PrintingCreateData (both feed the content-hash version).
  • lib/scryfall/jp-collector-queries.ts — new curated query list (source of truth).

Workflow

  • workflows/scryfall/steps.ts — new ingestCollectorPrintings step + fetchScryfallSearch paginator; lang/printed_name threaded through the printing upsert SQL; fix card_tokencard_tokens in token upsert.
  • workflows/scryfall/ingest.ts — invoke the step after bulk upsert, fold its stats in; lock release / staging cleanup still run via finally.

Testing

pnpm test. New coverage:

  • map: lang/printed_name defaults, JP mapping, and version sensitivity to each.
  • steps ingestCollectorPrintings: happy path (links JP printings to English Cards), next_page pagination, skip printings with no matching Card, and 404-as-empty (no Card lookup).
  • steps token guard: asserts upsert targets card_tokens, not card_token.
  • ingest: step runs in order between upsert and commitScryfallCheckpoint.

Enrich the bulk ingest with Japanese-exclusive-art and Kamigawa
full-art printings pulled from the Scryfall search API. These link to
existing English Cards by name, so no new Card rows or oracle/legality
drift — only Printings gain `lang` and `printed_name`.

Key changes:
- Add `lang` + `printed_name` to Printing model and map them from the
  Scryfall card payload (both feed the version hash)
- Add `ingestCollectorPrintings` step running after bulk upsert and
  before the checkpoint commit, paginating search and deduping by
  scryfallId
- Add JP_COLLECTOR_QUERIES as the curated source of search queries
- Treat a 404 search response as an empty result, not an error
- Fix token upsert target table: card_token -> card_tokens (@@Map'd
  plural; singular threw 42P01 in prod)
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@jcserv, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 30 minutes and 14 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4b43a314-b7d7-4d23-a497-ace3d1aa5665

📥 Commits

Reviewing files that changed from the base of the PR and between 53d0385 and cfd2028.

📒 Files selected for processing (12)
  • docs/runbook/ingest.md
  • lib/scryfall/__tests__/map.test.ts
  • lib/scryfall/filter.ts
  • lib/scryfall/jp-collector-queries.ts
  • lib/scryfall/map.ts
  • lib/scryfall/schema.ts
  • prisma/migrations/20260608223646_printing_lang/migration.sql
  • prisma/schema.prisma
  • workflows/scryfall/__tests__/ingest.test.ts
  • workflows/scryfall/__tests__/steps.test.ts
  • workflows/scryfall/ingest.ts
  • workflows/scryfall/steps.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-add-jp-collector-printings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jcserv jcserv self-assigned this Jun 9, 2026
A search-API outage in the JP collector-printing enrichment step threw
before the checkpoint commit, stranding the checkpoint and forcing the
next cron to re-download the full ~500MB bulk. Make enrichment
best-effort and harden its filtering and tests.

Key changes:
- ingest: wrap ingestCollectorPrintings in try/catch + logWarn so the
  checkpoint commits even when JP enrichment rejects
- filter: extract language-agnostic isPaperPlayable guard and apply it in
  the JP search path to keep digital-only/token-layout printings out
- steps: add inter-query courtesy delay mirroring the inter-page delay
- tests: cover the printing UPDATE-path SQL (lang/printed_name + version
  guard) and the checkpoint-commits-on-JP-failure path; assert query
  count against JP_COLLECTOR_QUERIES.length
- runbook: document the one-time printingsUpdated spike on first deploy
@jcserv jcserv merged commit 7962e75 into main Jun 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(tweak): Ingest jp printings like strixhaven mystical archive

1 participant