-- Migration: Bilder-Pool pro Kategorie statt Einzel-Cache pro Restaurant.
-- Einmalig ausfuehren: sqlite3 db/yumder.db < db/migrations/003_image_pool.sql

CREATE TABLE IF NOT EXISTS image_pool (
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    category    TEXT NOT NULL,          -- z.B. 'pizza', 'ice_cream', 'kebab'
    image_url   TEXT NOT NULL,
    fetched_at  TEXT NOT NULL DEFAULT (datetime('now')),
    UNIQUE(category, image_url)
);

CREATE INDEX IF NOT EXISTS idx_image_pool_category ON image_pool(category);

-- Alte, evtl. falsch gecachte Einzel-Bilder zuruecksetzen, damit ab jetzt
-- ausschliesslich aus dem Pool gezogen wird.
UPDATE restaurants SET fallback_image_url = NULL, image_source_used = NULL
WHERE image_source_used = 'fallback';
