File size: 1,638 Bytes
7ba2f95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
-- =====================================================================
-- SignalMod — Predictions table setup
-- Run this in Supabase SQL Editor:
--   Dashboard → SQL Editor → New query → paste this → Run
-- =====================================================================

-- 1. Table
create table if not exists public.predictions (
    id          bigserial primary key,
    created_at  timestamptz not null default now(),
    text        text not null,
    video_id    text,
    video_url   text,
    probability double precision,
    is_toxic    boolean,
    labels      text[] default '{}',
    model_used  text,
    threshold   double precision,
    latency_ms  double precision,
    source      text          -- "api_direct" | "video_fetch" | "user_comment"
);

-- 2. Indexes for the queries the API will run
create index if not exists predictions_created_at_idx
    on public.predictions (created_at desc);

create index if not exists predictions_video_id_idx
    on public.predictions (video_id);

-- 3. Row Level Security: allow anonymous insert + select
--    (we are using the publishable key from the frontend / backend with no auth)
alter table public.predictions enable row level security;

drop policy if exists "anon_insert" on public.predictions;
create policy "anon_insert"
    on public.predictions
    for insert
    to anon
    with check (true);

drop policy if exists "anon_select" on public.predictions;
create policy "anon_select"
    on public.predictions
    for select
    to anon
    using (true);

-- 4. Sanity check (run separately if you want)
-- select count(*) from public.predictions;