-- =====================================================
-- Migration: Add referee_type to martial_judge_invite
-- Version: V7
-- Description: Add referee type column (1-Chief Judge, 2-Judge, 3-General Judge)
-- Date: 2026-01-20
-- =====================================================

-- Idempotent: Only add column if not exists
SET @dbname = DATABASE();
SET @tablename = 'martial_judge_invite';
SET @columnname = 'referee_type';
SET @preparedStatement = (SELECT IF(
  (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS 
   WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = @columnname) > 0,
  'SELECT 1',
  CONCAT('ALTER TABLE ', @tablename, ' ADD COLUMN ', @columnname, ' INT DEFAULT NULL COMMENT "裁判类型：1-主裁判，2-裁判员，3-总裁"')
));
PREPARE alterIfNotExists FROM @preparedStatement;
EXECUTE alterIfNotExists;
DEALLOCATE PREPARE alterIfNotExists;
