"""Add asset risk-dimension (high-value-target) columns

Revision ID: 034
Revises: 033
Create Date: 2026-06-16 09:00:00.000000

"Risk Dimensions": crown-jewel role detection (Domain Controller, ADCS,
SQL, Exchange, WSUS, backup, ...) computed alongside network exposure and
fed into the URS. Stores a 0-100 high_value_score + the detected roles.

Idempotent — ADD COLUMN IF NOT EXISTS.
"""
from alembic import op


revision = "034"
down_revision = "033"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute("""
        ALTER TABLE assets
            ADD COLUMN IF NOT EXISTS high_value_score          DOUBLE PRECISION,
            ADD COLUMN IF NOT EXISTS risk_dimensions           TEXT,
            ADD COLUMN IF NOT EXISTS risk_dimensions_updated_at TIMESTAMP;
    """)
    op.execute("""
        CREATE INDEX IF NOT EXISTS ix_assets_high_value_score
            ON assets (high_value_score)
            WHERE high_value_score > 0;
    """)


def downgrade() -> None:
    op.execute("DROP INDEX IF EXISTS ix_assets_high_value_score;")
    op.execute("""
        ALTER TABLE assets
            DROP COLUMN IF EXISTS high_value_score,
            DROP COLUMN IF EXISTS risk_dimensions,
            DROP COLUMN IF EXISTS risk_dimensions_updated_at;
    """)
