Files
martial-master/database/martial-db/UPGRADE_GUIDE.md
宅房 7aa6545cbb
All checks were successful
continuous-integration/drone/push Build is passing
fix bugs
2025-12-12 05:13:10 +08:00

7.6 KiB

赛程编排系统数据库升级指南

当前状态

  • 数据库名: martial_db
  • 现有表: martial_schedule, martial_schedule_athlete
  • 需要创建: 4张新表(与旧表共存)

🚀 执行步骤

步骤1: 打开数据库管理工具

使用你常用的数据库管理工具:

  • Navicat
  • DBeaver
  • phpMyAdmin
  • MySQL Workbench
  • DataGrip
  • 或其他工具

步骤2: 连接到数据库

连接到 martial_db 数据库

步骤3: 执行SQL脚本

打开文件: D:\workspace\31.比赛项目\project\martial-master\database\martial-db\upgrade_schedule_system.sql

方式A: 在工具中直接打开此文件并执行

方式B: 复制以下SQL内容并执行

USE martial_db;

-- 1. 赛程编排分组表
CREATE TABLE IF NOT EXISTS `martial_schedule_group` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `competition_id` bigint(20) NOT NULL COMMENT '赛事ID',
  `group_name` varchar(200) NOT NULL COMMENT '分组名称(如:太极拳男组)',
  `project_id` bigint(20) NOT NULL COMMENT '项目ID',
  `project_name` varchar(100) DEFAULT NULL COMMENT '项目名称',
  `category` varchar(50) DEFAULT NULL COMMENT '组别(成年组、少年组等)',
  `project_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '项目类型(1=个人 2=集体)',
  `display_order` int(11) NOT NULL DEFAULT '0' COMMENT '显示顺序',
  `total_participants` int(11) DEFAULT '0' COMMENT '总参赛人数',
  `total_teams` int(11) DEFAULT '0' COMMENT '总队伍数(仅集体项目)',
  `estimated_duration` int(11) DEFAULT '0' COMMENT '预计时长(分钟)',
  `create_user` bigint(20) DEFAULT NULL,
  `create_dept` bigint(20) DEFAULT NULL,
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP,
  `update_user` bigint(20) DEFAULT NULL,
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `status` int(11) DEFAULT '1' COMMENT '状态(1-启用,2-禁用)',
  `is_deleted` int(11) DEFAULT '0',
  `tenant_id` varchar(12) DEFAULT '000000',
  PRIMARY KEY (`id`),
  KEY `idx_competition` (`competition_id`),
  KEY `idx_project` (`project_id`),
  KEY `idx_display_order` (`display_order`),
  KEY `idx_tenant` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='赛程编排分组表';

-- 2. 赛程编排明细表
CREATE TABLE IF NOT EXISTS `martial_schedule_detail` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `schedule_group_id` bigint(20) NOT NULL COMMENT '分组ID',
  `competition_id` bigint(20) NOT NULL COMMENT '赛事ID',
  `venue_id` bigint(20) NOT NULL COMMENT '场地ID',
  `venue_name` varchar(100) DEFAULT NULL COMMENT '场地名称',
  `schedule_date` date NOT NULL COMMENT '比赛日期',
  `time_period` varchar(20) NOT NULL COMMENT '时间段(morning/afternoon)',
  `time_slot` varchar(20) NOT NULL COMMENT '时间点(08:30/13:30)',
  `estimated_start_time` datetime DEFAULT NULL COMMENT '预计开始时间',
  `estimated_end_time` datetime DEFAULT NULL COMMENT '预计结束时间',
  `estimated_duration` int(11) DEFAULT '0' COMMENT '预计时长(分钟)',
  `participant_count` int(11) DEFAULT '0' COMMENT '参赛人数',
  `sort_order` int(11) DEFAULT '0' COMMENT '场内顺序',
  `create_user` bigint(20) DEFAULT NULL,
  `create_dept` bigint(20) DEFAULT NULL,
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP,
  `update_user` bigint(20) DEFAULT NULL,
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `status` int(11) DEFAULT '1' COMMENT '状态(1-未开始,2-进行中,3-已完成)',
  `is_deleted` int(11) DEFAULT '0',
  `tenant_id` varchar(12) DEFAULT '000000',
  PRIMARY KEY (`id`),
  KEY `idx_group` (`schedule_group_id`),
  KEY `idx_competition` (`competition_id`),
  KEY `idx_venue_time` (`venue_id`,`schedule_date`,`time_slot`),
  KEY `idx_tenant` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='赛程编排明细表';

-- 3. 赛程编排参赛者关联表
CREATE TABLE IF NOT EXISTS `martial_schedule_participant` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `schedule_detail_id` bigint(20) NOT NULL COMMENT '编排明细ID',
  `schedule_group_id` bigint(20) NOT NULL COMMENT '分组ID',
  `participant_id` bigint(20) NOT NULL COMMENT '参赛者ID(关联martial_athlete表)',
  `organization` varchar(200) DEFAULT NULL COMMENT '单位名称',
  `player_name` varchar(100) DEFAULT NULL COMMENT '选手姓名',
  `project_name` varchar(100) DEFAULT NULL COMMENT '项目名称',
  `category` varchar(50) DEFAULT NULL COMMENT '组别',
  `performance_order` int(11) DEFAULT '0' COMMENT '出场顺序',
  `create_user` bigint(20) DEFAULT NULL,
  `create_dept` bigint(20) DEFAULT NULL,
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP,
  `update_user` bigint(20) DEFAULT NULL,
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `status` int(11) DEFAULT '1' COMMENT '状态(1-待出场,2-已出场)',
  `is_deleted` int(11) DEFAULT '0',
  `tenant_id` varchar(12) DEFAULT '000000',
  PRIMARY KEY (`id`),
  KEY `idx_detail` (`schedule_detail_id`),
  KEY `idx_group` (`schedule_group_id`),
  KEY `idx_participant` (`participant_id`),
  KEY `idx_tenant` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='赛程编排参赛者关联表';

-- 4. 赛程编排状态表
CREATE TABLE IF NOT EXISTS `martial_schedule_status` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `competition_id` bigint(20) NOT NULL COMMENT '赛事ID(唯一)',
  `schedule_status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '编排状态(0=未编排 1=编排中 2=已保存锁定)',
  `last_auto_schedule_time` datetime DEFAULT NULL COMMENT '最后自动编排时间',
  `locked_time` datetime DEFAULT NULL COMMENT '锁定时间',
  `locked_by` varchar(100) DEFAULT NULL COMMENT '锁定人',
  `total_groups` int(11) DEFAULT '0' COMMENT '总分组数',
  `total_participants` int(11) DEFAULT '0' COMMENT '总参赛人数',
  `create_user` bigint(20) DEFAULT NULL,
  `create_dept` bigint(20) DEFAULT NULL,
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP,
  `update_user` bigint(20) DEFAULT NULL,
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `status` int(11) DEFAULT '1' COMMENT '状态(1-启用,2-禁用)',
  `is_deleted` int(11) DEFAULT '0',
  `tenant_id` varchar(12) DEFAULT '000000',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_competition` (`competition_id`),
  KEY `idx_tenant` (`tenant_id`),
  KEY `idx_schedule_status` (`schedule_status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='赛程编排状态表';

-- 验证
SELECT '✓ 升级完成' AS message, COUNT(*) AS created_tables
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'
  );

步骤4: 验证结果

执行以下SQL检查:

SHOW TABLES LIKE 'martial_schedule%';

预期结果(6张表):

  • martial_schedule (旧)
  • martial_schedule_athlete (旧)
  • martial_schedule_group (新) ✓
  • martial_schedule_detail (新) ✓
  • martial_schedule_participant (新) ✓
  • martial_schedule_status (新) ✓

步骤5: 测试新系统

重启后端服务,访问:

http://localhost:3000/martial/schedule?competitionId=200

⚠️ 注意事项

  1. 不会删除旧表: 旧的 martial_schedulemartial_schedule_athlete 表会保留
  2. 数据隔离: 新旧系统使用不同的表,互不影响
  3. 安全性: 使用 CREATE TABLE IF NOT EXISTS,不会覆盖已存在的表

遇到问题?

如果创建失败,检查:

  1. 是否有 CREATE TABLE 权限
  2. 数据库名称是否正确(martial_db)
  3. 字符集是否支持 utf8mb4

创建时间: 2025-12-09 版本: v1.1