"""Add subscription_ends_at and cancel_at_period_end to users

Revision ID: f6a7b8c9d0e1
Revises: e5b2c9d1f4a8
Create Date: 2026-05-31

Fixes critical bug: these columns were used in update_user() but never
persisted to the database, causing subscription end dates and cancellation
state to be lost on server restart.
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

# revision identifiers
revision = "f6a7b8c9d0e1"
down_revision = "e5b2c9d1f4a8"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column(
        "users",
        sa.Column("subscription_ends_at", sa.DateTime(), nullable=True),
    )
    op.add_column(
        "users",
        sa.Column("cancel_at_period_end", sa.Boolean(), nullable=False, server_default="false"),
    )


def downgrade() -> None:
    op.drop_column("users", "cancel_at_period_end")
    op.drop_column("users", "subscription_ends_at")
