"""scrape_isolated flag for slow movers (CARLOS SILVA)

Revision ID: 0005
Revises: 0004
Create Date: 2026-04-17

Distintivo "CARLOS SILVA" produces CITIUS responses so large that a subset of
tribunals consistently ReadTimeout. Isolating it into a dedicated late-evening
job keeps the main 03:00 batch fast (no 16 failed pairs dragging it to partial)
and lets us allocate more time to just this one company.
"""
from alembic import op


revision = "0005"
down_revision = "0004"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute(
        "ALTER TABLE companies ADD COLUMN scrape_isolated BOOLEAN NOT NULL DEFAULT FALSE"
    )
    op.execute(
        "CREATE INDEX ix_companies_scrape_isolated ON companies(scrape_isolated) WHERE scrape_isolated"
    )
    op.execute("UPDATE companies SET scrape_isolated = TRUE WHERE nif = '509534007'")


def downgrade() -> None:
    op.execute("DROP INDEX IF EXISTS ix_companies_scrape_isolated")
    op.execute("ALTER TABLE companies DROP COLUMN scrape_isolated")
