"""Add recurrence fields to events and event_exceptions table

Revision ID: 15c357c0cf31
Revises: b5a6c3d4e7f8
Create Date: 2025-10-12 05:24:43.936743

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '15c357c0cf31'
down_revision: Union[str, None] = 'b5a6c3d4e7f8'
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('event_exceptions',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('event_id', sa.Integer(), nullable=False),
    sa.Column('exception_date', sa.Date(), nullable=False),
    sa.Column('is_skipped', sa.Boolean(), nullable=False),
    sa.Column('override_title', sa.String(length=100), nullable=True),
    sa.Column('override_description', sa.Text(), nullable=True),
    sa.Column('override_start', sa.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('override_end', sa.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
    sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
    sa.ForeignKeyConstraint(['event_id'], ['events.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_event_exceptions_event_id'), 'event_exceptions', ['event_id'], unique=False)
    op.create_index(op.f('ix_event_exceptions_exception_date'), 'event_exceptions', ['exception_date'], unique=False)
    op.drop_index(op.f('ix_conv_source_event_media_id'), table_name='conversions')
    op.create_index(op.f('ix_conversions_source_event_media_id'), 'conversions', ['source_event_media_id'], unique=False)
    op.add_column('events', sa.Column('recurrence_rule', sa.String(length=255), nullable=True))
    op.add_column('events', sa.Column('recurrence_end', sa.TIMESTAMP(timezone=True), nullable=True))
    op.create_index(op.f('ix_events_recurrence_end'), 'events', ['recurrence_end'], unique=False)
    op.create_index(op.f('ix_events_recurrence_rule'), 'events', ['recurrence_rule'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_events_recurrence_rule'), table_name='events')
    op.drop_index(op.f('ix_events_recurrence_end'), table_name='events')
    op.drop_column('events', 'recurrence_end')
    op.drop_column('events', 'recurrence_rule')
    op.drop_index(op.f('ix_conversions_source_event_media_id'), table_name='conversions')
    op.create_index(op.f('ix_conv_source_event_media_id'), 'conversions', ['source_event_media_id'], unique=False)
    op.drop_index(op.f('ix_event_exceptions_exception_date'), table_name='event_exceptions')
    op.drop_index(op.f('ix_event_exceptions_event_id'), table_name='event_exceptions')
    op.drop_table('event_exceptions')
    # ### end Alembic commands ###
