iloom-flatten/migrations/20260524_170000_fix_washing_plans_rls.sql

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

-- ============================================
-- 修复水洗计划表RLS策略让水洗厂能访问关联计划
-- ============================================
-- 删除旧的SELECT策略
DROP POLICY IF EXISTS company_select_washing_plans ON washing_plans;
-- 创建新的SELECT策略允许创建公司或关联的水洗厂查看
CREATE POLICY company_select_washing_plans ON washing_plans
FOR SELECT USING (
company_id = get_user_master_company_id()
OR washing_factory_id = get_user_master_company_id()
);
-- 更新策略:只允许创建公司更新
DROP POLICY IF EXISTS company_update_washing_plans ON washing_plans;
CREATE POLICY company_update_washing_plans ON washing_plans
FOR UPDATE USING (
company_id = get_user_master_company_id()
OR washing_factory_id = get_user_master_company_id()
);
-- 添加注释说明
COMMENT ON POLICY company_select_washing_plans ON washing_plans IS '允许采购商(创建公司)或关联的水洗厂查看计划';
COMMENT ON POLICY company_update_washing_plans ON washing_plans IS '允许采购商(创建公司)或关联的水洗厂更新计划';