"""202601271517

Revision ID: 75f0ec80e50b
Revises: 325b759cd66b
Create Date: 2026-01-27 15:26:48.696600

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '75f0ec80e50b'
down_revision: Union[str, None] = '325b759cd66b'
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.alter_column('memory_config', 'config_id',
               existing_type=sa.UUID(),
               comment='配置ID',
               existing_nullable=False)
    op.alter_column('memory_config', 'config_id_old',
               existing_type=sa.INTEGER(),
               comment='备份的配置ID',
               existing_comment='配置ID',
               existing_nullable=True)
    op.add_column('tenants', sa.Column('external_id', sa.String(length=100), nullable=True))
    op.add_column('tenants', sa.Column('external_source', sa.String(length=50), nullable=True))
    op.create_index(op.f('ix_tenants_external_id'), 'tenants', ['external_id'], unique=False)
    op.add_column('users', sa.Column('external_id', sa.String(length=100), nullable=True))
    op.add_column('users', sa.Column('external_source', sa.String(length=50), nullable=True))
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'external_source')
    op.drop_column('users', 'external_id')
    op.drop_index(op.f('ix_tenants_external_id'), table_name='tenants')
    op.drop_column('tenants', 'external_source')
    op.drop_column('tenants', 'external_id')
    op.alter_column('memory_config', 'config_id_old',
               existing_type=sa.INTEGER(),
               comment='配置ID',
               existing_comment='备份的配置ID',
               existing_nullable=True)
    op.alter_column('memory_config', 'config_id',
               existing_type=sa.UUID(),
               comment=None,
               existing_comment='配置ID',
               existing_nullable=False)
    # ### end Alembic commands ###
