"""add session_token and expire_time to app_config

Revision ID: k4567mn8901
Revises: j3456kl7891
Create Date: 2026-07-07 16:10:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


revision: str = "k4567mn8901"
down_revision: Union[str, None] = "j3456kl7891"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    conn = op.get_bind()
    inspector = sa.inspect(conn)
    tables = inspector.get_table_names()

    if "app_config" in tables:
        columns = {col["name"] for col in inspector.get_columns("app_config")}
        if "session_token" not in columns:
            op.add_column("app_config", sa.Column("session_token", sa.String(), nullable=True))
        if "expire_time" not in columns:
            op.add_column("app_config", sa.Column("expire_time", sa.String(), nullable=True))


def downgrade() -> None:
    conn = op.get_bind()
    inspector = sa.inspect(conn)
    tables = inspector.get_table_names()

    if "app_config" in tables:
        columns = {col["name"] for col in inspector.get_columns("app_config")}
        if "expire_time" in columns:
            op.drop_column("app_config", "expire_time")
        if "session_token" in columns:
            op.drop_column("app_config", "session_token")
