-- 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 folder ( account text not null, name text not null, uidvalidity bigint not null, messages integer not null default 0, synced timestamptz not null default now(), primary key (account, name)); create table message ( account text not null, folder text not null, uid bigint not null, uidvalidity bigint not null, message_id text not null default '', in_reply_to text not null default '', date timestamptz not null, sender jsonb not null default '[]', recipients jsonb not null default '[]', copied jsonb not null default '[]', people text not null default '', subject text not null default '', size bigint not null default 0, flags text[] not null default '{}', attachments jsonb not null default '[]', body text not null default '', search tsvector generated always as ( to_tsvector('simple'::regconfig, subject || ' ' || people || ' ' || body)) stored, primary key (account, folder, uid)); create index message_search on message using gin (search); create index message_date on message (account, date desc); create table account_state ( account text primary key, state text not null, why text not null default '', heard timestamptz, synced timestamptz, said timestamptz not null default now()); create table outbox ( id bigserial primary key, key text not null, body jsonb not null, made timestamptz not null default now());