"""Add event_type to assignments

Revision ID: 005_add_assignment_event_type
Revises: 004_add_events
Create Date: 2024-12-14

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision: str = '005_add_assignment_event_type'
down_revision: Union[str, None] = '004_add_events'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # Add event_type column to assignments if it doesn't exist
    conn = op.get_bind()
    inspector = sa.inspect(conn)
    columns = [col['name'] for col in inspector.get_columns('assignments')]

    if 'event_type' not in columns:
        op.add_column(
            'assignments',
            sa.Column('event_type', sa.String(30), nullable=True)
        )


def downgrade() -> None:
    op.drop_column('assignments', 'event_type')
