-- 升级脚本：仅为缺失的列执行 ADD，可重复执行（不会因「列已存在」报错）
-- 适用：旧库 mes_xsl_biz_entity_field_detail 缺少 detail_property_name / detail_slot_kind

SET NAMES utf8mb4;

SELECT COUNT(*) INTO @jeecg_chk_dpn FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
  AND TABLE_NAME = 'mes_xsl_biz_entity_field_detail'
  AND COLUMN_NAME = 'detail_property_name';

SET @jeecg_sql_dpn := IF(@jeecg_chk_dpn = 0,
  'ALTER TABLE mes_xsl_biz_entity_field_detail ADD COLUMN detail_property_name varchar(128) DEFAULT NULL COMMENT ''主实体明细属性名（与打印绑定 detailProperty 一致）'' AFTER profile_id',
  'SELECT ''detail_property_name 已存在，跳过'' AS msg');
PREPARE jeecg_stmt_dpn FROM @jeecg_sql_dpn;
EXECUTE jeecg_stmt_dpn;
DEALLOCATE PREPARE jeecg_stmt_dpn;

SELECT COUNT(*) INTO @jeecg_chk_dsk FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
  AND TABLE_NAME = 'mes_xsl_biz_entity_field_detail'
  AND COLUMN_NAME = 'detail_slot_kind';

SET @jeecg_sql_dsk := IF(@jeecg_chk_dsk = 0,
  'ALTER TABLE mes_xsl_biz_entity_field_detail ADD COLUMN detail_slot_kind varchar(16) DEFAULT NULL COMMENT ''LIST 或 OBJECT'' AFTER detail_property_name',
  'SELECT ''detail_slot_kind 已存在，跳过'' AS msg');
PREPARE jeecg_stmt_dsk FROM @jeecg_sql_dsk;
EXECUTE jeecg_stmt_dsk;
DEALLOCATE PREPARE jeecg_stmt_dsk;
