-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.sql
87 lines (77 loc) · 2.43 KB
/
table.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
CREATE TABLE messages (
id SERIAL NOT NULL PRIMARY KEY,
parentid int REFERENCES messages,
threadid int NOT NULL,
_from text NOT NULL,
_to text NOT NULL,
cc text NOT NULL,
subject text NOT NULL,
date timestamptz NOT NULL,
loaddate timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
has_attachment boolean NOT NULL,
hiddenstatus int NULL,
messageid text NOT NULL,
bodytxt text NOT NULL,
rawtxt bytea NOT NULL
);
CREATE INDEX idx_messages_threadid ON messages(threadid);
CREATE UNIQUE INDEX idx_messages_msgid ON messages(messageid);
CREATE INDEX idx_messages_date ON messages(date);
CREATE INDEX idx_messages_parentid ON messages(parentid);
CREATE TABLE message_hide_reasons (
message int NOT NULL PRIMARY KEY REFERENCES messages,
dt timestamptz,
reason text,
by text
);
CREATE SEQUENCE threadid_seq;
CREATE TABLE unresolved_messages(
message int NOT NULL REFERENCES messages,
priority int NOT NULL,
msgid text NOT NULL,
CONSTRAINT unresolved_messages_pkey PRIMARY KEY (message, priority)
);
CREATE UNIQUE INDEX idx_unresolved_msgid_message ON unresolved_messages(msgid, message);
CREATE TABLE listgroups(
groupid int NOT NULL PRIMARY KEY,
groupname text NOT NULL UNIQUE,
sortkey int NOT NULL
);
CREATE TABLE lists(
listid int NOT NULL PRIMARY KEY,
listname text NOT NULL UNIQUE,
shortdesc text NOT NULL,
description text NOT NULL,
active boolean NOT NULL,
subscriber_access boolean NOT NULL,
groupid int NOT NULL REFERENCES listgroups(groupid)
);
CREATE TABLE list_months(
listid int NOT NULL REFERENCES lists(listid),
year int NOT NULL,
month int NOT NULL,
CONSTRAINT list_months_pk PRIMARY KEY (listid, year, month)
);
CREATE TABLE list_threads(
threadid int NOT NULL, /* comes from threadid_seq */
listid int NOT NULL REFERENCES lists(listid),
CONSTRAINT pg_list_threads PRIMARY KEY (threadid, listid)
);
CREATE INDEX list_threads_listid_idx ON list_threads(listid);
CREATE TABLE attachments(
id serial not null primary key,
message int not null references messages(id),
filename text not null,
contenttype text not null,
attachment bytea not null
);
CREATE INDEX idx_attachments_msg ON attachments(message);
CREATE TABLE loaderrors(
id SERIAL NOT NULL PRIMARY KEY,
listid int NOT NULL,
dat timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
msgid text NOT NULL,
srctype text NOT NULL,
src text NOT NULL,
err text NOT NULL
);