-- =============================================
-- 验证赛程编排系统表创建情况
-- =============================================

USE martial_db;

-- 1. 检查所有赛程相关表
SELECT
    table_name AS '表名',
    table_comment AS '说明',
    CASE
        WHEN table_name IN ('martial_schedule_group', 'martial_schedule_detail',
                           'martial_schedule_participant', 'martial_schedule_status')
        THEN '✓ 新系统'
        ELSE '旧系统'
    END AS '系统版本',
    table_rows AS '记录数'
FROM information_schema.tables
WHERE table_schema = 'martial_db'
  AND table_name LIKE 'martial_schedule%'
ORDER BY
    CASE
        WHEN table_name IN ('martial_schedule_group', 'martial_schedule_detail',
                           'martial_schedule_participant', 'martial_schedule_status')
        THEN 1
        ELSE 2
    END,
    table_name;

-- 2. 验证新系统4张表是否全部创建
SELECT
    CASE
        WHEN COUNT(*) = 4 THEN '✓ 新系统表创建成功! 共4张表已就绪'
        ELSE CONCAT('⚠ 警告: 只创建了 ', COUNT(*), ' 张表,应该是4张')
    END AS '创建状态'
FROM information_schema.tables
WHERE table_schema = 'martial_db'
  AND table_name IN (
    'martial_schedule_group',
    'martial_schedule_detail',
    'martial_schedule_participant',
    'martial_schedule_status'
  );

-- 3. 检查各表的字段数量
SELECT
    table_name AS '表名',
    COUNT(*) AS '字段数'
FROM information_schema.columns
WHERE table_schema = 'martial_db'
  AND table_name IN (
    'martial_schedule_group',
    'martial_schedule_detail',
    'martial_schedule_participant',
    'martial_schedule_status'
  )
GROUP BY table_name
ORDER BY table_name;

-- 4. 检查索引创建情况
SELECT
    table_name AS '表名',
    COUNT(DISTINCT index_name) AS '索引数量',
    GROUP_CONCAT(DISTINCT index_name ORDER BY index_name) AS '索引列表'
FROM information_schema.statistics
WHERE table_schema = 'martial_db'
  AND table_name IN (
    'martial_schedule_group',
    'martial_schedule_detail',
    'martial_schedule_participant',
    'martial_schedule_status'
  )
GROUP BY table_name
ORDER BY table_name;

-- 5. 检查是否有数据(应该为空,因为是新表)
SELECT
    'martial_schedule_group' AS '表名',
    COUNT(*) AS '记录数'
FROM martial_schedule_group
UNION ALL
SELECT
    'martial_schedule_detail',
    COUNT(*)
FROM martial_schedule_detail
UNION ALL
SELECT
    'martial_schedule_participant',
    COUNT(*)
FROM martial_schedule_participant
UNION ALL
SELECT
    'martial_schedule_status',
    COUNT(*)
FROM martial_schedule_status;

-- 6. 显示最终状态
SELECT
    '🎉 数据库升级完成!' AS '状态',
    DATABASE() AS '当前数据库',
    NOW() AS '验证时间';
