Spaces:
Runtime error

File size: 2,224 Bytes
00033cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5f2a085
 
 
00033cb
 
 
 
5f2a085
 
 
 
00033cb
 
 
 
 
 
5f2a085
00033cb
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
create table if not exists incidents (
  id varchar(36) primary key,
  user_id varchar(255) not null,
  target_user_id varchar(255) not null,
  timestamp timestamptz not null,
  text text not null,
  status varchar(32) not null default 'queued',
  severity_level varchar(32) not null,
  severity_score double precision not null,
  aggression_score double precision not null,
  intent_score double precision not null,
  repetition_score double precision not null,
  toxic_score double precision not null,
  insult_score double precision not null,
  identity_attack_score double precision not null,
  model_name varchar(128) not null,
  model_version varchar(128) not null,
  raw_model_output jsonb not null,
  review_note text,
  reviewed_by_user_id varchar(255),
  reviewed_by_email varchar(255),
  moderated_at timestamptz,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

alter table incidents add column if not exists reviewed_by_user_id varchar(255);
alter table incidents add column if not exists reviewed_by_email varchar(255);
alter table incidents add column if not exists moderated_at timestamptz;

create index if not exists ix_incidents_user_id on incidents (user_id);
create index if not exists ix_incidents_target_user_id on incidents (target_user_id);
create index if not exists ix_incidents_timestamp on incidents (timestamp);
create index if not exists ix_incidents_status on incidents (status);
create index if not exists ix_incidents_severity_level on incidents (severity_level);
create index if not exists ix_incidents_severity_score on incidents (severity_score);
create index if not exists ix_incidents_moderated_at on incidents (moderated_at);
create index if not exists ix_incidents_user_target_timestamp
  on incidents (user_id, target_user_id, timestamp);

create table if not exists alerts (
  id varchar(36) primary key,
  incident_id varchar(36) not null,
  severity_score double precision not null,
  recipient varchar(255) not null,
  payload jsonb not null,
  delivery_state varchar(32) not null default 'stubbed',
  created_at timestamptz not null default now()
);

create index if not exists ix_alerts_incident_id on alerts (incident_id);