-- ============================================
-- 此文件由 Meoo Cloud 自动生成，请勿修改
-- This file is auto-generated by Meoo Cloud, DO NOT MODIFY
-- ============================================


-- 删除刚才创建的策略（有问题）
DROP POLICY IF EXISTS factory_select_plans_via_share ON public.production_plans;
DROP POLICY IF EXISTS factory_select_yarn_ratios_via_share ON public.yarn_ratios;
DROP POLICY IF EXISTS users_select_yarn_ratios ON public.yarn_ratios;

-- 重新创建策略：允许所有登录用户查看计划（但只能看到分享链接中展示的非敏感字段）
-- 实际敏感信息控制由前端完成
DROP POLICY IF EXISTS purchaser_select_plans ON public.production_plans;
CREATE POLICY users_select_plans ON public.production_plans
FOR SELECT USING (true);

-- yarn_ratios：允许查看（配合计划查看）
DROP POLICY IF EXISTS users_select_yarn_ratios ON public.yarn_ratios;
DROP POLICY IF EXISTS users_insert_yarn_ratios ON public.yarn_ratios;
DROP POLICY IF EXISTS users_update_yarn_ratios ON public.yarn_ratios;
DROP POLICY IF EXISTS users_delete_yarn_ratios ON public.yarn_ratios;

CREATE POLICY users_select_yarn_ratios ON public.yarn_ratios
FOR SELECT USING (true);

CREATE POLICY users_insert_yarn_ratios ON public.yarn_ratios
FOR INSERT WITH CHECK (
 company_id = public.get_user_master_company_id()
);

CREATE POLICY users_update_yarn_ratios ON public.yarn_ratios
FOR UPDATE USING (
 company_id = public.get_user_master_company_id()
);

CREATE POLICY users_delete_yarn_ratios ON public.yarn_ratios
FOR DELETE USING (
 company_id = public.get_user_master_company_id()
);

