-- 1.0.325.sql  WP-C 齐套口径统一：为齐套结果头补来源标记
--   D-A02：排产（净口径）与手动检查（毛口径）写同一张 b_examine_result 且互相覆盖，
--          事后无法判断某条结论出自哪条路径。bangid 列早已存在但从未写入。
--   幂等：经 information_schema 判列是否存在，可重复执行。
--   行尾必须 LF（CRLF 会导致 SHA256 与 sys_db_migration_log 不一致并阻止启动）。
SET NAMES utf8mb4;

SET @ddl := (SELECT IF(
  EXISTS(SELECT 1 FROM information_schema.COLUMNS
         WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'b_examine_result' AND COLUMN_NAME = 'check_scope'),
  'SELECT 1',
  'ALTER TABLE b_examine_result ADD COLUMN check_scope VARCHAR(20) NULL COMMENT ''触发来源：SCHEDULE=排产内嵌/RELEASE=工单下达/SINGLE=手动单工单/BATCH=批量/REVIEW=订单评审'' AFTER bangid'));
PREPARE s FROM @ddl; EXECUTE s; DEALLOCATE PREPARE s;

SET @ddl := (SELECT IF(
  EXISTS(SELECT 1 FROM information_schema.COLUMNS
         WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'b_examine_result' AND COLUMN_NAME = 'net_scope'),
  'SELECT 1',
  'ALTER TABLE b_examine_result ADD COLUMN net_scope TINYINT(1) NULL DEFAULT 0 COMMENT ''1=净口径（已扣同版本占用）；0=毛口径'' AFTER check_scope'));
PREPARE s FROM @ddl; EXECUTE s; DEALLOCATE PREPARE s;