"""add agentic polling table

Revision ID: 6bb9c3509892
Revises: 4af384f67b6b
Create Date: 2026-02-05 12:13:33.654617

"""

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "6bb9c3509892"
down_revision = "4af384f67b6b"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "agent_polling_data",
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("task_id", sa.String(), nullable=False),
        sa.Column("status", sa.String(), nullable=False),
        sa.Column("failed_runs", sa.Integer(), nullable=False),
        sa.Column("error_message", sa.String(), nullable=True),
        sa.Column("created_at", sa.TIMESTAMP(), nullable=False),
        sa.Column("updated_at", sa.TIMESTAMP(), nullable=False),
        sa.Column("last_fetched", sa.TIMESTAMP(), nullable=True),
        sa.ForeignKeyConstraint(["task_id"], ["tasks.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_agent_polling_data_created_at"),
        "agent_polling_data",
        ["created_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_agent_polling_data_task_id"),
        "agent_polling_data",
        ["task_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_agent_polling_data_updated_at"),
        "agent_polling_data",
        ["updated_at"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        op.f("ix_agent_polling_data_updated_at"),
        table_name="agent_polling_data",
    )
    op.drop_index(
        op.f("ix_agent_polling_data_task_id"),
        table_name="agent_polling_data",
    )
    op.drop_index(
        op.f("ix_agent_polling_data_created_at"),
        table_name="agent_polling_data",
    )
    op.drop_table("agent_polling_data")
    # ### end Alembic commands ###
