chrysopedia/alembic/versions/012_multi_source_format.py
jlightner bd0dbb4df9 feat: Added body_sections_format column, technique_page_videos associat…
- "alembic/versions/012_multi_source_format.py"
- "backend/models.py"
- "backend/schemas.py"

GSD-Task: S03/T01
2026-04-03 01:16:31 +00:00

55 lines
1.7 KiB
Python

"""Add body_sections_format column and technique_page_videos association table.
Supports multi-source technique pages: tracks which source videos contributed
to a technique page, and marks the body_sections format version for future
structured section layouts.
Revision ID: 012_multi_source_fmt
Revises: 011_cls_cache_rerun
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID
revision = "012_multi_source_fmt"
down_revision = "011_cls_cache_rerun"
branch_labels = None
depends_on = None
def upgrade() -> None:
# Add body_sections_format to technique_pages with default for existing rows
op.add_column(
"technique_pages",
sa.Column(
"body_sections_format",
sa.String(20),
nullable=False,
server_default="v1",
),
)
# Create technique_page_videos association table
op.create_table(
"technique_page_videos",
sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.func.gen_random_uuid()),
sa.Column(
"technique_page_id",
UUID(as_uuid=True),
sa.ForeignKey("technique_pages.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column(
"source_video_id",
UUID(as_uuid=True),
sa.ForeignKey("source_videos.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("added_at", sa.TIMESTAMP(), server_default=sa.func.now(), nullable=False),
sa.UniqueConstraint("technique_page_id", "source_video_id", name="uq_page_video"),
)
def downgrade() -> None:
op.drop_table("technique_page_videos")
op.drop_column("technique_pages", "body_sections_format")