-- ======================================================================
-- FashCognitive Season Master — Season Type
-- Adds the mandatory `season_type` field (per the Style Season Master
-- spec: Season Name, Season Type, Start Date, End Date are required).
-- Idempotent: safe to re-run (skips existing column/index).
-- ======================================================================


SET @has_col = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'master_seasons' AND COLUMN_NAME = 'season_type');

SET @sql = IF(@has_col = 0,
  'ALTER TABLE `master_seasons` ADD COLUMN `season_type` varchar(50) DEFAULT NULL AFTER `season_name`',
  'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @has_key = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'master_seasons' AND INDEX_NAME = 'season_type');

SET @sql = IF(@has_key = 0,
  'ALTER TABLE `master_seasons` ADD KEY `season_type` (`season_type`)',
  'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

