from sqlalchemy import Column, ForeignKey, Integer, String, Text, UniqueConstraint from app.database import Base class QuestionMedia(Base): """One figure on a question. A figure is a row rather than a path so it can be labelled, ordered, and reused: the same radiograph can illustrate two questions without being stored twice, and the bank knows where each one is used. """ __tablename__ = "question_media" __table_args__ = (UniqueConstraint("question_id", "media_id", "role", name="uq_question_media"),) id = Column(Integer, primary_key=True, index=True) question_id = Column(Integer, ForeignKey("questions.id", ondelete="CASCADE"), nullable=False, index=True) media_id = Column(Integer, ForeignKey("media_assets.id", ondelete="CASCADE"), nullable=False, index=True) # stem | explanation. A figure that gives the answer away must never sit # beside the question, which is the mistake this area started with. role = Column(String(20), nullable=False, default="stem") # What the prose calls it, so "shown in Figure 1" refers to something. label = Column(String(80), nullable=True) caption = Column(Text, nullable=True) position = Column(Integer, default=0)