All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m6s
16 lines
677 B
SQL
16 lines
677 B
SQL
-- 修复历史数据:对每个店铺取 created_at 最早的代理账号(user_type = 3)设为主账号(is_primary = true)
|
||
-- 背景:shop/service.go 创建初始账号时未设置 is_primary = true,导致 fund-summary 接口查不到主账号信息
|
||
-- 策略:DISTINCT ON (shop_id) 按 created_at ASC 取最早账号;AND is_primary = false 避免覆盖已正确的数据
|
||
UPDATE tb_account a
|
||
SET is_primary = true
|
||
FROM (
|
||
SELECT DISTINCT ON (shop_id) id
|
||
FROM tb_account
|
||
WHERE shop_id IS NOT NULL
|
||
AND user_type = 3
|
||
AND deleted_at IS NULL
|
||
ORDER BY shop_id, created_at ASC
|
||
) earliest
|
||
WHERE a.id = earliest.id
|
||
AND a.is_primary = false;
|