admin/sql/migrate_t_order_exception_event_handler.sql
zzh 2018e45a7d feat: 代发进度统计、申报HS分列与异常事件表迁移脚本
补充代发进度 Tab 计数、PrimarySkuCodes 与 Im/Ex HS 编码输出;新增 t_order_exception_event 幂等迁移(Handler*、ConcurrencyStamp)并同步 db.sql。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-20 17:06:16 +08:00

119 lines
3.4 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 订单异常事件表:补齐 Handler* / ConcurrencyStamp(幂等;列已存在则自动跳过)
-- 修复:Unknown column 'HandlerNames' / 'ConcurrencyStamp' in 'field list'
-- MySQL 5.7+ / 8.0
SET @db := DATABASE();
-- HandlerNames
SET @col := (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_order_exception_event'
AND COLUMN_NAME = 'HandlerNames'
);
SET @sql := IF(
@col = 0,
'ALTER TABLE `t_order_exception_event` ADD COLUMN `HandlerNames` VARCHAR(256) NULL COMMENT ''处理人快照''',
'SELECT ''skip HandlerNames'' AS msg'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- HandlerType
SET @col := (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_order_exception_event'
AND COLUMN_NAME = 'HandlerType'
);
SET @sql := IF(
@col = 0,
'ALTER TABLE `t_order_exception_event` ADD COLUMN `HandlerType` VARCHAR(16) NULL COMMENT ''处理人类型''',
'SELECT ''skip HandlerType'' AS msg'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- HandlerUserId
SET @col := (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_order_exception_event'
AND COLUMN_NAME = 'HandlerUserId'
);
SET @sql := IF(
@col = 0,
'ALTER TABLE `t_order_exception_event` ADD COLUMN `HandlerUserId` INT NULL COMMENT ''处理人用户Id(customer 时为订单客户账号)''',
'SELECT ''skip HandlerUserId'' AS msg'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- ConcurrencyStamp(AggregateRoot 并发戳;避免 DEFAULT(UUID()) 触发 1674 复制不安全)
SET @col := (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_order_exception_event'
AND COLUMN_NAME = 'ConcurrencyStamp'
);
SET @sql := IF(
@col = 0,
'ALTER TABLE `t_order_exception_event` ADD COLUMN `ConcurrencyStamp` CHAR(36) NULL COMMENT ''并发戳''',
'SELECT ''skip ConcurrencyStamp add'' AS msg'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @col := (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_order_exception_event'
AND COLUMN_NAME = 'ConcurrencyStamp'
);
SET @sql := IF(
@col > 0,
'UPDATE `t_order_exception_event`
SET `ConcurrencyStamp` = LOWER(CONCAT(
LPAD(HEX(`Id`), 8, ''0''),
''-0000-4000-8000-'',
LPAD(HEX(`Id` * 9973), 12, ''0'')
))
WHERE `ConcurrencyStamp` IS NULL OR `ConcurrencyStamp` = ''''',
'SELECT ''skip ConcurrencyStamp backfill'' AS msg'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @col := (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_order_exception_event'
AND COLUMN_NAME = 'ConcurrencyStamp'
);
SET @isNullable := (
SELECT IFNULL(MAX(CASE WHEN IS_NULLABLE = 'YES' THEN 1 ELSE 0 END), 0)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_order_exception_event'
AND COLUMN_NAME = 'ConcurrencyStamp'
);
SET @sql := IF(
@col > 0 AND @isNullable = 1,
'ALTER TABLE `t_order_exception_event` MODIFY COLUMN `ConcurrencyStamp` CHAR(36) NOT NULL COMMENT ''并发戳''',
'SELECT ''skip ConcurrencyStamp not null'' AS msg'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;