-- Per-card chat messages (human-to-human comments).
-- Distinct from card_events (which records system events like title_changed)
-- and from /api/chat (which is the board-level LLM chat).

CREATE TABLE IF NOT EXISTS card_messages (
    id          TEXT PRIMARY KEY,
    card_id     TEXT NOT NULL,
    author_id   TEXT,
    body        TEXT NOT NULL,
    created_at  TEXT NOT NULL,
    FOREIGN KEY (card_id) REFERENCES cards(id) ON DELETE CASCADE
);

CREATE INDEX IF NOT EXISTS idx_card_messages_card ON card_messages(card_id, created_at);
