"""Add date_id foreign key to fact_state table.

Revision ID: e2205fd93662
Revises: 7e65d4230d6b
Create Date: 2026-01-15 15:11:59.029618

"""

from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

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


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column("fact_state", sa.Column("date_id", sa.Integer(), nullable=True))
    op.create_index("idx_state_date", "fact_state", ["date_id"], unique=False)
    op.create_foreign_key(
        None, "fact_state", "dim_date", ["date_id"], ["date_id"], ondelete="SET NULL"
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, "fact_state", type_="foreignkey")
    op.drop_index("idx_state_date", table_name="fact_state")
    op.drop_column("fact_state", "date_id")
    # ### end Alembic commands ###
