CREATE TABLE IF NOT EXISTS public.simulations ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), process_id uuid NOT NULL REFERENCES public.processes(id) ON DELETE CASCADE, executed_at bigint NOT NULL, result jsonb NOT NULL, result_automated jsonb, created_at timestamptz NOT NULL DEFAULT now() ); CREATE INDEX IF NOT EXISTS simulations_process_executed_idx ON public.simulations(process_id, executed_at DESC); ALTER TABLE public.simulations ENABLE ROW LEVEL SECURITY; CREATE POLICY "all_simulations" ON public.simulations FOR ALL USING (auth.uid() IS NOT NULL) WITH CHECK (auth.uid() IS NOT NULL);