-- Migration 006: Add author profile discovery table
--
-- Per ADR-061 and v1.2.0 Phase 2:
-- Stores author information discovered from IndieAuth profile URLs
-- Enables automatic h-card population for Microformats2 compliance
--
-- Features:
-- - Caches author h-card data from IndieAuth 'me' URL
-- - 24-hour TTL for cache freshness (per developer Q&A Q14)
-- - Graceful fallback when discovery fails
-- - Supports rel-me links for identity verification

-- Create author profile table
CREATE TABLE IF NOT EXISTS author_profile (
    me TEXT PRIMARY KEY,           -- IndieAuth 'me' URL (user identity)
    name TEXT,                      -- h-card p-name
    photo TEXT,                     -- h-card u-photo URL
    url TEXT,                       -- h-card u-url (canonical)
    note TEXT,                      -- h-card p-note (bio)
    rel_me_links TEXT,              -- JSON array of rel-me URLs
    discovered_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    cached_until DATETIME NOT NULL  -- 24-hour cache per Q&A Q14
);

-- Index for cache expiry checks
CREATE INDEX IF NOT EXISTS idx_author_profile_cache
ON author_profile(cached_until);
