-- =====================================================
-- 升级 martial_judge_invite 表
-- 添加邀请状态、时间、联系方式等字段
-- 执行时间: 2025-12-12
-- =====================================================

USE blade;

-- 检查表是否存在
SELECT 'Checking martial_judge_invite table...' AS status;

-- 添加邀请状态字段
ALTER TABLE martial_judge_invite
ADD COLUMN IF NOT EXISTS invite_status INT DEFAULT 0 COMMENT '邀请状态(0-待回复,1-已接受,2-已拒绝,3-已取消)';

-- 添加邀请时间字段
ALTER TABLE martial_judge_invite
ADD COLUMN IF NOT EXISTS invite_time DATETIME COMMENT '邀请时间';

-- 添加回复时间字段
ALTER TABLE martial_judge_invite
ADD COLUMN IF NOT EXISTS reply_time DATETIME COMMENT '回复时间';

-- 添加回复备注字段
ALTER TABLE martial_judge_invite
ADD COLUMN IF NOT EXISTS reply_note VARCHAR(500) COMMENT '回复备注';

-- 添加联系电话字段
ALTER TABLE martial_judge_invite
ADD COLUMN IF NOT EXISTS contact_phone VARCHAR(20) COMMENT '联系电话';

-- 添加联系邮箱字段
ALTER TABLE martial_judge_invite
ADD COLUMN IF NOT EXISTS contact_email VARCHAR(100) COMMENT '联系邮箱';

-- 添加邀请消息字段
ALTER TABLE martial_judge_invite
ADD COLUMN IF NOT EXISTS invite_message VARCHAR(1000) COMMENT '邀请消息';

-- 添加取消原因字段
ALTER TABLE martial_judge_invite
ADD COLUMN IF NOT EXISTS cancel_reason VARCHAR(500) COMMENT '取消原因';

-- 为邀请状态字段添加索引
ALTER TABLE martial_judge_invite
ADD INDEX IF NOT EXISTS idx_invite_status (invite_status);

-- 为赛事ID和邀请状态组合添加索引
ALTER TABLE martial_judge_invite
ADD INDEX IF NOT EXISTS idx_competition_status (competition_id, invite_status);

-- 验证字段是否添加成功
SELECT
    COLUMN_NAME,
    COLUMN_TYPE,
    COLUMN_COMMENT
FROM
    INFORMATION_SCHEMA.COLUMNS
WHERE
    TABLE_SCHEMA = 'blade'
    AND TABLE_NAME = 'martial_judge_invite'
    AND COLUMN_NAME IN (
        'invite_status',
        'invite_time',
        'reply_time',
        'reply_note',
        'contact_phone',
        'contact_email',
        'invite_message',
        'cancel_reason'
    )
ORDER BY
    ORDINAL_POSITION;

SELECT 'Upgrade completed successfully!' AS status;
