Files
yunzerwebsiteallinone/go/docs/sql/cleanup_pending_register_identity.sql
T
2026-10-31 01:21:55 +08:00

28 lines
1.2 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.
-- 清理「注册未完成」的残留身份(历史遗留)。
-- 旧版本在第一步核验通过时就建号,第二步企业归属超时未完成时,
-- 账号名/手机号被占用却无法使用,重新注册会提示「该账号已被占用」。
-- 新版本已做到:第二步才建号 + 令牌过期回滚 + 校验时自动回收孤儿身份,
-- 本脚本仅用于手动清理历史残留(注意:account / mobile 有唯一索引,
-- 软删仍然占着索引,因此这里用物理删除)。
--
-- ① 先查:确认这些身份确实没企业归属、也没登录过
SELECT i.id, i.account, i.mobile, i.nickname, i.create_time
FROM yz_auth_identity i
WHERE i.last_login_at IS NULL
AND NOT EXISTS (
SELECT 1 FROM yz_auth_tenant_user t
WHERE t.identity_id = i.id AND t.delete_time IS NULL
)
AND NOT EXISTS (
SELECT 1 FROM yz_auth_tenant_apply a
WHERE a.identity_id = i.id AND a.delete_time IS NULL
);
-- ② 再清:把 '账号名' 换成第①步查到的账号(手机号注册则改用 mobile = '手机号')
DELETE FROM yz_auth_identity_third
WHERE identity_id IN (
SELECT id FROM (SELECT id FROM yz_auth_identity WHERE account = '账号名') x
);
DELETE FROM yz_auth_identity WHERE account = '账号名';