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


-- 修复 inventory_records 的 RLS 策略
-- 删除旧的策略
DROP POLICY IF EXISTS users_select_company_inventory ON public.inventory_records;
DROP POLICY IF EXISTS users_insert_company_inventory ON public.inventory_records;
DROP POLICY IF EXISTS users_update_company_inventory ON public.inventory_records;
DROP POLICY IF EXISTS users_delete_company_inventory ON public.inventory_records;

-- 创建新的策略：允许查看（用于仓库同步），但只允许公司自己管理
CREATE POLICY users_select_inventory ON public.inventory_records
FOR SELECT USING (true);

CREATE POLICY users_insert_inventory ON public.inventory_records
FOR INSERT WITH CHECK (
 company_id = public.get_user_master_company_id()
);

CREATE POLICY users_update_inventory ON public.inventory_records
FOR UPDATE USING (
 company_id = public.get_user_master_company_id()
);

CREATE POLICY users_delete_inventory ON public.inventory_records
FOR DELETE USING (
 company_id = public.get_user_master_company_id()
);

