"""Remove EngineSettingsTable.running_processes.

Created with these steps:
1. Ran `alembic revision --autogenerate`
2. Removed statements that are part of the runtime llm_migration
3. Added an upgrade statement drop_constraint for "uq_workflow_schedule" so that it can be created as alembic expects
4. Removed drop_constraint for "uq_workflow_schedule" in the downgrade path

Revision ID: fbc16e410bc6
Revises: aa1b92d0d07d
Create Date: 2026-03-12 10:51:02.886509

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "fbc16e410bc6"
down_revision = "aa1b92d0d07d"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # This is the actual change
    op.drop_column("engine_settings", "running_processes")

    # Other differences detected by `alembic revision --autogenerate`:
    # 1. The manually created index (in bac6be6f2b4f) was missing an 's' after the 3rd word
    op.drop_index(op.f("ix_input_state_input_state_id"), table_name="input_states")
    op.create_index(op.f("ix_input_states_input_state_id"), "input_states", ["input_state_id"], unique=False)

    # 2. Fix indexes/contraints from 961eddbd4c13
    op.create_index(
        op.f("ix_workflows_apscheduler_jobs_workflow_id"), "workflows_apscheduler_jobs", ["workflow_id"], unique=False
    )
    op.drop_constraint("uq_workflow_schedule", "workflows_apscheduler_jobs")
    op.create_unique_constraint("uq_workflow_schedule", "workflows_apscheduler_jobs", ["workflow_id", "schedule_id"])
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_workflows_apscheduler_jobs_workflow_id"), table_name="workflows_apscheduler_jobs")
    op.drop_index(op.f("ix_input_states_input_state_id"), table_name="input_states")
    op.create_index(op.f("ix_input_state_input_state_id"), "input_states", ["input_state_id"], unique=False)
    op.add_column(
        "engine_settings",
        sa.Column("running_processes", sa.INTEGER(), autoincrement=False, nullable=False, server_default="0"),
    )
    # ### end Alembic commands ###
