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

CREATE TABLE IF NOT EXISTS public.audit_logs (id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID REFERENCES auth.users(id) ON DELETE SET NULL, company_id UUID REFERENCES public.companies(id) ON DELETE SET NULL, action TEXT NOT NULL, resource_type TEXT NOT NULL, resource_id UUID, details JSONB, ip_address TEXT, user_agent TEXT, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()); CREATE INDEX idx_audit_logs_user_id ON public.audit_logs(user_id); CREATE INDEX idx_audit_logs_company_id ON public.audit_logs(company_id); CREATE INDEX idx_audit_logs_action ON public.audit_logs(action); CREATE INDEX idx_audit_logs_created_at ON public.audit_logs(created_at DESC); ALTER TABLE public.audit_logs ENABLE ROW LEVEL SECURITY; CREATE POLICY users_select_company_audit_logs ON public.audit_logs FOR SELECT USING (company_id = public.get_user_master_company_id()); CREATE POLICY users_insert_audit_logs ON public.audit_logs FOR INSERT WITH CHECK (true);
