20261030 #18
@ -1,5 +1,6 @@
|
|||||||
-- 渠道代理与返佣(首版轻量)。可重复执行。
|
-- 渠道代理与返佣(首版轻量)。可重复执行。
|
||||||
-- 含:t_agent、t_agent_commission_detail;t_customer / t_order 扩展 AgentId。
|
-- 含:t_agent、t_agent_commission_detail;t_customer / t_order 扩展 AgentId。
|
||||||
|
-- AggregateRoot 需要 ConcurrencyStamp。
|
||||||
|
|
||||||
SET @db := DATABASE();
|
SET @db := DATABASE();
|
||||||
|
|
||||||
@ -22,11 +23,25 @@ CREATE TABLE IF NOT EXISTS `t_agent` (
|
|||||||
`CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
`UpdateUserId` INT NOT NULL DEFAULT 0,
|
`UpdateUserId` INT NOT NULL DEFAULT 0,
|
||||||
`UpdateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
`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`),
|
PRIMARY KEY (`Id`),
|
||||||
KEY `ix_agent_code` (`AgentCode`),
|
KEY `ix_agent_code` (`AgentCode`),
|
||||||
KEY `ix_agent_userid` (`UserId`)
|
KEY `ix_agent_userid` (`UserId`)
|
||||||
) COMMENT='渠道代理主数据';
|
) 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 ----------
|
-- ---------- t_agent_commission_detail ----------
|
||||||
CREATE TABLE IF NOT EXISTS `t_agent_commission_detail` (
|
CREATE TABLE IF NOT EXISTS `t_agent_commission_detail` (
|
||||||
`Id` INT NOT NULL AUTO_INCREMENT,
|
`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,
|
`CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
`UpdateUserId` INT NOT NULL DEFAULT 0,
|
`UpdateUserId` INT NOT NULL DEFAULT 0,
|
||||||
`UpdateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
`UpdateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
`ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT '' COMMENT '并发戳',
|
||||||
PRIMARY KEY (`Id`),
|
PRIMARY KEY (`Id`),
|
||||||
KEY `ix_agent_comm_agent` (`AgentId`),
|
KEY `ix_agent_comm_agent` (`AgentId`),
|
||||||
KEY `ix_agent_comm_order` (`OrderId`),
|
KEY `ix_agent_comm_order` (`OrderId`),
|
||||||
KEY `ix_agent_comm_status` (`Status`)
|
KEY `ix_agent_comm_status` (`Status`)
|
||||||
) COMMENT='代理返佣明细(首版无余额入账)';
|
) 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 ----------
|
-- ---------- t_customer.AgentId ----------
|
||||||
SET @exists := (
|
SET @exists := (
|
||||||
SELECT COUNT(1) FROM information_schema.COLUMNS
|
SELECT COUNT(1) FROM information_schema.COLUMNS
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user