File size: 1,403 Bytes
a32af27
 
 
 
 
 
 
 
 
 
 
 
89a70e2
a32af27
 
 
 
 
 
89a70e2
 
 
 
 
 
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
-- Admin audit trail — every manual admin action (review decisions, source
-- toggles, poll runs), newest first. Mirrors DataWiz-Project's /admin/audit.
-- Automatic pipeline decisions (auto-publish, auto-discard) are NOT logged
-- here — they're already visible per-item in news_items.status, and logging
-- every one of them would make this table useless as a human-action trail.

create extension if not exists pgcrypto;

create table if not exists admin_audit_log (
  id         uuid primary key default gen_random_uuid(),
  at         timestamptz not null default now(),
  actor      text not null,   -- admin's Firebase UID
  kind       text not null check (kind in ('review', 'source', 'run', 'niche')),
  action     text not null,   -- e.g. 'published', 'discarded', 'enabled', 'disabled', 'started'
  target     text,            -- the item/source/poll id this action was on
  summary    text not null    -- short human-readable description, e.g. the item title
);

create index if not exists admin_audit_log_at_idx on admin_audit_log (at desc);

-- 2026-10-22: niche requests (marking a missing niche added/dismissed) are
-- audited too. For a table created before this date, run:
alter table admin_audit_log drop constraint if exists admin_audit_log_kind_check;
alter table admin_audit_log add constraint admin_audit_log_kind_check
  check (kind in ('review', 'source', 'run', 'niche'));