"""add benchmark_prices

Stores daily closes for a benchmark index (SPY) so paper-trade alpha — trade
return minus the benchmark's return over the same holding period — can be
computed. Kept separate from the tradeable universe: the benchmark is not a
Ticker, so it never enters the scanner, momentum ranking, or rankings.

Revision ID: 012
Revises: 011
Create Date: 2026-06-28 00:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "012"
down_revision: Union[str, None] = "011"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        "benchmark_prices",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("symbol", sa.String(length=20), nullable=False),
        sa.Column("date", sa.Date(), nullable=False),
        sa.Column("close", sa.Float(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("symbol", "date", name="uq_benchmark_symbol_date"),
    )
    op.create_index("ix_benchmark_prices_symbol", "benchmark_prices", ["symbol"])


def downgrade() -> None:
    op.drop_index("ix_benchmark_prices_symbol", table_name="benchmark_prices")
    op.drop_table("benchmark_prices")
