"""add school holidays table

Revision ID: 9b7a1f2a4d2b
Revises: e6eaede720aa
Create Date: 2025-09-18 00:00:00.000000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '9b7a1f2a4d2b'
down_revision = 'e6eaede720aa'
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        'school_holidays',
        sa.Column('id', sa.Integer(), primary_key=True, autoincrement=True),
        sa.Column('name', sa.String(length=150), nullable=False),
        sa.Column('start_date', sa.Date(), nullable=False),
        sa.Column('end_date', sa.Date(), nullable=False),
        sa.Column('region', sa.String(length=100), nullable=True),
        sa.Column('source_file_name', sa.String(length=255), nullable=True),
        sa.Column('imported_at', sa.TIMESTAMP(timezone=True),
                  server_default=sa.text('CURRENT_TIMESTAMP')),
    )
    op.create_index('ix_school_holidays_start_date',
                    'school_holidays', ['start_date'])
    op.create_index('ix_school_holidays_end_date',
                    'school_holidays', ['end_date'])
    op.create_index('ix_school_holidays_region', 'school_holidays', ['region'])
    op.create_unique_constraint('uq_school_holidays_unique', 'school_holidays', [
                                'name', 'start_date', 'end_date', 'region'])


def downgrade() -> None:
    op.drop_constraint('uq_school_holidays_unique',
                       'school_holidays', type_='unique')
    op.drop_index('ix_school_holidays_region', table_name='school_holidays')
    op.drop_index('ix_school_holidays_end_date', table_name='school_holidays')
    op.drop_index('ix_school_holidays_start_date',
                  table_name='school_holidays')
    op.drop_table('school_holidays')
