Files
tazlin 5e0456b616 feat(moderation): filter prompt events by reason
- `GET /operations/moderation/prompts` takes a repeatable `reason`; an unknown value is `400 InvalidModerationReason`
- `(reason, id)` index on `prompt_moderation_events` in the model and `sql_statements/5.1.14.txt`, so a page of a rare reason does not walk the common ones
- `hold_source` on each listed event (`note`, `account_status` or null), computed in the page query from the same predicates `_under_moderation_action` applies, so the listing never disagrees with retention; nothing is stored and there is no release
- the migration test applies every migration that changes a moderation table, now 5.1.12 and 5.1.14
- version 5.1.14
2026-10-03 00:57:55 -04:00

15 lines
848 B
Plaintext

-- Run with psql in its default autocommit mode. Do not pass --single-transaction:
-- CREATE INDEX CONCURRENTLY cannot run inside a transaction block. Pass
-- -v ON_ERROR_STOP=1 so a failure stops the migration. A failed concurrent build
-- leaves an INVALID index; drop it and rerun after correcting the cause.
--
-- Moderators browse the evidence of one reason newest-first:
-- SELECT ... FROM prompt_moderation_events WHERE reason IN (...) ORDER BY id DESC LIMIT ?
-- Without an index the descending id scan walks every event of the common
-- reasons to fill a page of a rare one. The application filters by reason with
-- or without the index, so this can be applied before or after deploying 5.1.14.
SET lock_timeout = '3s';
CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_prompt_moderation_reason_id
ON prompt_moderation_events (reason, id);