0023_abuse_reports.sql 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. -- 0023_abuse_reports — dedicated table; replaces the audit-log overload
  2. -- that services/abuse.ts used pre-cleanup. audit_logs still receives
  3. -- one row per state transition for the security audit perspective,
  4. -- but the dashboard's abuse-triage list now reads this table directly.
  5. -- Historical abuse rows in audit_logs are preserved for forensics;
  6. -- a one-off backfill into abuse_reports can be done later if needed.
  7. CREATE TABLE IF NOT EXISTS "abuse_reports" (
  8. "id" text PRIMARY KEY NOT NULL,
  9. "target_url" text NOT NULL,
  10. "reason" text NOT NULL,
  11. "severity" text NOT NULL,
  12. "reporter_contact" text,
  13. "source_ip_hash" text,
  14. "source_user_agent" text,
  15. "status" text DEFAULT 'open' NOT NULL,
  16. "resolution" text,
  17. "project_id" text,
  18. "triaged_at" timestamp with time zone,
  19. "triaged_by" text,
  20. "triage_notes" text,
  21. "resolved_at" timestamp with time zone,
  22. "resolved_by" text,
  23. "resolve_notes" text,
  24. "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  25. "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
  26. CONSTRAINT "abuse_reports_project_id_fk"
  27. FOREIGN KEY ("project_id") REFERENCES "projects"("id") ON DELETE SET NULL,
  28. CONSTRAINT "abuse_reports_triaged_by_fk"
  29. FOREIGN KEY ("triaged_by") REFERENCES "users"("id") ON DELETE SET NULL,
  30. CONSTRAINT "abuse_reports_resolved_by_fk"
  31. FOREIGN KEY ("resolved_by") REFERENCES "users"("id") ON DELETE SET NULL
  32. );
  33. CREATE INDEX IF NOT EXISTS "abuse_reports_status_idx"
  34. ON "abuse_reports" USING btree ("status", "created_at");
  35. CREATE INDEX IF NOT EXISTS "abuse_reports_severity_idx"
  36. ON "abuse_reports" USING btree ("severity", "created_at");
  37. CREATE INDEX IF NOT EXISTS "abuse_reports_project_idx"
  38. ON "abuse_reports" USING btree ("project_id")
  39. WHERE "project_id" IS NOT NULL;