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

DROP POLICY IF EXISTS share_links_select ON share_links; DROP POLICY IF EXISTS share_links_insert ON share_links; DROP POLICY IF EXISTS share_links_update ON share_links; CREATE POLICY share_links_select ON share_links FOR SELECT USING (created_by = auth.uid() OR EXISTS (SELECT 1 FROM profiles p WHERE p.id = auth.uid() AND p.company_id IN (SELECT purchaser_company_id FROM company_relationships WHERE factory_company_id = p.company_id)) OR short_code IS NOT NULL); CREATE POLICY share_links_insert ON share_links FOR INSERT WITH CHECK (auth.uid() IS NOT NULL); CREATE POLICY share_links_update ON share_links FOR UPDATE USING (created_by = auth.uid() OR EXISTS (SELECT 1 FROM profiles p WHERE p.id = auth.uid() AND p.company_id IN (SELECT factory_company_id FROM company_relationships WHERE purchaser_company_id = (SELECT purchaser_id FROM production_plans WHERE id = share_links.plan_id))));
