"""Add Subscription.scheduler_locked

Revision ID: 795c209e28a7
Revises: 31fc877afc52
Create Date: 2025-06-26 11:43:34.464666

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "795c209e28a7"
down_revision = "31fc877afc52"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "subscriptions", sa.Column("scheduler_locked", sa.Boolean(), nullable=True)
    )
    op.execute(
        "UPDATE subscriptions SET scheduler_locked = FALSE WHERE scheduler_locked IS NULL"
    )
    op.alter_column(
        "subscriptions",
        "scheduler_locked",
        existing_type=sa.Boolean(),
        nullable=False,
        existing_nullable=True,
    )
    op.create_index(
        op.f("ix_subscriptions_scheduler_locked"),
        "subscriptions",
        ["scheduler_locked"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_subscriptions_scheduler_locked"), table_name="subscriptions")
    op.drop_column("subscriptions", "scheduler_locked")
    # ### end Alembic commands ###
