"""
Migrazione 0013: campo scheduled_at su send_jobs
(Feature 5 – Invio differito).
"""

from alembic import op
import sqlalchemy as sa

revision = "0013"
down_revision = "0012"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.add_column(
        "send_jobs",
        sa.Column("scheduled_at", sa.DateTime(timezone=True), nullable=True),
    )
    op.create_index(
        "idx_sendjobs_scheduled",
        "send_jobs",
        ["scheduled_at"],
        postgresql_where=sa.text("status = 'pending' AND scheduled_at IS NOT NULL"),
    )


def downgrade() -> None:
    op.drop_index("idx_sendjobs_scheduled", table_name="send_jobs")
    op.drop_column("send_jobs", "scheduled_at")
