-- =====================================================
-- 迁移脚本: 创建缺失的表
-- 版本: V4
-- 描述: 创建 contact, exception_event, judge_project, team 等表
-- 日期: 2026-01-13
-- =====================================================

-- 1. martial_contact 联系人表
CREATE TABLE IF NOT EXISTS martial_contact (
    id bigint NOT NULL,
    user_id bigint DEFAULT NULL COMMENT '用户ID',
    name varchar(100) DEFAULT NULL COMMENT '联系人姓名',
    phone varchar(20) DEFAULT NULL COMMENT '联系电话',
    organization varchar(200) DEFAULT NULL COMMENT '所属单位',
    is_default tinyint DEFAULT 0 COMMENT '是否默认',
    tenant_id varchar(12) DEFAULT '000000',
    create_user bigint DEFAULT NULL,
    create_dept bigint DEFAULT NULL,
    create_time datetime DEFAULT NULL,
    update_user bigint DEFAULT NULL,
    update_time datetime DEFAULT NULL,
    status int DEFAULT 1,
    is_deleted int DEFAULT 0,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='联系人表';

-- 2. martial_exception_event 异常事件表
CREATE TABLE IF NOT EXISTS martial_exception_event (
    id bigint NOT NULL,
    competition_id bigint DEFAULT NULL COMMENT '赛事ID',
    schedule_id bigint DEFAULT NULL COMMENT '编排ID',
    athlete_id bigint DEFAULT NULL COMMENT '运动员ID',
    event_type varchar(50) DEFAULT NULL COMMENT '事件类型',
    description text COMMENT '事件描述',
    handler_id bigint DEFAULT NULL COMMENT '处理人ID',
    handle_time datetime DEFAULT NULL COMMENT '处理时间',
    handle_result text COMMENT '处理结果',
    tenant_id varchar(12) DEFAULT '000000',
    create_user bigint DEFAULT NULL,
    create_dept bigint DEFAULT NULL,
    create_time datetime DEFAULT NULL,
    update_user bigint DEFAULT NULL,
    update_time datetime DEFAULT NULL,
    status int DEFAULT 1,
    is_deleted int DEFAULT 0,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='异常事件表';

-- 3. martial_judge_project 裁判项目关联表
CREATE TABLE IF NOT EXISTS martial_judge_project (
    id bigint NOT NULL,
    judge_id bigint DEFAULT NULL COMMENT '裁判ID',
    project_id bigint DEFAULT NULL COMMENT '项目ID',
    competition_id bigint DEFAULT NULL COMMENT '赛事ID',
    role_type varchar(50) DEFAULT NULL COMMENT '角色类型',
    tenant_id varchar(12) DEFAULT '000000',
    create_user bigint DEFAULT NULL,
    create_dept bigint DEFAULT NULL,
    create_time datetime DEFAULT NULL,
    update_user bigint DEFAULT NULL,
    update_time datetime DEFAULT NULL,
    status int DEFAULT 1,
    is_deleted int DEFAULT 0,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='裁判项目关联表';

-- 4. martial_team 团队表
CREATE TABLE IF NOT EXISTS martial_team (
    id bigint NOT NULL,
    competition_id bigint DEFAULT NULL COMMENT '赛事ID',
    project_id bigint DEFAULT NULL COMMENT '项目ID',
    order_id bigint DEFAULT NULL COMMENT '订单ID',
    team_name varchar(200) DEFAULT NULL COMMENT '团队名称',
    organization varchar(200) DEFAULT NULL COMMENT '所属单位',
    member_count int DEFAULT 0 COMMENT '成员数量',
    tenant_id varchar(12) DEFAULT '000000',
    create_user bigint DEFAULT NULL,
    create_dept bigint DEFAULT NULL,
    create_time datetime DEFAULT NULL,
    update_user bigint DEFAULT NULL,
    update_time datetime DEFAULT NULL,
    status int DEFAULT 1,
    is_deleted int DEFAULT 0,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='团队表';

-- 5. martial_team_member 团队成员表
CREATE TABLE IF NOT EXISTS martial_team_member (
    id bigint NOT NULL,
    team_id bigint DEFAULT NULL COMMENT '团队ID',
    athlete_id bigint DEFAULT NULL COMMENT '运动员ID',
    role varchar(50) DEFAULT NULL COMMENT '角色',
    sequence int DEFAULT 0 COMMENT '顺序',
    tenant_id varchar(12) DEFAULT '000000',
    create_user bigint DEFAULT NULL,
    create_dept bigint DEFAULT NULL,
    create_time datetime DEFAULT NULL,
    update_user bigint DEFAULT NULL,
    update_time datetime DEFAULT NULL,
    status int DEFAULT 1,
    is_deleted int DEFAULT 0,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='团队成员表';
