"""Add YouTubeVideo model

Revision ID: b36380486760
Revises: 3a0ff6bfaed1
Create Date: 2025-08-30 16:13:59.777911

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'b36380486760'
down_revision: Union[str, Sequence[str], None] = '3a0ff6bfaed1'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('youtube_videos',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('youtube_id', sa.String(length=20), nullable=False),
    sa.Column('title', sa.String(length=500), nullable=False),
    sa.Column('channel', sa.String(length=200), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('duration_seconds', sa.Integer(), nullable=False),
    sa.Column('url', sa.String(length=500), nullable=False),
    sa.Column('metadata_extracted_at', sa.DateTime(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_youtube_videos_youtube_id'), 'youtube_videos', ['youtube_id'], unique=True)
    op.add_column('media_files', sa.Column('youtube_video_id', sa.UUID(), nullable=True))
    op.create_index(op.f('ix_media_files_youtube_video_id'), 'media_files', ['youtube_video_id'], unique=False)
    op.create_foreign_key(None, 'media_files', 'youtube_videos', ['youtube_video_id'], ['id'])
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'media_files', type_='foreignkey')
    op.drop_index(op.f('ix_media_files_youtube_video_id'), table_name='media_files')
    op.drop_column('media_files', 'youtube_video_id')
    op.drop_index(op.f('ix_youtube_videos_youtube_id'), table_name='youtube_videos')
    op.drop_table('youtube_videos')
    # ### end Alembic commands ###
