"""add_position_members_table

Revision ID: 5448c81e7afd
Revises: 3d5b88fe1875
Create Date: 2025-09-22 08:13:54.755269

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision: str = '5448c81e7afd'
down_revision: Union[str, None] = '3d5b88fe1875'
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.create_table('position_members',
    sa.Column('position_id', sa.Integer(), nullable=False, comment='岗位ID'),
    sa.Column('user_id', sa.Integer(), nullable=False, comment='用户ID'),
    sa.Column('role', sa.String(length=50), nullable=True, comment='成员角色（预留字段）'),
    sa.Column('joined_at', sa.DateTime(), nullable=True, comment='加入时间'),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('is_deleted', sa.Boolean(), nullable=False),
    sa.Column('deleted_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['position_id'], ['positions.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('position_id', 'user_id', 'is_deleted', name='uix_position_user')
    )
    op.create_index(op.f('ix_position_members_id'), 'position_members', ['id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_position_members_id'), table_name='position_members')
    op.drop_table('position_members')
    # ### end Alembic commands ###