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


-- 启用所有表的 RLS
ALTER TABLE public.companies ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.profiles ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.company_members ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.production_plans ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.plan_factories ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.yarn_ratios ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.warehouses ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.inventory_records ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.yarn_stock ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.plan_process_steps ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.payments ENABLE ROW LEVEL SECURITY;

-- companies: 所有人可查看，登录用户可创建/修改自己公司的
CREATE POLICY anon_select_companies ON public.companies FOR SELECT USING (true);
CREATE POLICY anon_insert_companies ON public.companies FOR INSERT WITH CHECK (true);
CREATE POLICY anon_update_companies ON public.companies FOR UPDATE USING (true);

-- profiles: 登录用户可查看所有profile，只能修改自己的
CREATE POLICY anon_select_profiles ON public.profiles FOR SELECT USING (true);
CREATE POLICY anon_insert_profiles ON public.profiles FOR INSERT WITH CHECK (true);
CREATE POLICY users_update_own_profile ON public.profiles FOR UPDATE USING (auth.uid() = id);

-- company_members: 所有人可查看和创建
CREATE POLICY anon_select_company_members ON public.company_members FOR SELECT USING (true);
CREATE POLICY anon_insert_company_members ON public.company_members FOR INSERT WITH CHECK (true);

-- production_plans: 所有人可查看，登录用户可创建/修改
CREATE POLICY anon_select_plans ON public.production_plans FOR SELECT USING (true);
CREATE POLICY anon_insert_plans ON public.production_plans FOR INSERT WITH CHECK (true);
CREATE POLICY anon_update_plans ON public.production_plans FOR UPDATE USING (true);
CREATE POLICY anon_delete_plans ON public.production_plans FOR DELETE USING (true);

-- plan_factories: 所有人可查看和操作
CREATE POLICY anon_select_plan_factories ON public.plan_factories FOR SELECT USING (true);
CREATE POLICY anon_insert_plan_factories ON public.plan_factories FOR INSERT WITH CHECK (true);
CREATE POLICY anon_delete_plan_factories ON public.plan_factories FOR DELETE USING (true);

-- yarn_ratios: 所有人可查看和操作
CREATE POLICY anon_select_yarn_ratios ON public.yarn_ratios FOR SELECT USING (true);
CREATE POLICY anon_insert_yarn_ratios ON public.yarn_ratios FOR INSERT WITH CHECK (true);
CREATE POLICY anon_delete_yarn_ratios ON public.yarn_ratios FOR DELETE USING (true);

-- warehouses: 所有人可查看和操作
CREATE POLICY anon_select_warehouses ON public.warehouses FOR SELECT USING (true);
CREATE POLICY anon_insert_warehouses ON public.warehouses FOR INSERT WITH CHECK (true);
CREATE POLICY anon_update_warehouses ON public.warehouses FOR UPDATE USING (true);

-- inventory_records: 所有人可查看和操作
CREATE POLICY anon_select_inventory ON public.inventory_records FOR SELECT USING (true);
CREATE POLICY anon_insert_inventory ON public.inventory_records FOR INSERT WITH CHECK (true);

-- yarn_stock: 所有人可查看和操作
CREATE POLICY anon_select_yarn_stock ON public.yarn_stock FOR SELECT USING (true);
CREATE POLICY anon_insert_yarn_stock ON public.yarn_stock FOR INSERT WITH CHECK (true);
CREATE POLICY anon_update_yarn_stock ON public.yarn_stock FOR UPDATE USING (true);

-- plan_process_steps: 所有人可查看和操作
CREATE POLICY anon_select_process_steps ON public.plan_process_steps FOR SELECT USING (true);
CREATE POLICY anon_insert_process_steps ON public.plan_process_steps FOR INSERT WITH CHECK (true);
CREATE POLICY anon_update_process_steps ON public.plan_process_steps FOR UPDATE USING (true);

-- payments: 所有人可查看和操作
CREATE POLICY anon_select_payments ON public.payments FOR SELECT USING (true);
CREATE POLICY anon_insert_payments ON public.payments FOR INSERT WITH CHECK (true);
CREATE POLICY anon_update_payments ON public.payments FOR UPDATE USING (true);

