elder-yudao-pro/mysql_script/health/V016__platform_identity_bridge.sql

29 lines
1.7 KiB
SQL
Raw Permalink 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.

-- Platform 身份桥:为原生会员接口补 email 字段,并显式映射既有 Pro 健康档案。
-- 不假定 health_elderly_profile.id 与 elderly_person.id 相同;不自动复制/覆盖业务数据。
SET NAMES utf8mb4;
SET @platform_email_ddl = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'member_user' AND COLUMN_NAME = 'email') = 0,
'ALTER TABLE `member_user` ADD COLUMN `email` varchar(50) NULL DEFAULT NULL COMMENT ''邮箱(Platform 会员资料兼容)''',
'SELECT 1'
);
PREPARE platform_email_stmt FROM @platform_email_ddl;
EXECUTE platform_email_stmt;
DEALLOCATE PREPARE platform_email_stmt;
CREATE TABLE IF NOT EXISTS `health_platform_profile_link` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '身份桥编号',
`health_profile_id` bigint NOT NULL COMMENT 'Pro 老人健康档案编号(health_elderly_profile.id)',
`elderly_id` bigint NOT NULL COMMENT 'Platform 老人档案编号(elderly_person.id)',
`creator` varchar(64) DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_health_platform_profile` (`tenant_id`, `health_profile_id`),
UNIQUE KEY `uk_platform_elderly_profile` (`tenant_id`, `elderly_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Pro 健康档案与 Platform 老人档案显式映射';