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

DROP POLICY IF EXISTS anon_select_companies ON companies; DROP POLICY IF EXISTS purchaser_select_linked_companies ON companies; DROP POLICY IF EXISTS factory_select_linked_companies ON companies; CREATE POLICY users_select_own_company ON companies FOR SELECT USING (id = get_user_master_company_id()); CREATE POLICY purchaser_select_linked_factories ON companies FOR SELECT USING (role IN ('textile', 'washing') AND EXISTS (SELECT 1 FROM company_relationships WHERE company_relationships.purchaser_company_id = get_user_master_company_id() AND company_relationships.factory_company_id = companies.id AND company_relationships.status = 'active')); CREATE POLICY factory_select_linked_purchasers ON companies FOR SELECT USING (role = 'purchaser' AND EXISTS (SELECT 1 FROM company_relationships WHERE company_relationships.factory_company_id = get_user_master_company_id() AND company_relationships.purchaser_company_id = companies.id AND company_relationships.status = 'active'));
