CREATE TABLE IF NOT EXISTS exam (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  course TEXT NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS question (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  exam_id INTEGER NOT NULL,
  title TEXT NOT NULL,
  max_score INTEGER NOT NULL DEFAULT 100,
  rubric TEXT,
  FOREIGN KEY (exam_id) REFERENCES exam(id)
);

CREATE TABLE IF NOT EXISTS history (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  question_id INTEGER DEFAULT 0,
  image_path TEXT DEFAULT '',
  student_answer TEXT DEFAULT '',
  ai_score REAL DEFAULT 0,
  teacher_score REAL DEFAULT 0,
  confidence REAL DEFAULT 0,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
