Files
SupplierSystem/migrations/20261041_main_supplier_bindings_backfill_source.sql
雨天 17957fe120
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
fix(主系统绑定): 回填绑定标为 backfill、绑定时间按本地时区
迁移 20261031 两处回填的 source 由 manual 改 backfill(与超管手工登记可区分,符合设计 V10),新增迁移 20261041 回标存量行(按 note 精确识别、幂等),服务层 source 类型同步;BranchManagement 绑定弹层时间改本地时区(原按 UTC 截断,差 8 小时)。
2026-10-13 10:45:56 +08:00

32 lines
1.6 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.
-- 修正:存量「迁移回填」的绑定行 `source` 由 'manual' 回标为 'backfill'。
--
-- 为什么:`migrations/20261031_main_supplier_bindings.sql` 的回填把 `source` 硬写成 'manual'
-- ⇒ 与"超管在分公司管理里手工登记"**不可区分**,违反设计验收项 V10
-- (docs/design/20261027-分公司接入编码与主系统供应商绑定.md §6「回填的绑定行 source 标注可区分」)。
-- 现象与处置:docs/design/20261013-主系统订单被本地拉取机制与绑定缺陷.md(缺陷 D1)。
--
-- 隔离边界(勿破):
-- 1) 只改 `public.main_supplier_bindings.source` **一列**;不碰任何租户业务表、不改 `branch_code`、
-- 不改绑定的 active/unbound 状态、不改 `bound_at`;
-- 2) 按 `note` 精确识别回填行(回填写的是"迁移回填:…"),**不误伤**真·手工行(note="超管手工登记");
-- 3) 幂等:回标后 `source <> 'manual'`,第二次跑无匹配行。
UPDATE public.main_supplier_bindings
SET source = 'backfill'
WHERE source = 'manual'
AND note LIKE '迁移回填%';
DO $$
BEGIN
IF to_regclass('public.main_supplier_bindings') IS NULL THEN
RAISE EXCEPTION '迁移未生效:public.main_supplier_bindings 不存在';
END IF;
-- 自证:回标后不应再有"迁移回填 且 source=manual"的行
IF EXISTS (
SELECT 1 FROM public.main_supplier_bindings
WHERE source = 'manual' AND note LIKE '迁移回填%'
) THEN
RAISE EXCEPTION '迁移未生效:仍存在 source=manual 的迁移回填行';
END IF;
END $$;