-- =====================================================
-- 手动执行：删除 tenant_package 表的 package_id 字段
--
-- 说明：
-- - V31 已经尝试删除此字段，但可能执行失败
-- - 现在该字段已不再使用，使用 collection_id 替代
-- =====================================================

-- 安全删除 package_id 列（如果存在）
SET @column_exists := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'tenant_package'
    AND COLUMN_NAME = 'package_id'
);

SET @sql := IF(@column_exists > 0,
    'ALTER TABLE `tenant_package` DROP COLUMN `package_id`',
    'SELECT "Column package_id does not exist in tenant_package, skipping"'
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- 验证列已删除
SELECT '=== tenant_package 表结构验证 ===' AS info;
DESCRIBE tenant_package;

-- 检查是否还有 packageId (驼峰命名) 列
SET @column_exists2 := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'tenant_package'
    AND COLUMN_NAME = 'packageId'
);

SET @sql2 := IF(@column_exists2 > 0,
    'ALTER TABLE `tenant_package` DROP COLUMN `packageId`',
    'SELECT "Column packageId does not exist in tenant_package, skipping"'
);

PREPARE stmt2 FROM @sql2;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;

-- 再次验证
SELECT '=== tenant_package 最终表结构 ===' AS info;
DESCRIBE tenant_package;
