"""Figures on a question: many of them, labelled, and each a real image record. Revision ID: f0a1b2c3d4e5 Revises: e9f0a1b2c3d4 """ import sqlalchemy as sa from alembic import op from sqlalchemy import inspect revision = "f0a1b2c3d4e5" down_revision = "e9f0a1b2c3d4" branch_labels = None depends_on = None def upgrade(): # A question could carry exactly one stem image and one explanation image, # held as a bare path with no title, no legend and no way to refer to it # from the text. This makes a figure a row: it points at an image in the # bank, carries the label the prose calls it by, and there can be several. if "question_media" not in inspect(op.get_bind()).get_table_names(): op.create_table( "question_media", sa.Column("id", sa.Integer, primary_key=True), sa.Column("question_id", sa.Integer, sa.ForeignKey("questions.id", ondelete="CASCADE"), nullable=False, index=True), sa.Column("media_id", sa.Integer, sa.ForeignKey("media_assets.id", ondelete="CASCADE"), nullable=False, index=True), # Where it belongs. A figure that illustrates the answer must not # appear beside the stem, which is the mistake this whole area had. sa.Column("role", sa.String(20), nullable=False, server_default="stem"), # What the prose calls it — "Figure 1" — so the text can say # "shown in Figure 1" and mean something. sa.Column("label", sa.String(80), nullable=True), sa.Column("caption", sa.Text, nullable=True), sa.Column("position", sa.Integer, server_default="0"), sa.UniqueConstraint("question_id", "media_id", "role", name="uq_question_media"), ) def downgrade(): op.drop_table("question_media")