CREATE TABLE events (
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    title       TEXT NOT NULL,
    category    TEXT NOT NULL DEFAULT 'event',
    book_ref    TEXT NOT NULL,
    chapter_ref TEXT NOT NULL,
    summary     TEXT NOT NULL,
    content     TEXT NOT NULL,
    sort_order  INTEGER NOT NULL DEFAULT 0
);
---
CREATE TABLE people (
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        TEXT NOT NULL,
    role        TEXT NOT NULL,
    book_ref    TEXT NOT NULL,
    summary     TEXT NOT NULL,
    content     TEXT NOT NULL,
    sort_order  INTEGER NOT NULL DEFAULT 0
);
---
CREATE TABLE quiz_questions (
    id           INTEGER PRIMARY KEY AUTOINCREMENT,
    entity_type  TEXT NOT NULL CHECK(entity_type IN ('event','person')),
    entity_id    INTEGER NOT NULL,
    question     TEXT NOT NULL,
    option_a     TEXT NOT NULL,
    option_b     TEXT NOT NULL,
    option_c     TEXT NOT NULL,
    option_d     TEXT NOT NULL,
    correct      TEXT NOT NULL CHECK(correct IN ('a','b','c','d')),
    explanation  TEXT NOT NULL,
    sort_order   INTEGER NOT NULL DEFAULT 0
);
CREATE INDEX idx_quiz_q_entity ON quiz_questions(entity_type, entity_id);
---
CREATE TABLE quiz_results (
    id           INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id      INTEGER NOT NULL REFERENCES users(id),
    entity_type  TEXT NOT NULL,
    entity_id    INTEGER NOT NULL,
    score        INTEGER NOT NULL,
    total        INTEGER NOT NULL,
    answers      TEXT NOT NULL,
    taken_at     DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_quiz_r_user   ON quiz_results(user_id);
---
Error: in prepare, no such column: name
  SELECT id, name, sort_order FROM events LIMIT 5;
             ^--- error here
