"""添加 location_type 字段到 vwed_operate_point_layer 表

Revision ID: 20250904_150033
Revises: 822a081a7774
Create Date: 2025-09-04 15:00:33

"""
from alembic import op
import sqlalchemy as sa
import uuid


# revision identifiers, used by Alembic.
revision = '20250904_150033'
down_revision = '822a081a7774'
branch_labels = None
depends_on = None


def upgrade():
    # 添加 location_type 字段到 vwed_operate_point_layer 表
    op.add_column('vwed_operate_point_layer', sa.Column('location_type', sa.INTEGER, nullable=False, server_default=sa.text('1'), comment='库位类型：1-物理库位，2-逻辑库位'))
    
    # 为已有记录设置默认值（物理库位）
    conn = op.get_bind()
    
    # 确保所有现有记录都设置为物理库位（location_type = 1）
    conn.execute("UPDATE vwed_operate_point_layer SET location_type = 1 WHERE location_type IS NULL OR location_type = 0")
    
    print("✅ 已为所有现有库位设置为物理库位（location_type = 1）")


def downgrade():
    # 删除 location_type 字段
    op.drop_column('vwed_operate_point_layer', 'location_type')
