This commit is contained in:
Chris Kruining 2026-02-05 11:34:57 +01:00
parent 0801ceee6a
commit 54ba7496c6
No known key found for this signature in database
GPG key ID: EB894A3560CCCAD2
19 changed files with 1765 additions and 591 deletions

View file

@ -313,22 +313,63 @@ public MatchResult Match(byte[] queryHash, CardDatabase db)
### Database Schema
The schema mirrors Scryfall's data model with three main tables:
```sql
CREATE TABLE cards (
id TEXT PRIMARY KEY, -- Scryfall ID
oracle_id TEXT NOT NULL,
-- Abstract game cards (oracle)
CREATE TABLE oracles (
id TEXT PRIMARY KEY, -- Scryfall oracle_id
name TEXT NOT NULL,
set_code TEXT NOT NULL,
collector_number TEXT,
illustration_id TEXT,
image_url TEXT,
art_hash BLOB, -- 256-bit hash of art region
full_hash BLOB, -- 256-bit hash of full card
color_hash BLOB -- 768-bit color-aware hash
mana_cost TEXT,
cmc REAL,
type_line TEXT,
oracle_text TEXT,
colors TEXT, -- JSON array
color_identity TEXT, -- JSON array
keywords TEXT, -- JSON array
reserved INTEGER DEFAULT 0,
legalities TEXT, -- JSON object
power TEXT,
toughness TEXT
);
CREATE INDEX idx_cards_oracle ON cards(oracle_id);
CREATE INDEX idx_cards_illustration ON cards(illustration_id);
-- MTG sets
CREATE TABLE sets (
id TEXT PRIMARY KEY, -- Scryfall set id
code TEXT NOT NULL UNIQUE, -- e.g., "lea", "mh2"
name TEXT NOT NULL, -- e.g., "Limited Edition Alpha"
set_type TEXT, -- e.g., "expansion", "core"
released_at TEXT,
card_count INTEGER,
icon_svg_uri TEXT,
digital INTEGER DEFAULT 0,
parent_set_code TEXT,
block TEXT
);
-- Card printings with perceptual hashes
CREATE TABLE cards (
id TEXT PRIMARY KEY, -- Scryfall card ID (printing)
oracle_id TEXT NOT NULL, -- FK to oracles
set_id TEXT NOT NULL, -- FK to sets
set_code TEXT,
name TEXT NOT NULL,
collector_number TEXT,
rarity TEXT,
artist TEXT,
illustration_id TEXT, -- Same across printings with identical art
image_uri TEXT,
hash BLOB, -- Perceptual hash for matching
lang TEXT DEFAULT 'en',
prices_usd REAL,
prices_usd_foil REAL,
FOREIGN KEY (oracle_id) REFERENCES oracles(id),
FOREIGN KEY (set_id) REFERENCES sets(id)
);
CREATE INDEX idx_cards_oracle_id ON cards(oracle_id);
CREATE INDEX idx_cards_set_id ON cards(set_id);
CREATE INDEX idx_cards_name ON cards(name);
```
### Phase 2: Enhanced (Add OCR Fallback)