ALTER TABLE school_class
  ADD COLUMN created_by VARCHAR(64) NULL COMMENT 'class creator user id',
  ADD COLUMN class_type VARCHAR(20) NOT NULL DEFAULT 'ADMIN' COMMENT '班级类型：ADMIN-行政班 TEACHING-教学班',
  ADD COLUMN data_source VARCHAR(20) NOT NULL DEFAULT 'LOCAL' COMMENT '数据来源：LOCAL-本系统 ZHIYUN-智云',
  ADD COLUMN source_class_ids TEXT NULL COMMENT '教学班来源行政班ID列表';

CREATE TABLE IF NOT EXISTS teaching_class_student (
  id VARCHAR(64) NOT NULL PRIMARY KEY,
  teaching_class_id VARCHAR(64) NOT NULL COMMENT '教学班ID',
  student_user_id VARCHAR(64) NOT NULL COMMENT '学生用户ID',
  admin_class_id VARCHAR(64) NOT NULL COMMENT '学生行政班ID快照',
  status VARCHAR(32) NOT NULL DEFAULT 'IN_PROGRESS' COMMENT '成员状态',
  join_reason VARCHAR(32) NULL COMMENT '加入原因',
  join_time DATETIME NULL COMMENT '加入时间',
  exit_time DATETIME NULL COMMENT '退出时间',
  create_time DATETIME NULL COMMENT '创建时间',
  UNIQUE KEY uk_teaching_class_student (teaching_class_id, student_user_id),
  KEY idx_teaching_class_student_student (student_user_id),
  KEY idx_teaching_class_student_admin_class (admin_class_id)
) COMMENT='教学班学生成员关系';

CREATE TABLE IF NOT EXISTS external_resource_mapping (
  id VARCHAR(64) NOT NULL PRIMARY KEY,
  source_system VARCHAR(32) NOT NULL COMMENT '外部来源系统',
  resource_type VARCHAR(32) NOT NULL COMMENT '资源类型',
  local_id VARCHAR(64) NOT NULL COMMENT '本系统ID',
  external_id VARCHAR(128) NOT NULL COMMENT '外部系统ID',
  external_code VARCHAR(128) NULL COMMENT '外部编码',
  external_name VARCHAR(255) NULL COMMENT '外部名称快照',
  create_time DATETIME NULL COMMENT '创建时间',
  update_time DATETIME NULL COMMENT '更新时间',
  UNIQUE KEY uk_external_resource (source_system, resource_type, external_id),
  KEY idx_external_resource_local (resource_type, local_id)
) COMMENT='外部系统资源映射';
