"""Initial migration

Revision ID: 65b0d87d025a
Revises: 
Create Date: 2025-10-22 09:03:08.353806

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '65b0d87d025a'
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('reports',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('symbol', sa.String(), nullable=False),
    sa.Column('market', sa.String(), nullable=False),
    sa.Column('status', sa.String(), nullable=False),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_reports_market'), 'reports', ['market'], unique=False)
    op.create_index(op.f('ix_reports_status'), 'reports', ['status'], unique=False)
    op.create_index(op.f('ix_reports_symbol'), 'reports', ['symbol'], unique=False)
    op.create_table('analysis_modules',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('report_id', sa.UUID(), nullable=False),
    sa.Column('module_type', sa.String(), nullable=False),
    sa.Column('content', sa.JSON(), nullable=True),
    sa.Column('status', sa.String(), nullable=False),
    sa.Column('error_message', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['report_id'], ['reports.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_analysis_modules_report_id'), 'analysis_modules', ['report_id'], unique=False)
    op.create_index(op.f('ix_analysis_modules_status'), 'analysis_modules', ['status'], unique=False)
    op.create_table('progress_tracking',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('report_id', sa.UUID(), nullable=False),
    sa.Column('step_name', sa.String(), nullable=False),
    sa.Column('status', sa.String(), nullable=False),
    sa.Column('started_at', sa.DateTime(), nullable=True),
    sa.Column('completed_at', sa.DateTime(), nullable=True),
    sa.Column('duration_ms', sa.Integer(), nullable=True),
    sa.Column('token_usage', sa.Integer(), nullable=True),
    sa.Column('error_message', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['report_id'], ['reports.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_progress_tracking_report_id'), 'progress_tracking', ['report_id'], unique=False)
    op.create_index(op.f('ix_progress_tracking_status'), 'progress_tracking', ['status'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_progress_tracking_status'), table_name='progress_tracking')
    op.drop_index(op.f('ix_progress_tracking_report_id'), table_name='progress_tracking')
    op.drop_table('progress_tracking')
    op.drop_index(op.f('ix_analysis_modules_status'), table_name='analysis_modules')
    op.drop_index(op.f('ix_analysis_modules_report_id'), table_name='analysis_modules')
    op.drop_table('analysis_modules')
    op.drop_index(op.f('ix_reports_symbol'), table_name='reports')
    op.drop_index(op.f('ix_reports_status'), table_name='reports')
    op.drop_index(op.f('ix_reports_market'), table_name='reports')
    op.drop_table('reports')
    # ### end Alembic commands ###
