import pymysql

# DB Configs
host = '150.158.78.154'
port = 3306
user = 'root'
password = 'bindbox2025kdy'
database = 'bindbox_game'

# Connect
try:
    connection = pymysql.connect(
        host=host,
        port=port,
        user=user,
        password=password,
        database=database,
        charset='utf8mb4',
        cursorclass=pymysql.cursors.DictCursor
    )
    
    with connection.cursor() as cursor:
        # Check columns
        cursor.execute("SHOW COLUMNS FROM livestream_draw_logs LIKE 'shop_order_id'")
        result = cursor.fetchone()
        if not result:
            print("Adding shop_order_id column...")
            cursor.execute("ALTER TABLE livestream_draw_logs ADD COLUMN shop_order_id VARCHAR(255) DEFAULT '' COMMENT '抖店订单号' AFTER douyin_order_id")
            connection.commit()
            print("shop_order_id added.")
        else:
            print("shop_order_id already exists.")
            
        cursor.execute("SHOW COLUMNS FROM livestream_draw_logs LIKE 'user_nickname'")
        result = cursor.fetchone()
        if not result:
            print("Adding user_nickname column...")
            cursor.execute("ALTER TABLE livestream_draw_logs ADD COLUMN user_nickname VARCHAR(255) DEFAULT '' COMMENT '用户昵称' AFTER douyin_user_id")
            connection.commit()
            print("user_nickname added.")
        else:
            print("user_nickname already exists.")

except Exception as e:
    print(f"Error: {e}")
finally:
    if 'connection' in locals() and connection.open:
        connection.close()
