"""Initial schema

Revision ID: 3a0ff6bfaed1
Revises: 
Create Date: 2025-08-30 06:23:25.706926

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = '3a0ff6bfaed1'
down_revision: Union[str, Sequence[str], None] = None
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('media_files',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('filename', sa.String(length=255), nullable=False),
    sa.Column('file_size', sa.BigInteger(), nullable=False),
    sa.Column('duration', sa.Float(), nullable=True),
    sa.Column('mime_type', sa.String(length=100), nullable=True),
    sa.Column('source_path', sa.Text(), nullable=False),
    sa.Column('local_path', sa.Text(), nullable=True),
    sa.Column('file_hash', sa.String(length=64), nullable=True),
    sa.Column('file_metadata', postgresql.JSONB(astext_type=sa.Text()), 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_media_files_file_hash'), 'media_files', ['file_hash'], unique=True)
    op.create_index(op.f('ix_media_files_filename'), 'media_files', ['filename'], unique=False)
    op.create_table('processing_jobs',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('job_type', sa.String(length=50), nullable=False),
    sa.Column('status', sa.String(length=20), nullable=False),
    sa.Column('config', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('file_patterns', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('total_items', sa.Integer(), nullable=True),
    sa.Column('processed_items', sa.Integer(), nullable=True),
    sa.Column('successful_items', sa.Integer(), nullable=True),
    sa.Column('failed_items', sa.Integer(), nullable=True),
    sa.Column('started_at', sa.DateTime(), nullable=True),
    sa.Column('completed_at', sa.DateTime(), nullable=True),
    sa.Column('error_message', sa.Text(), 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_processing_jobs_job_type'), 'processing_jobs', ['job_type'], unique=False)
    op.create_index(op.f('ix_processing_jobs_status'), 'processing_jobs', ['status'], unique=False)
    op.create_table('transcription_jobs',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('media_file_id', sa.UUID(), nullable=False),
    sa.Column('status', sa.String(length=20), nullable=False),
    sa.Column('priority', sa.Integer(), nullable=True),
    sa.Column('model_config', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('processing_options', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('started_at', sa.DateTime(), nullable=True),
    sa.Column('completed_at', sa.DateTime(), nullable=True),
    sa.Column('processing_time', sa.Float(), nullable=True),
    sa.Column('error_message', sa.Text(), nullable=True),
    sa.Column('retry_count', sa.Integer(), nullable=True),
    sa.Column('max_retries', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['media_file_id'], ['media_files.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_transcription_jobs_media_file_id'), 'transcription_jobs', ['media_file_id'], unique=False)
    op.create_index(op.f('ix_transcription_jobs_priority'), 'transcription_jobs', ['priority'], unique=False)
    op.create_index(op.f('ix_transcription_jobs_status'), 'transcription_jobs', ['status'], unique=False)
    op.create_table('transcription_results',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('job_id', sa.UUID(), nullable=False),
    sa.Column('media_file_id', sa.UUID(), nullable=False),
    sa.Column('pipeline_version', sa.String(length=10), nullable=False),
    sa.Column('content', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('segments', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('confidence_scores', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('speaker_info', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('accuracy', sa.Float(), nullable=True),
    sa.Column('word_count', sa.Integer(), nullable=True),
    sa.Column('processing_time', sa.Float(), nullable=True),
    sa.Column('model_used', sa.String(length=100), nullable=True),
    sa.Column('model_config', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('parent_result_id', sa.UUID(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('version', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['job_id'], ['transcription_jobs.id'], ),
    sa.ForeignKeyConstraint(['media_file_id'], ['media_files.id'], ),
    sa.ForeignKeyConstraint(['parent_result_id'], ['transcription_results.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_transcription_results_job_id'), 'transcription_results', ['job_id'], unique=False)
    op.create_index(op.f('ix_transcription_results_media_file_id'), 'transcription_results', ['media_file_id'], unique=False)
    op.create_index(op.f('ix_transcription_results_parent_result_id'), 'transcription_results', ['parent_result_id'], unique=False)
    op.create_index(op.f('ix_transcription_results_pipeline_version'), 'transcription_results', ['pipeline_version'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_transcription_results_pipeline_version'), table_name='transcription_results')
    op.drop_index(op.f('ix_transcription_results_parent_result_id'), table_name='transcription_results')
    op.drop_index(op.f('ix_transcription_results_media_file_id'), table_name='transcription_results')
    op.drop_index(op.f('ix_transcription_results_job_id'), table_name='transcription_results')
    op.drop_table('transcription_results')
    op.drop_index(op.f('ix_transcription_jobs_status'), table_name='transcription_jobs')
    op.drop_index(op.f('ix_transcription_jobs_priority'), table_name='transcription_jobs')
    op.drop_index(op.f('ix_transcription_jobs_media_file_id'), table_name='transcription_jobs')
    op.drop_table('transcription_jobs')
    op.drop_index(op.f('ix_processing_jobs_status'), table_name='processing_jobs')
    op.drop_index(op.f('ix_processing_jobs_job_type'), table_name='processing_jobs')
    op.drop_table('processing_jobs')
    op.drop_index(op.f('ix_media_files_filename'), table_name='media_files')
    op.drop_index(op.f('ix_media_files_file_hash'), table_name='media_files')
    op.drop_table('media_files')
    # ### end Alembic commands ###
