CREATE TABLE IF NOT EXISTS training_knowledge_file (
  id varchar(64) NOT NULL,
  source_type varchar(32) NOT NULL COMMENT 'CASE/STUDENT_UPLOAD',
  config_scope varchar(32) NOT NULL COMMENT 'ADMIN/TEACHER/STUDENT',
  effective_config_id varchar(64) NOT NULL,
  task_id varchar(64) NOT NULL,
  task_key varchar(128) NOT NULL,
  teaching_class_id varchar(64) NULL,
  student_user_id varchar(64) NULL,
  step_no int NULL,
  file_name varchar(512) NOT NULL,
  file_url varchar(1024) NOT NULL,
  content_hash varchar(128) NULL,
  parse_status varchar(32) NOT NULL COMMENT 'SUCCESS/PENDING_VISION/EMPTY/FAILED',
  parse_message varchar(1000) NULL,
  section_count int NOT NULL DEFAULT 0,
  create_time datetime NOT NULL,
  update_time datetime NOT NULL,
  PRIMARY KEY (id),
  KEY idx_training_knowledge_file_scope (source_type, effective_config_id, student_user_id),
  KEY idx_training_knowledge_file_task (task_key, teaching_class_id, student_user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS training_knowledge_chunk (
  id varchar(64) NOT NULL,
  knowledge_file_id varchar(64) NOT NULL,
  task_key varchar(128) NOT NULL,
  effective_config_id varchar(64) NOT NULL,
  teaching_class_id varchar(64) NULL,
  student_user_id varchar(64) NULL,
  step_no int NULL,
  section_type varchar(32) NOT NULL,
  section_name varchar(512) NULL,
  section_sequence int NOT NULL,
  content longtext NOT NULL,
  create_time datetime NOT NULL,
  PRIMARY KEY (id),
  KEY idx_training_knowledge_chunk_file (knowledge_file_id),
  KEY idx_training_knowledge_chunk_scope (task_key, effective_config_id, teaching_class_id, student_user_id, step_no)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
