"""active flag for historically-scraped (closed/insolvent) competitors

Revision ID: 0007
Revises: 0006
Create Date: 2026-04-17

Security companies flagged by Racius as 'encerradas', 'insolvencia' or
'revitalizacao' are imported once for their credor/executado footprint, but
should not pollute the daily cron — nothing new will ever land for them.
active=FALSE excludes from daily scrape while keeping the company visible in
/competitors with its historical processes.
"""
from alembic import op


revision = "0007"
down_revision = "0006"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute(
        "ALTER TABLE companies ADD COLUMN active BOOLEAN NOT NULL DEFAULT TRUE"
    )
    op.execute("CREATE INDEX ix_companies_active ON companies(active) WHERE NOT active")


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