mail/back/db/structure
2023-03-16 16:14:25 +01:00

157 lines
4.5 KiB
Plaintext

create table addresses (
id int not null auto_increment,
name text,
localpart text not null,
domain text not null,
email text not null,
primary key (id),
unique key (email)
);
create table mailboxes (
-- Grant: select, insert, update
id serial primary key,
name text not null unique,
-- owner int references users(id), todo
-- The UID that will be assigned to the next delivered message.
-- Incremented after each successful delivery.
uidnext int not null default 1,
-- The next modsequence value for this mailbox.
nextmodseq bigint not null default 1,
-- The UID of the first message that should be marked \Recent.
-- Set to uidnext when each new IMAP session is created.
first_recent int not null default 1,
-- The IMAP mailbox UIDVALIDITY value, which, along with a message UID,
-- is forever guaranteed to uniquely refer to a single message.
uidvalidity int not null default 1,
-- When a mailbox is deleted, its entry is marked (not removed), so
-- that its UIDVALIDITY can be incremented if it is ever re-created.
deleted boolean not null default false
);
/**
* Store message
*/
create table messages (
-- Grant: select, insert
id int primary key auto_increment,
-- the time the message was added to the mailbox, as a unix time_t
idate timestamp not null,
-- the size of the message in RFC 822 format, in bytes
rfc822size int
);
-- todo make this work
-- foreign key (mailbox) references mailboxes(id),
-- foreign key (uid) references messages(id),
create table mailbox_messages (
-- Grant: select, insert, update
mailbox int not null,
-- the message's number in the mailbox
uid int not null,
message int not null,
modseq bigint not null,
seen boolean not null default false,
deleted boolean not null default false,
primary key (mailbox, uid)
);
-- tood should not be auto increment but nextval('bodypart_ids')
create table bodyparts (
-- Grant: select, insert
id int primary key auto_increment,
-- the size of either text or data, whichever is used
bytes int not null,
-- MD5 hash of either text or data
hash text not null,
text text,
data binary
);
create table part_numbers (
-- Grant: select, insert
message int references messages(id) on delete cascade,
part text not null,
bodypart int references bodyparts(id),
bytes int,
nbLines int,
primary key (message)
);
create table field_names (
-- Grant: select, insert
id serial primary key,
name text unique
);
-- add foreign key (message, part)
-- references part_numbers(message, part)
--on delete cascade at the end
-- references field_names(id) to field
create table header_fields (
-- Grant: select, insert
id serial primary key,
message int not null,
part text not null,
position int not null,
field int not null,
value text,
unique (message, part, position, field)
);
create table address_fields (
-- Grant: select, insert
message int not null,
part text not null,
position int not null,
field int not null,
number int,
address int not null-- references addresses(id),
-- foreign key (message, part)
-- references part_numbers(message, part)
-- on delete cascade
);
create table date_fields (
-- Grant: select, insert
message int not null references messages(id)
on delete cascade,
value timestamp --with time zone
);
/**
* APP tables
*/
create table app_accounts (
id int not null auto_increment,
user varchar(255) not null,
password binary(20),
xoauth varchar(116),
xoauth2 varchar(116),
host varchar(255) not null default 'localhost',
port int(5) not null default 143,
tls int(1) not null default 0,
primary key (id)
);
create table app_rooms (
id int not null auto_increment,
name text not null,
owner int not null,
isGroup BIT(1) not null default 0,
notSeen int not null default 0,
lastUpdate timestamp not null,
primary key (id)
);
create table app_room_messages (
message int [not null]
room int,
primary key()
)