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


-- warehouses 表 RLS 策略
CREATE POLICY users_select_company_warehouses ON public.warehouses
FOR SELECT USING (
 company_id = public.get_user_master_company_id()
);

CREATE POLICY users_insert_company_warehouses ON public.warehouses
FOR INSERT WITH CHECK (
 company_id = public.get_user_master_company_id()
);

CREATE POLICY users_update_company_warehouses ON public.warehouses
FOR UPDATE USING (
 company_id = public.get_user_master_company_id()
);

CREATE POLICY users_delete_company_warehouses ON public.warehouses
FOR DELETE USING (
 company_id = public.get_user_master_company_id()
);

-- inventory_records 表 RLS 策略
-- 通过 warehouse 关联到公司
CREATE POLICY users_select_company_inventory ON public.inventory_records
FOR SELECT USING (
 EXISTS (
 SELECT 1 FROM public.warehouses
 WHERE id = warehouse_id AND company_id = public.get_user_master_company_id()
 )
);

CREATE POLICY users_insert_company_inventory ON public.inventory_records
FOR INSERT WITH CHECK (
 EXISTS (
 SELECT 1 FROM public.warehouses
 WHERE id = warehouse_id AND company_id = public.get_user_master_company_id()
 )
);

