-- =====================================================
-- 迁移脚本: 添加项目表字段
-- 版本: V2
-- 描述: 为 martial_project 表添加 event_type 和报名时间字段
-- 日期: 2024-12-29
-- =====================================================

-- 添加 event_type 字段（如果不存在）
SET @exist := (SELECT COUNT(*) FROM information_schema.columns 
               WHERE table_schema = DATABASE() 
               AND table_name = 'martial_project' 
               AND column_name = 'event_type');
SET @sql := IF(@exist = 0, 
    'ALTER TABLE martial_project ADD COLUMN event_type int DEFAULT NULL COMMENT "项目类型: 1-套路 2-散打 3-器械 4-对练" AFTER category',
    'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- 添加 registration_start_time 字段（如果不存在）
SET @exist := (SELECT COUNT(*) FROM information_schema.columns 
               WHERE table_schema = DATABASE() 
               AND table_name = 'martial_project' 
               AND column_name = 'registration_start_time');
SET @sql := IF(@exist = 0, 
    'ALTER TABLE martial_project ADD COLUMN registration_start_time datetime DEFAULT NULL COMMENT "报名开始时间" AFTER price',
    'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- 添加 registration_end_time 字段（如果不存在）
SET @exist := (SELECT COUNT(*) FROM information_schema.columns 
               WHERE table_schema = DATABASE() 
               AND table_name = 'martial_project' 
               AND column_name = 'registration_end_time');
SET @sql := IF(@exist = 0, 
    'ALTER TABLE martial_project ADD COLUMN registration_end_time datetime DEFAULT NULL COMMENT "报名结束时间" AFTER registration_start_time',
    'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
