USE keiba_ai;

-- 取込重複防止・長い識別子
ALTER TABLE races
  MODIFY COLUMN data_source VARCHAR(512) DEFAULT NULL COMMENT '取込元';

SET @db := DATABASE();
SET @sql := (
  SELECT IF(
    EXISTS(SELECT 1 FROM information_schema.STATISTICS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='races' AND INDEX_NAME='uq_races_source_cname'),
    'SELECT 1',
    'ALTER TABLE races ADD COLUMN source_cname VARCHAR(260) DEFAULT NULL COMMENT ''JRA CNAME本体（pw01sde.../HEX）'', ADD UNIQUE KEY uq_races_source_cname (source_cname)'
  )
);
PREPARE s FROM @sql; EXECUTE s; DEALLOCATE PREPARE s;
