Skip to main content

max / makenotwork

1.2 KB · 23 lines History Blame Raw
1 -- Per-community chat retention, the second half of what a room needs to
2 -- resolve (wiki livechat-design, "Retention").
3 --
4 -- `livechat::Room` carries a `Retention`, and 037 gave a community only a
5 -- `chat_policy`. These two columns are where that `Retention` comes from, and
6 -- they are what the owner settings screen writes.
7 --
8 -- Both bounds are NOT NULL with a default and both are CHECK-bounded against
9 -- the crate ceilings (`livechat::MAX_AGE_CEILING` = 720 hours,
10 -- `MAX_MESSAGES_CEILING` = 20000). There is deliberately no "keep forever":
11 -- `livechat::Retention::new` has no Option and no sentinel, and a NULL here
12 -- would be exactly the sentinel that type exists to refuse. The CHECKs restate
13 -- the ceilings in the schema so a bad UPDATE fails at the database rather than
14 -- at whichever call site forgot to validate.
15 --
16 -- Defaults match `Retention::forum_default()`: 7 days, 5000 messages.
17
18 ALTER TABLE communities
19 ADD COLUMN chat_retention_hours INTEGER NOT NULL DEFAULT 168
20 CHECK (chat_retention_hours > 0 AND chat_retention_hours <= 720),
21 ADD COLUMN chat_max_messages INTEGER NOT NULL DEFAULT 5000
22 CHECK (chat_max_messages > 0 AND chat_max_messages <= 20000);
23