from datetime import datetime from sqlalchemy import JSON, Column, DateTime, ForeignKey, Integer, String, UniqueConstraint from app.database import Base class Exam(Base): """A study objective — the top of the hierarchy, above systems and disciplines. A question can sit under more than one exam (paediatric cardiology counts for both a paediatrics board and a step exam), so membership is a link table rather than a column on the question. """ __tablename__ = "exams" id = Column(Integer, primary_key=True, index=True) slug = Column(String(80), unique=True, nullable=False, index=True) name = Column(String(160), nullable=False) sort_order = Column(Integer, default=100) is_active = Column(Integer, default=1) # 0 hides it from the switcher # Objectives are picked from families — USMLE, COMLEX, boards — because a # flat list of every exam is not a choice anyone can make. family = Column(String(80), nullable=True) description = Column(String(300), nullable=True) # Which article views this objective shows. Someone revising a basic-science # step has no use for bedside dosing, and a view they can open but must never # act on is worse than one they were never offered. Null means all of them. article_views = Column(JSON, nullable=True) created_at = Column(DateTime, default=datetime.utcnow) class QuestionExamLink(Base): __tablename__ = "question_exam_links" __table_args__ = (UniqueConstraint("question_id", "exam_id", name="uq_question_exam"),) id = Column(Integer, primary_key=True, index=True) question_id = Column(Integer, ForeignKey("questions.id", ondelete="CASCADE"), nullable=False, index=True) exam_id = Column(Integer, ForeignKey("exams.id", ondelete="CASCADE"), nullable=False, index=True)