-- 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);