"""Added user_id to tasks.

Revision ID: d40eba8ebc4c
Revises: b9860676dd49
Create Date: 2025-01-23 14:17:04.394863

"""
from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "d40eba8ebc4c"
down_revision: str | None = "b9860676dd49"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Upgrade database to this revision from previous."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("tasks", schema=None) as batch_op:
        batch_op.add_column(
            sa.Column(
                "user_id",
                sa.String(),
                nullable=True,
                comment="ID of the user who launched the task",
            )
        )
        batch_op.create_index(batch_op.f("ix_tasks_status"), ["status"], unique=False)
        batch_op.create_index(batch_op.f("ix_tasks_user_id"), ["user_id"], unique=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade database from this revision to previous."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("tasks", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_tasks_user_id"))
        batch_op.drop_index(batch_op.f("ix_tasks_status"))
        batch_op.drop_column("user_id")

    # ### end Alembic commands ###
