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


-- 修改 production_plans 的 SELECT 策略，允许分享链接导入时查询
DROP POLICY IF EXISTS users_select_plans ON production_plans;

CREATE POLICY users_select_plans ON production_plans
 FOR SELECT
 USING (
 purchaser_id = get_user_master_company_id()
 OR EXISTS (
 SELECT 1 FROM plan_factories
 WHERE plan_factories.plan_id = production_plans.id
 AND plan_factories.factory_id = get_user_master_company_id()
 )
 OR EXISTS (
 SELECT 1 FROM plan_factories pf
 WHERE pf.plan_id = production_plans.id
 )
 );

