ADR 0106: The inbox's hosted schema adds columns, a comment audit table and conditional moderation functions, opt in
- Status: Accepted
- Date: 2026-10-26
- Decision issue: #225
- Parent story: #203
- Parent epic: #16
- Builds on: ADR 0080, ADR 0083, ADR 0102, ADR 0105
- Amends: ADR 0102 (comments keep their
statuscolumn and gain the full state beside it now, not with #226), ADR 0083 (the audit fields it left for #225) - Coordinates with: #226
Context#
The one state machine needs, for every item, its version, its text's revision, the revision an
approval covers, the revision a clarification asked about, and the reader's consent to be asked.
Comments have none of these, and their status column holds only pending, approved and
rejected, which public reads use. B5's feedback table has a version but not the revisions, and
its audit table left the item's kind, revision and the actor's role to #225. Hosted storage is a
one-way door: every change must be additive, opt in and reversible without making anything
private public.
Decision#
- Additive only. Nothing is renamed, dropped, retyped or rewritten. Every new column has a default or is nullable, so every row already stored reads as before.
- Comments (
supabase/moderation.sql, new and optional):openblog_commentsgainsversion integer not null default 1,moderation_state text(nullable: a comment no inbox decision touched has the state itsstatussays) andmoderation_reason text(a reason code, never free text).statuskeeps its three values and stays what public reads use. Every decision writes the full state tomoderation_stateand its ADR 0102 legacy value tostatusin the same statement: removed is stored asrejected, so nothing that is not public is ever stored as approved.- The
openblog_comment_eventsaudit table (comment, action, states, reason, actor, actor role, time, version; never text or a name), private like ADR 0080's tables. Its rows are only inserted here; engagement protection (ADR 0108) later lets the retention run delete events older than the site's audit period, and a trigger refuses to delete any recorded in the last day. openblog_moderate_comment(...)applies one decision only while the comment still has the state and version both Admin and the function saw, raises the version and inserts the event, in one statement, writing only a comment's four states.
- Passage feedback (
supabase/feedback.sql, run again to add them):openblog_feedbackgainsitem_revision integer not null default 1,approved_revision,clarification_askedandclarification_consent boolean not null default false. (Itsrevisioncolumn is the passage revision a reader saw, ADR 0078, so the text's revision isitem_revision.)openblog_feedback_eventsgains the nullablekind,item_revisionandactor_roleADR 0083 left for this task; older events keep none.openblog_moderate_feedback_item(...)applies one decision conditionally on state and version, sets the revisions as the state machine does, and inserts the full event. It also refuses in SQL what must never happen whatever its caller says: approving the text a clarification asked about, reopening it to anything but clarification, and asking a reader who did not consent. A submitter's clarification (p_body) replaces the text as the next revision; no route offers it until reader receipts exist (#226).
statusdecides when the two columns disagree. A comment's state is itsmoderation_stateonly whilestatusstill holds that state's legacy value; otherwise it is itsstatus. A decision taken while the variable was unset writesstatusalone, so after the variable is set again a comment approved, reopened or rejected in between reads as what itsstatussays, never as the stale full state (a comment removed and then reopened without the schema is pending, not removed). The function's reads, the inbox's state filters andopenblog_moderate_comment's condition all apply this one rule (commentStateandcommentStateFilterinnetlify/lib/participation-moderation.mjs).- Opt in, with the older schema still served.
OPENBLOG_MODERATION_ENABLED=truetells the function the schema is there. Without it, the inbox still lists comments and feedback and offers only what the older schema can store: comments are approved, rejected, removed (stored as rejected) and reopened with a write conditional on theirstatus, and feedback uses B5'sopenblog_moderate_feedback; asking to clarify and reopening feedback answer that the schema is needed. With it, the older bare commentPATCH /admin/commentsis refused, because it would skip the version, the state and the audit event; B5'sPATCH /admin/feedbackgoes through the new function. B5's/admin/feedbackanswers keep v0.33.0's shape exactly, with or without the variable, because an Admin of that version refuses any field it does not know; only the inbox's/admin/moderationitems carry the revisions and the reader's consent. - Rollback drops exactly what was added.
supabase/moderation-rollback.sqldrops the comment function,openblog_comment_events, the three comment columns, the feedback function and the feedback columns this task added, leaving every comment and feedback item and its state; a removed comment'sstatusis alreadyrejected.supabase/feedback-rollback.sqldrops both feedback functions with its tables. Unsetting the variable first returns the function to the older schema.
Considered options#
- Widen
openblog_comments.status. Rejected: it would change what public reads see for any older function still deployed, and is not additive. - Store comment events in
openblog_feedback_events. Rejected: itsfeedback_idis a required reference to the feedback table, and relaxing it is not additive. - Trust the caller's revisions in SQL. Rejected: the statement computes them from the row it updates, and refuses the clarification rule's violations itself.
Consequences#
- A site that runs nothing new keeps comments and feedback working, with the older schema's decisions; running the files and setting the variable enables every inbox decision.
- #226 adds retention, abuse reports and reader receipts on these columns without another migration for the facts the state machine needs.