Files
ai-exchange/migrations/042_create_alert_feedback.sql
2026-05-11 23:37:47 +08:00

33 lines
1.2 KiB
SQL

create table if not exists alert_feedback (
id bigserial primary key,
subject_type text not null,
subject_id bigint not null,
alert_id bigint references decision_alerts(id) on delete cascade,
visual_review_id bigint references visual_reviews(id) on delete cascade,
label text not null,
note text not null default '',
created_by text not null default 'local_operator',
created_ts timestamptz not null default now(),
payload jsonb not null default '{}'::jsonb,
constraint chk_alert_feedback_subject check (
(
subject_type = 'alert'
and alert_id is not null
and visual_review_id is null
and subject_id = alert_id
)
or (
subject_type = 'visual_review'
and visual_review_id is not null
and alert_id is null
and subject_id = visual_review_id
)
)
);
create index if not exists idx_alert_feedback_alert_created_desc
on alert_feedback (alert_id, created_ts desc, id desc);
create index if not exists idx_alert_feedback_visual_review_created_desc
on alert_feedback (visual_review_id, created_ts desc, id desc);