Every day from 07:00 Chiang Mai time the app mails the journal's last entry number and its hash to the addresses set on the Notifications page (src/anchor.rs, migration 0012: settings, journal_anchors), when anything was added since the last anchor that went out. A day without news is noted without a mail; a failed send is tried again after an hour; a transaction-level advisory lock keeps two runs from both sending. "Send the anchor now" sends at once. Each mail says whether the chain checked whole (in capitals when it did not) and links to /journal/anchor, which compares a kept entry number and hash with the journal now: the same hash, another one, or no such entry. Changing the recipients is itself a journal entry. Every anchor mail is in the notifications log. Tests: the daily rule (before seven, once a day, an hour after a failure), recipients checked and journaled, one mail per recipient with the head hash, unchanged days, by hand, the check page's three answers, and a chain broken around the app said in the mail. 126 unit, 67 integration.
35 lines
1.4 KiB
SQL
35 lines
1.4 KiB
SQL
-- Lanna Desk, phase 11, step 2: the journal's anchor (docs/PLAN.md "Phase 11").
|
|
--
|
|
-- Once a day the app mails the journal's last entry number and hash to
|
|
-- addresses outside the server. A journal rebuilt later by someone with
|
|
-- database access no longer matches those mails: the copies kept by the
|
|
-- recipients are what this table cannot be, out of reach. The rows here
|
|
-- only say what was sent when.
|
|
|
|
-- The app's settings that the office changes on its pages: for now the
|
|
-- anchor's recipients ('anchor_to', addresses separated by commas).
|
|
CREATE TABLE settings (
|
|
key TEXT PRIMARY KEY,
|
|
value TEXT NOT NULL,
|
|
updated_by TEXT NOT NULL,
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE TABLE journal_anchors (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
-- the day in Chiang Mai the anchor is for
|
|
day DATE NOT NULL,
|
|
seq BIGINT NOT NULL CHECK (seq > 0),
|
|
hash TEXT NOT NULL CHECK (hash ~ '^[0-9a-f]{64}$'),
|
|
-- whether the chain checked whole when it was sent
|
|
whole BOOLEAN NOT NULL,
|
|
-- sent to all, failed for one or more, or no mail because nothing was
|
|
-- added since the last anchor
|
|
status TEXT NOT NULL CHECK (status IN ('sent', 'failed', 'unchanged')),
|
|
recipients TEXT NOT NULL DEFAULT '',
|
|
how TEXT NOT NULL CHECK (how IN ('daily', 'by hand')),
|
|
actor TEXT NOT NULL,
|
|
at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX journal_anchors_day ON journal_anchors (day DESC, id DESC);
|