From 0c89ec6ce5336c1555aaa29ceacea2c1c30efb79 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Thu, 29 Oct 2026 18:38:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BB=A3=E7=90=86=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E8=A1=A5=E5=85=85=20ConcurrencyStamp?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=20MySQL=201674?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- sql/migrate_agent_module_20261029.sql | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/sql/migrate_agent_module_20261029.sql b/sql/migrate_agent_module_20261029.sql index 78a5ba3..ef74284 100644 --- a/sql/migrate_agent_module_20261029.sql +++ b/sql/migrate_agent_module_20261029.sql @@ -1,5 +1,6 @@ -- 渠道代理与返佣(首版轻量)。可重复执行。 -- 含:t_agent、t_agent_commission_detail;t_customer / t_order 扩展 AgentId。 +-- AggregateRoot 需要 ConcurrencyStamp。 SET @db := DATABASE(); @@ -22,11 +23,25 @@ CREATE TABLE IF NOT EXISTS `t_agent` ( `CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `UpdateUserId` INT NOT NULL DEFAULT 0, `UpdateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + -- 不用 DEFAULT(UUID()):statement 复制下会报 1674;运行时由 ORM 写入 + `ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT '' COMMENT '并发戳', PRIMARY KEY (`Id`), KEY `ix_agent_code` (`AgentCode`), KEY `ix_agent_userid` (`UserId`) ) COMMENT='渠道代理主数据'; +-- 已建表补 ConcurrencyStamp(可重复) +SET @exists := ( + SELECT COUNT(1) FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_agent' AND COLUMN_NAME = 'ConcurrencyStamp' +); +SET @sql := IF( + @exists = 0, + 'ALTER TABLE `t_agent` ADD COLUMN `ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT '''' COMMENT ''并发戳'' AFTER `UpdateTime`', + 'SELECT ''t_agent.ConcurrencyStamp already exists'' AS info' +); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; + -- ---------- t_agent_commission_detail ---------- CREATE TABLE IF NOT EXISTS `t_agent_commission_detail` ( `Id` INT NOT NULL AUTO_INCREMENT, @@ -47,12 +62,24 @@ CREATE TABLE IF NOT EXISTS `t_agent_commission_detail` ( `CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `UpdateUserId` INT NOT NULL DEFAULT 0, `UpdateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT '' COMMENT '并发戳', PRIMARY KEY (`Id`), KEY `ix_agent_comm_agent` (`AgentId`), KEY `ix_agent_comm_order` (`OrderId`), KEY `ix_agent_comm_status` (`Status`) ) COMMENT='代理返佣明细(首版无余额入账)'; +SET @exists := ( + SELECT COUNT(1) FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_agent_commission_detail' AND COLUMN_NAME = 'ConcurrencyStamp' +); +SET @sql := IF( + @exists = 0, + 'ALTER TABLE `t_agent_commission_detail` ADD COLUMN `ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT '''' COMMENT ''并发戳'' AFTER `UpdateTime`', + 'SELECT ''t_agent_commission_detail.ConcurrencyStamp already exists'' AS info' +); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; + -- ---------- t_customer.AgentId ---------- SET @exists := ( SELECT COUNT(1) FROM information_schema.COLUMNS