Table users {
  id integer [primary key, increment]
  username varchar [not null, unique]
  email varchar [not null, unique]
  password varchar [null] // 소셜로그인 대비
  created_at timestamp [default: `now()`]
}

Table study_sessions {
  id integer [primary key, increment] // 이게 answers의 FK가 됨
  user_id integer [ref: > users.id, not null]
  category varchar [not null] // 'OS', 'NETWORK'...
  mode varchar [not null] // 'INTERVIEW', 'BATTLE'
  status varchar [not null] // 'COMPLETED'(완료), 'ABORTED'(중도포기)
  timer_setting integer
  target_question_count integer [not null] // 설정했던 목표 개수 (예: 10문제)
  solved_question_count integer [default: 0] // 실제 푼 개수 (예: 3문제 풀고 나감 -> 3)
  total_score integer // 최종 점수 저장용 (학습, 배틀)
  is_win bool [null] // 승패 기록 저장용 (배틀)
  opponent integer [ref: > users.id, null] // 배틀 상대. bot이나 battle이 아닌경우 null
  created_at timestamp [default: `now()`]
}

Table questions {
  id integer [primary key, increment]
  content text [not null]
  type varchar [not null] // 'MULTIPLE_CHOICE'(객관식), SHORT_ANSWER(단답형), LONG_ANSWER(서술형)
  category varchar [not null]
  difficulty varchar [not null] // 'EASY', 'NORMAL', 'HARD'
  writer_id integer [ref: > users.id] // 누가 만들었는지 (시스템 문제는 null 또는 관리자 id로)
  details jsonb // { "options": ["A", "B"], "answer": 1 }
  created_at timestamp [default: `now()`]
}

Table answers {
  id integer [primary key, increment]
  session_id integer [ref: > study_sessions.id]
  question_id integer [ref: > questions.id]
  user_id integer [ref: > users.id]
  content text [not null] // 사용자 답변
  elapsed_time integer
  score integer [default: 0]
  feedback_content text [null]
  created_at timestamp [default: `now()`]
}