"""Add report_type column to weekly_reports.

Revision ID: 007_add_report_type
Revises: 006_anonymize_fall_ids
"""

from alembic import op
import sqlalchemy as sa

revision = "007_add_report_type"
down_revision = "006_anonymize_fall_ids"
branch_labels = None
depends_on = None


def upgrade():
    # Add report_type column with default 'gesamt'
    op.add_column(
        "weekly_reports",
        sa.Column("report_type", sa.String(50), nullable=False, server_default="gesamt"),
    )

    # Drop old unique constraint (jahr, kw)
    op.drop_constraint("uk_jahr_kw", "weekly_reports", type_="unique")

    # Add new unique constraint (jahr, kw, report_type)
    op.create_unique_constraint(
        "uk_jahr_kw_type", "weekly_reports", ["jahr", "kw", "report_type"]
    )


def downgrade():
    op.drop_constraint("uk_jahr_kw_type", "weekly_reports", type_="unique")
    op.drop_column("weekly_reports", "report_type")
    op.create_unique_constraint("uk_jahr_kw", "weekly_reports", ["jahr", "kw"])
