"""add users soft delete columns

Revision ID: add_users_soft_delete
Revises: 20250921_align_schema_to_design
Create Date: 2025-09-22 03:00:00

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'add_users_soft_delete'
down_revision: Union[str, None] = '20250921_align_schema_to_design'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # 为 users 表添加软删除字段
    op.add_column('users', sa.Column('is_deleted', sa.Boolean(), nullable=False, server_default='0'))
    op.add_column('users', sa.Column('deleted_at', sa.DateTime(), nullable=True))
    
    # 添加索引
    op.create_index('idx_users_is_deleted', 'users', ['is_deleted'])


def downgrade() -> None:
    # 删除索引
    op.drop_index('idx_users_is_deleted', table_name='users')
    
    # 删除字段
    op.drop_column('users', 'deleted_at')
    op.drop_column('users', 'is_deleted')
