-- 添加 is_timeout 欄位到現有資料庫表
-- 執行時間: 2024-01-XX
-- 描述: 為測試結果表添加時間到標記欄位

USE hr_assessment;

-- 檢查並添加 test_results 表的 is_timeout 欄位
SET @column_exists = (
  SELECT COUNT(*) 
  FROM INFORMATION_SCHEMA.COLUMNS 
  WHERE TABLE_SCHEMA = DATABASE() 
  AND TABLE_NAME = 'test_results' 
  AND COLUMN_NAME = 'is_timeout'
);

SET @sql = IF(@column_exists = 0, 
  'ALTER TABLE test_results ADD COLUMN is_timeout BOOLEAN DEFAULT FALSE',
  'SELECT "test_results 表的 is_timeout 欄位已存在，跳過" as message'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- 檢查並添加 combined_test_results 表的 is_timeout 欄位
SET @column_exists = (
  SELECT COUNT(*) 
  FROM INFORMATION_SCHEMA.COLUMNS 
  WHERE TABLE_SCHEMA = DATABASE() 
  AND TABLE_NAME = 'combined_test_results' 
  AND COLUMN_NAME = 'is_timeout'
);

SET @sql = IF(@column_exists = 0, 
  'ALTER TABLE combined_test_results ADD COLUMN is_timeout BOOLEAN DEFAULT FALSE',
  'SELECT "combined_test_results 表的 is_timeout 欄位已存在，跳過" as message'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- 驗證欄位是否添加成功
DESCRIBE test_results;
DESCRIBE combined_test_results;

-- 顯示成功訊息
SELECT 'is_timeout 欄位添加完成！' AS message;
