-- =====================================================
-- 创建调度调整日志表
-- 用于记录调度功能的调整历史
-- 执行时间: 2025-12-12
-- =====================================================

USE blade;

-- 创建调度调整日志表
CREATE TABLE IF NOT EXISTS `martial_schedule_adjustment_log` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `competition_id` bigint NOT NULL COMMENT '赛事ID',
  `schedule_detail_id` bigint NOT NULL COMMENT '编排明细ID',
  `schedule_group_id` bigint NOT NULL COMMENT '分组ID',
  `participant_id` bigint NOT NULL COMMENT '参赛者记录ID',
  `participant_name` varchar(100) DEFAULT NULL COMMENT '参赛者姓名',
  `organization` varchar(200) DEFAULT NULL COMMENT '单位名称',
  `old_order` int NOT NULL COMMENT '原顺序',
  `new_order` int NOT NULL COMMENT '新顺序',
  `adjustment_type` varchar(20) DEFAULT NULL COMMENT '调整类型(move_up=上移, move_down=下移, swap=交换)',
  `adjustment_reason` varchar(500) DEFAULT NULL COMMENT '调整原因',
  `operator_id` bigint DEFAULT NULL COMMENT '操作人ID',
  `operator_name` varchar(100) DEFAULT NULL COMMENT '操作人姓名',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
  PRIMARY KEY (`id`),
  KEY `idx_competition` (`competition_id`),
  KEY `idx_detail` (`schedule_detail_id`),
  KEY `idx_group` (`schedule_group_id`),
  KEY `idx_participant` (`participant_id`),
  KEY `idx_create_time` (`create_time`),
  KEY `idx_tenant` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='赛程调度调整日志表';

-- 验证表是否创建成功
SELECT
    TABLE_NAME,
    TABLE_COMMENT,
    TABLE_ROWS
FROM
    INFORMATION_SCHEMA.TABLES
WHERE
    TABLE_SCHEMA = 'blade'
    AND TABLE_NAME = 'martial_schedule_adjustment_log';

-- 查看表结构
DESC martial_schedule_adjustment_log;

SELECT '调度日志表创建成功！' AS status;
