admin/sql/migrate_customer_wechat_unionid_20261112.sql
zzh c2eae1c327
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
feat: 落库微信 UnionID,支持换公众号昵称+手机号迁移 OpenID
注册/绑定写入 UnionID;授权登录可回填。换公众号时昵称命中存量客户可凭手机号确认,更新 WechatOpenid 与 UnionID 后登录。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 16:34:50 +08:00

37 lines
1.1 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.

-- 客户表增加微信 UnionID(可重复执行;禁止 UNIQUE)
-- 用途:微信扫码/授权注册与绑定落库 UnionID,便于开放平台下跨应用识别
SET @db := DATABASE();
SET @exists := (
SELECT COUNT(1)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_customer'
AND COLUMN_NAME = 'WechatUnionid'
);
SET @sql := IF(
@exists = 0,
'ALTER TABLE `t_customer` ADD COLUMN `WechatUnionid` VARCHAR(64) NULL COMMENT ''微信UnionID(开放平台)'' AFTER `WechatOpenid`',
'SELECT ''t_customer.WechatUnionid already exists'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @idx_exists := (
SELECT COUNT(1)
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_customer'
AND INDEX_NAME = 'ix_cus_wechat_unionid'
);
SET @sql := IF(
@idx_exists = 0,
'ALTER TABLE `t_customer` ADD KEY `ix_cus_wechat_unionid` (`WechatUnionid`)',
'SELECT ''ix_cus_wechat_unionid already exists'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;