Files
SupplierSystem/migrations/20261076_report_push_queue_branch_isolation.sql
T
Ubuntu 13efb78141
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(报告推送): 补核查影响——分拣/出库来源也入队(否则报告最多晚 24h)、僵尸任务收口告警、队列表分公司隔离 RLS + 按分公司处理
2026-10-24 13:05:30 +08:00

25 lines
1.3 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.
-- 报告推送队列:**分公司隔离**(2026-10-24 核查项 6)
--
-- 背景:`public.main_system_report_push_queue` 建表时没有 RLS,而租户角色 `canteen_app_rls`
-- 默认拿到 INSERT/SELECT/UPDATE/DELETE ⇒ 租户连接理论上能读写**其它分公司**的队列行。
-- 队列本身不含敏感业务数据,但按本项目"schema 级隔离"纪律应当收口。
--
-- 口径:
-- · 有租户上下文(`app.branch_code` 非空)⇒ 只能看/改自己分公司的行;
-- · 无租户上下文(调度器 / 运维 / 主系统对账)⇒ 放行(否则 worker 跨分公司处理会被拦死);
-- · 用 FORCE 让表 owner 也受限(本项目核心表同款作风),策略里对空上下文开白。
ALTER TABLE public.main_system_report_push_queue ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.main_system_report_push_queue FORCE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS report_push_queue_branch_isolation ON public.main_system_report_push_queue;
CREATE POLICY report_push_queue_branch_isolation ON public.main_system_report_push_queue
USING (
COALESCE(current_setting('app.branch_code', true), '') = ''
OR branch_code = current_setting('app.branch_code', true)
)
WITH CHECK (
COALESCE(current_setting('app.branch_code', true), '') = ''
OR branch_code = current_setting('app.branch_code', true)
);