File size: 1,787 Bytes
3a6c182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- =============================================================================
-- Fix: PGRST205 "Could not find the table 'public.simulation_runs' in the schema cache"
-- =============================================================================
-- 1. Open Supabase Dashboard → your project → SQL Editor → New query.
-- 2. Paste and run this entire script.
-- 3. If the API still errors after ~1 minute, run the last line alone to reload PostgREST.
-- 4. Create Storage bucket "reports" (private) under Storage if you use report files.
-- =============================================================================

create table if not exists public.simulation_runs (
  id uuid primary key,
  user_id text not null,
  backend_task_id text,
  report_id text,
  status text not null default 'pending',
  requirement_preview text,
  report_storage_path text,
  report_public_url text,
  simulation_id text,
  project_id text,
  error_message text,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

create index if not exists simulation_runs_user_id_idx on public.simulation_runs (user_id);
create index if not exists simulation_runs_status_idx on public.simulation_runs (status);

alter table public.simulation_runs enable row level security;

drop policy if exists "simulation_runs_select_own" on public.simulation_runs;
create policy "simulation_runs_select_own"
  on public.simulation_runs for select
  to authenticated
  using (auth.uid()::text = user_id);

-- If the table exists but REST still returns PGRST205, wait ~1 min or pause/resume the project
-- in Dashboard → Settings. (Uncomment below only if your project supports it.)
-- select pg_notify('pgrst', 'reload schema');