"""users.role 列(admin 管理后台访问控制).

Revision ID: 0009
Revises: 0008
Create Date: 2026-06-12

给 users 加 role 列(user / admin),给现有所有行默认 'user';/v1/admin/* 监控端点
走 make_require_admin gate,只放 role='admin' 的用户。提管理员:
`.venv/Scripts/python.exe main.py user role --email X --role admin`。

只加列、不动现有数据(开发期测试数据保留);server_default='user' 让历史行自动回填。
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op


revision: str = "0009"
down_revision: Union[str, None] = "0008"
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("role", sa.Text(), nullable=False, server_default="user"),
    )


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