Gmail files one message in INBOX and All Mail, each with its own UID; the reader kept an entry per folder. waiting_mail and mail_entry are now unique per account and message key (migration 0002 and schema.sql), a mail that already has its entry no longer waits again, and the test double keeps PgStore's own keys (issue 1548). A schema model test proves schema.sql equals the migrations in order.
80 lines
4.2 KiB
SQL
80 lines
4.2 KiB
SQL
-- The consolidated schema, through migration 0002: 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,
|
|
uidvalidity bigint not null default 0,
|
|
uid bigint not null default 0,
|
|
message_key text not null default '',
|
|
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(),
|
|
constraint mail_entry_one_per_message unique (account, message_key));
|
|
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: by its account, folder, UIDVALIDITY and UID, and by its account and message key
|
|
-- (issue 1849: its Message-ID, else its folder, UIDVALIDITY and UID), so one Gmail message heard in INBOX and
|
|
-- in All Mail waits once.
|
|
create table waiting_mail (
|
|
id bigserial primary key,
|
|
account text not null,
|
|
folder text not null,
|
|
message_id text not null default '',
|
|
message_key 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),
|
|
constraint waiting_mail_one_per_message unique (account, message_key));
|
|
|
|
-- 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));
|