You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
2.0 KiB
41 lines
2.0 KiB
|
2 days ago
|
-- ----------------------------
|
||
|
|
-- convert_relation_entry 补反写回滚所需的两个字段。
|
||
|
|
--
|
||
|
|
-- 背景:ConvertRelationEntry 实体上声明了 beforeValue / writebackRuleVersion,
|
||
|
|
-- 但 DDL 没跟上,MyBatis-Plus 查询会带上这两列,导致
|
||
|
|
-- Unknown column 'before_value' in 'field list'
|
||
|
|
-- 反写(WriteBackOrchestrator#loadRelationEntries)与转换落库都会直接报错。
|
||
|
|
--
|
||
|
|
-- 请在 tenant-admin 服务指向的默认数据库执行该脚本;脚本可重复执行。
|
||
|
|
-- ----------------------------
|
||
|
|
SET NAMES utf8mb4;
|
||
|
|
SET FOREIGN_KEY_CHECKS = 0;
|
||
|
|
|
||
|
|
-- ----------------------------
|
||
|
|
-- 1. before_value:反写前的源单字段原值。
|
||
|
|
-- 只有「覆盖」方式需要——累加/扣减天然可逆,覆盖把原值冲掉了,不记下来撤销时就回不去。
|
||
|
|
-- ----------------------------
|
||
|
|
SET @ddl = (SELECT IF(COUNT(*) = 0,
|
||
|
|
'ALTER TABLE `convert_relation_entry` ADD COLUMN `before_value` decimal(24,8) DEFAULT NULL COMMENT ''反写前的源单字段原值,仅覆盖方式使用,供撤销回滚恢复''',
|
||
|
|
'DO 0')
|
||
|
|
FROM information_schema.columns
|
||
|
|
WHERE table_schema = DATABASE() AND table_name = 'convert_relation_entry' AND column_name = 'before_value');
|
||
|
|
PREPARE stmt FROM @ddl;
|
||
|
|
EXECUTE stmt;
|
||
|
|
DEALLOCATE PREPARE stmt;
|
||
|
|
|
||
|
|
-- ----------------------------
|
||
|
|
-- 2. writeback_rule_version:本次反写实际使用的反写规则版本。
|
||
|
|
-- 撤销/弃审时按该版本取快照执行,保证「怎么加的就怎么退」。
|
||
|
|
-- ----------------------------
|
||
|
|
SET @ddl = (SELECT IF(COUNT(*) = 0,
|
||
|
|
'ALTER TABLE `convert_relation_entry` ADD COLUMN `writeback_rule_version` int DEFAULT NULL COMMENT ''本次反写使用的反写规则版本,供撤销回滚按同一版本执行''',
|
||
|
|
'DO 0')
|
||
|
|
FROM information_schema.columns
|
||
|
|
WHERE table_schema = DATABASE() AND table_name = 'convert_relation_entry' AND column_name = 'writeback_rule_version');
|
||
|
|
PREPARE stmt FROM @ddl;
|
||
|
|
EXECUTE stmt;
|
||
|
|
DEALLOCATE PREPARE stmt;
|
||
|
|
|
||
|
|
SET FOREIGN_KEY_CHECKS = 1;
|