Add a back_image_uri column to printings, populated during ingest from a card's second card_faces image (only present for transform/MDFC/ reversible cards — split/adventure cards share one combined image and correctly get ""). Plumb it through CardRef across every query path (search, library, filters, deck contents) via the same printing row, using a shared deterministic ORDER BY so front/back always come from one printing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
58 lines
2.5 KiB
SQL
58 lines
2.5 KiB
SQL
-- Schema for reference.db: read-only card data built from Scryfall bulk.
|
|
-- Applied against a connection whose `main` database IS the reference db
|
|
-- (the ingester opens reference.db directly; at runtime it is ATTACHed as `ref`).
|
|
|
|
CREATE TABLE IF NOT EXISTS oracle_cards (
|
|
oracle_id TEXT PRIMARY KEY,
|
|
name TEXT NOT NULL,
|
|
name_lower TEXT NOT NULL, -- for cheap case-insensitive substring
|
|
mana_value REAL NOT NULL DEFAULT 0,
|
|
colors INTEGER NOT NULL DEFAULT 0, -- WUBRG bitmask
|
|
color_identity INTEGER NOT NULL DEFAULT 0, -- WUBRG bitmask
|
|
type_line TEXT NOT NULL DEFAULT '',
|
|
oracle_text TEXT NOT NULL DEFAULT ''
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_oracle_name_lower ON oracle_cards(name_lower);
|
|
CREATE INDEX IF NOT EXISTS idx_oracle_ci ON oracle_cards(color_identity);
|
|
CREATE INDEX IF NOT EXISTS idx_oracle_mv ON oracle_cards(mana_value);
|
|
|
|
-- Normalized attribute tables for fast type/subtype/keyword filtering.
|
|
CREATE TABLE IF NOT EXISTS card_types (
|
|
oracle_id TEXT NOT NULL,
|
|
type TEXT NOT NULL
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_card_types_type ON card_types(type);
|
|
CREATE INDEX IF NOT EXISTS idx_card_types_oid ON card_types(oracle_id);
|
|
|
|
CREATE TABLE IF NOT EXISTS card_subtypes (
|
|
oracle_id TEXT NOT NULL,
|
|
subtype TEXT NOT NULL
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_card_subtypes_sub ON card_subtypes(subtype);
|
|
CREATE INDEX IF NOT EXISTS idx_card_subtypes_oid ON card_subtypes(oracle_id);
|
|
|
|
CREATE TABLE IF NOT EXISTS card_keywords (
|
|
oracle_id TEXT NOT NULL,
|
|
keyword TEXT NOT NULL
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_card_keywords_kw ON card_keywords(keyword);
|
|
CREATE INDEX IF NOT EXISTS idx_card_keywords_oid ON card_keywords(oracle_id);
|
|
|
|
-- One row per printing (default-language bulk).
|
|
CREATE TABLE IF NOT EXISTS printings (
|
|
scryfall_id TEXT PRIMARY KEY,
|
|
oracle_id TEXT NOT NULL,
|
|
set_code TEXT NOT NULL DEFAULT '',
|
|
collector_number TEXT NOT NULL DEFAULT '',
|
|
finishes TEXT NOT NULL DEFAULT '', -- comma-joined, e.g. "nonfoil,foil"
|
|
rarity TEXT NOT NULL DEFAULT '',
|
|
image_uri TEXT NOT NULL DEFAULT '',
|
|
back_image_uri TEXT NOT NULL DEFAULT '' -- transform/MDFC/reversible back face
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_printings_oid ON printings(oracle_id);
|
|
|
|
-- Secondary trigram FTS index over names (typo-tolerant fallback; the primary
|
|
-- interactive search is the in-memory nucleo matcher).
|
|
CREATE VIRTUAL TABLE IF NOT EXISTS oracle_names_fts
|
|
USING fts5(name, oracle_id UNINDEXED, tokenize = 'trigram');
|