admin/sql/migrate_t_9610_order_item_concurrency_stamp.sql
zzh d1d31fee8a
All checks were successful
Build and Deploy / deploy (push) Successful in 1m43s
fix: 仓储图片上传支持 customerId,9610 明细补并发戳且主从安全
上传接口接受 query customerId;ConcurrencyStamp 默认改为空串并用主键确定性回填,避免 Galera UUID unsafe。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-11 12:09:36 +08:00

34 lines
1.2 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.

-- t_9610_order_item 补齐 Fake AggregateRoot 并发戳(幂等)
-- 现象:详情/申报查明细时报 Unknown column 'ConcurrencyStamp' in 'field list'
-- 原因:实体继承 OmsAuditedAggregateRoot → AggregateRoot 含 ConcurrencyStamp,头表有、明细表缺
-- 注意:勿用 DEFAULT (UUID())——Galera/主从会报 Statement is unsafe(副本上 UUID 不一致)
SET @db := DATABASE();
SET @has := (
SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_9610_order_item'
AND COLUMN_NAME = 'ConcurrencyStamp'
);
SET @sql := IF(
@has = 0,
'ALTER TABLE `t_9610_order_item` ADD COLUMN `ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT '''' COMMENT ''并发戳'' AFTER `IsDeleted`',
'SELECT ''skip t_9610_order_item.ConcurrencyStamp'' AS msg'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 已有行补确定性戳(基于主键,主从一致);新写入由 ORM 覆盖
UPDATE `t_9610_order_item`
SET `ConcurrencyStamp` = LOWER(CONCAT(
LPAD(HEX(`Id`), 8, '0'),
'-0000-4000-8000-',
LPAD(HEX(`Id`), 12, '0')
))
WHERE `ConcurrencyStamp` = '' OR `ConcurrencyStamp` IS NULL;