Files
mesh-catalog/modules/mesh-mail-reader/cmd/mesh-mail-reader/schema.sql
T

73 lines
3.8 KiB
SQL

-- The consolidated schema, through migration 0001: what a fresh database is given at once (the mesh's rule: a
-- numbered migration for the running store, and this for a fresh install).
create table mail_group (
id bigserial primary key,
label text not null unique default '',
created timestamptz not null default now());
create table mail_entry (
id bigserial primary key,
account text not null,
message_id text not null default '',
folder text not null,
date timestamptz not null,
sender_name text not null default '',
sender_address text not null default '',
subject text not null default '',
mail_group bigint references mail_group (id),
summary text not null default '' check (char_length(summary) <= 160),
mark text check (mark is null or mark in ('matters', 'scam warning', 'neither')),
why text not null default '',
due_date date,
told boolean not null default false,
judged timestamptz not null default now());
create index mail_entry_account_date on mail_entry (account, date desc);
create index mail_entry_judged on mail_entry (judged);
-- A reading lesson (novox/hq ADR 0459 §8, §9, issue 1428): the corrected mail's own headers (never a body),
-- the change made, when, and whether it was undone. sender_address and mail_group are its own matching keys
-- for the next batch's question (1427): a lesson matches a mail of the same sender, or already known to be
-- of the same mail group.
create table reading_lesson (
id bigserial primary key,
account text not null default '',
folder text not null default '',
sender_name text not null default '',
sender_address text not null default '',
subject text not null default '',
mail_group bigint references mail_group (id),
change text not null default '',
made timestamptz not null default now(),
undone boolean not null default false);
create index reading_lesson_sender on reading_lesson (sender_address);
-- Heard but not yet read (novox/hq ADR 0459 §3, §12, issue 1518): headers only, kept until reading takes them,
-- in the order they were heard (id, a bigserial, orders arrival regardless of the mail's own date). A mail
-- heard twice is kept once: the unique key below is its account, folder, UIDVALIDITY and UID, the same
-- identity mesh-mail's own event carries for a message whose message id may be empty.
create table waiting_mail (
id bigserial primary key,
account text not null,
folder text not null,
message_id text not null default '',
uidvalidity bigint not null default 0,
uid bigint not null default 0,
date timestamptz not null,
sender jsonb not null default '[]',
subject text not null default '',
flags text[] not null default '{}',
size bigint not null default 0,
heard timestamptz not null default now(),
unique (account, folder, uidvalidity, uid));
-- The reader's own health (novox/hq ADR 0459 §12, issue 1519), kept across a restart: one row, singleton by
-- its fixed id. cause is "" while healthy, else one of refused, timed out, out of shape; since is the first
-- failure's own time, not the latest one.
create table reader_health (
id smallint primary key default 1,
healthy boolean not null default true,
cause text not null default '',
why text not null default '',
since timestamptz,
constraint reader_health_singleton check (id = 1));