]> git.donarmstrong.com Git - debbugs.git/blob - sql/debbugs_schema.sql
the maintainer address should be a correspondent
[debbugs.git] / sql / debbugs_schema.sql
1
2 DROP TABLE bug_status_cache CASCADE;
3 DROP VIEW  bug_package CASCADE;
4 DROP VIEW binary_versions CASCADE;
5 DROP TABLE bug_tag CASCADE;
6 DROP TABLE tag CASCADE;
7 DROP TABLE severity CASCADE;
8 DROP TABLE bug CASCADE;
9 DROP TABLE src_pkg CASCADE;
10 DROP TABLE bug_ver CASCADE;
11 DROP TABLE src_ver CASCADE;
12 DROP TABLE arch CASCADE;
13 DROP TABLE bin_ver CASCADE;
14 DROP TABLE bin_pkg CASCADE;
15 DROP TABLE bug_blocks CASCADE;
16 DROP TABLE bug_merged CASCADE;
17 DROP TABLE bug_srcpackage CASCADE;
18 DROP TABLE bug_binpackage CASCADE;
19 DROP TABLE suite CASCADE;
20 DROP TABLE bin_associations CASCADE;
21 DROP TABLE src_associations CASCADE;
22 DROP TABLE maintainer CASCADE;
23 DROP TABLE bug_message CASCADE;
24 DROP TABLE message_correspondent CASCADE;
25 DROP TABLE correspondent_full_name CASCADE;
26 DROP TABLE correspondent CASCADE;
27 DROP TABLE message_refs CASCADE;
28 DROP TABLE message CASCADE;
29 DROP TYPE message_correspondent_type CASCADE;
30 DROP TABLE table_comments CASCADE;
31 DROP TABLE column_comments CASCADE;
32 DROP TYPE bug_status_type CASCADE;
33
34 -- the following two tables are used to provide documentation about
35 -- the tables and columns for DBIx::Class::Schema::Loader
36 CREATE TABLE table_comments (
37        table_name TEXT UNIQUE NOT NULL,
38        comment_text TEXT NOT NULL
39 );
40 CREATE TABLE column_comments (
41        table_name TEXT  NOT NULL,
42        column_name TEXT  NOT NULL,
43        comment_text TEXT NOT NULL
44 );
45 CREATE UNIQUE INDEX ON column_comments(table_name,column_name);
46
47
48 CREATE TABLE correspondent (
49        id SERIAL PRIMARY KEY,
50        addr TEXT NOT NULL UNIQUE
51 );
52 INSERT INTO table_comments VALUES ('correspondent','Individual who has corresponded with the BTS');
53 INSERT INTO column_comments VALUES ('correspondent','id','Correspondent ID');
54 INSERT INTO column_comments VALUES ('correspondent','addr','Correspondent address');
55
56 CREATE TABLE maintainer (
57        id SERIAL PRIMARY KEY,
58        name TEXT NOT NULL UNIQUE,
59        correspondent INT NOT NULL REFERENCES correspondent(id),
60        created TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
61        modified TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL
62 );
63 INSERT INTO table_comments  VALUES ('maintainer','Package maintainer names');
64 INSERT INTO column_comments VALUES ('maintainer','id','Package maintainer id');
65 INSERT INTO column_comments VALUES ('maintainer','name','Name of package maintainer');
66 INSERT INTO column_comments VALUES ('maintainer','correspondent','Correspondent ID');
67 INSERT INTO column_comments VALUES ('maintainer','created','Time maintainer record created');
68 INSERT INTO column_comments VALUES ('maintainer','modified','Time maintainer record modified');
69
70
71 CREATE TABLE severity (
72        id SERIAL PRIMARY KEY,
73        severity TEXT NOT NULL UNIQUE,
74        ordering INT NOT NULL DEFAULT 5,
75        strong BOOLEAN DEFAULT FALSE,
76        obsolete BOOLEAN DEFAULT FALSE
77 );
78 INSERT INTO table_comments VALUES ('severity','Bug severity');
79 INSERT INTO column_comments VALUES ('severity','id','Severity id');
80 INSERT INTO column_comments VALUES ('severity','severity','Severity name');
81 INSERT INTO column_comments VALUES ('severity','ordering','Severity ordering (more severe severities have higher numbers)');
82 INSERT INTO column_comments VALUES ('severity','strong','True if severity is a strong severity');
83 INSERT INTO column_comments VALUES ('severity','obsolete','Whether a severity level is obsolete (should not be set on new bugs)');
84
85 -- bugs table
86 CREATE TABLE bug (
87        id INTEGER NOT NULL PRIMARY KEY,
88        creation TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
89        log_modified TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
90        last_modified TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
91        archived BOOLEAN NOT NULL DEFAULT FALSE,
92        unarchived TIMESTAMP WITH TIME ZONE,
93        forwarded TEXT NOT NULL DEFAULT '',
94        summary TEXT NOT NULL DEFAULT '',
95        outlook TEXT NOT NULL DEFAULT '',
96        subject TEXT NOT NULL,
97        severity INT NOT NULL REFERENCES severity(id),
98        done INT REFERENCES correspondent(id),
99        done_full TEXT NOT NULL DEFAULT '',
100        owner INT REFERENCES correspondent(id),
101        owner_full TEXT NOT NULL DEFAULT '',
102        -- submitter would ideally be NOT NULL, but there are some ancient bugs which do not have submitters
103        submitter INT REFERENCES correspondent(id),
104        submitter_full TEXT NOT NULL DEFAULT '',
105        unknown_packages TEXT NOT NULL DEfAULT ''
106 );
107 INSERT INTO table_comments VALUES ('bug','Bugs');
108 INSERT INTO column_comments VALUES ('bug','id','Bug number');
109 INSERT INTO column_comments VALUES ('bug','creation','Time bug created');
110 INSERT INTO column_comments VALUES ('bug','log_modified','Time bug log was last modified');
111 INSERT INTO column_comments VALUES ('bug','last_modified','Time bug status was last modified');
112 INSERT INTO column_comments VALUES ('bug','archived','True if bug has been archived');
113 INSERT INTO column_comments VALUES ('bug','unarchived','Time bug was last unarchived; null if bug has never been unarchived');
114 INSERT INTO column_comments VALUES ('bug','forwarded','Where bug has been forwarded to; empty if it has not been forwarded');
115 INSERT INTO column_comments VALUES ('bug','summary','Summary of the bug; empty if it has no summary');
116 INSERT INTO column_comments VALUES ('bug','outlook','Outlook of the bug; empty if it has no outlook');
117 INSERT INTO column_comments VALUES ('bug','subject','Subject of the bug');
118 INSERT INTO column_comments VALUES ('bug','done','Individual who did the -done; empty if it has never been -done');
119 INSERT INTO column_comments VALUES ('bug','owner','Individual who owns this bug; empty if no one owns it');
120 INSERT INTO column_comments VALUES ('bug','submitter','Individual who submitted this bug; empty if there is no submitter');
121 INSERT INTO column_comments VALUES ('bug','unknown_packages','Package name if the package is not known');
122
123 CREATE INDEX ON bug(creation);
124 CREATE INDEX ON bug(log_modified);
125 CREATE INDEX ON bug(done);
126 CREATE INDEX ON bug(owner);
127 CREATE INDEX ON bug(submitter);
128 CREATE INDEX ON bug(forwarded);
129
130
131
132 CREATE TABLE bug_blocks (
133        id SERIAL PRIMARY KEY,
134        bug INT NOT NULL REFERENCES bug,
135        blocks INT NOT NULL REFERENCES bug,
136        CONSTRAINT bug_doesnt_block_itself CHECK (bug <> blocks)
137 );
138 CREATE UNIQUE INDEX bug_blocks_bug_id_blocks_idx ON bug_blocks(bug,blocks);
139 CREATE INDEX bug_blocks_bug_id_idx ON bug_blocks(bug);
140 CREATE INDEX bug_blocks_blocks_idx ON bug_blocks(blocks);
141 INSERT INTO table_comments VALUES ('bug_blocks','Bugs which block other bugs');
142 INSERT INTO column_comments VALUES ('bug_blocks','bug','Bug number');
143 INSERT INTO column_comments VALUES ('bug_blocks','blocks','Bug number which is blocked by bug');
144
145
146 CREATE TABLE bug_merged (
147        id SERIAL PRIMARY KEY,
148        bug INT NOT NULL REFERENCES bug,
149        merged INT NOT NULL REFERENCES bug,
150        CONSTRAINT bug_doesnt_merged_itself CHECK (bug <> merged)
151 );
152 CREATE UNIQUE INDEX bug_merged_bug_id_merged_idx ON bug_merged(bug,merged);
153 CREATE INDEX bug_merged_bug_id_idx ON bug_merged(bug);
154 CREATE INDEX bug_merged_merged_idx ON bug_merged(merged);
155 INSERT INTO table_comments  VALUES ('bug_merged','Bugs which are merged with other bugs');
156 INSERT INTO column_comments VALUES ('bug_merged','bug','Bug number');
157 INSERT INTO column_comments VALUES ('bug_merged','merged','Bug number which is merged with bug');
158
159 CREATE TABLE src_pkg (
160        id SERIAL PRIMARY KEY,
161        pkg TEXT NOT NULL UNIQUE,
162        pseduopkg BOOLEAN DEFAULT FALSE,
163        alias_of INT REFERENCES src_pkg ON UPDATE CASCADE ON DELETE CASCADE
164        CONSTRAINT src_pkg_doesnt_alias_itself CHECK (id <> alias_of)
165 );
166 INSERT INTO table_comments VALUES ('src_pkg','Source packages');
167 INSERT INTO column_comments VALUES ('src_pkg','id','Source package id');
168 INSERT INTO column_comments VALUES ('src_pkg','pkg','Source package name');
169 INSERT INTO column_comments VALUES ('src_pkg','pseudopkg','True if this is a pseudo package');
170 INSERT INTO column_comments VALUES ('src_pkg','alias_of','Source package id which this source package is an alias of');
171
172
173
174 CREATE TABLE src_ver (
175        id SERIAL PRIMARY KEY,
176        src_pkg INT NOT NULL REFERENCES src_pkg
177             ON UPDATE CASCADE ON DELETE CASCADE,
178        ver public.debversion NOT NULL,
179        maintainer_id INT REFERENCES maintainer
180             ON UPDATE CASCADE ON DELETE SET NULL,
181        upload_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
182        based_on INT REFERENCES src_ver
183             ON UPDATE CASCADE ON DELETE CASCADE
184 );
185 CREATE UNIQUE INDEX src_ver_src_pkg_id_ver ON src_ver(src_pkg,ver);
186 INSERT INTO table_comments VALUES ('src_ver','Source Package versions');
187 INSERT INTO column_comments VALUES ('src_ver','id','Source package version id');
188 INSERT INTO column_comments VALUES ('src_ver','src_pkg','Source package id (matches src_pkg table)');
189 INSERT INTO column_comments VALUES ('src_ver','ver','Version of the source package');
190 INSERT INTO column_comments VALUES ('src_ver','maintainer_id','Maintainer id (matches maintainer table)');
191 INSERT INTO column_comments VALUES ('src_ver','upload_date','Date this version of the source package was uploaded');
192 INSERT INTO column_comments VALUES ('src_ver','based_on','Source package version this version is based on');
193
194
195
196 CREATE TABLE bug_ver (
197        bug INT NOT NULL REFERENCES bug
198          ON UPDATE CASCADE ON DELETE RESTRICT,
199        ver_string TEXT,
200        src_pkg INT REFERENCES src_pkg
201             ON UPDATE CASCADE ON DELETE SET NULL,
202        src_ver_id INT REFERENCES src_ver
203             ON UPDATE CASCADE ON DELETE SET NULL,
204        found BOOLEAN NOT NULL DEFAULT TRUE,
205        creation TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
206        last_modified TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
207 );
208 CREATE INDEX bug_ver_src_pkg_id_idx ON bug_ver(src_pkg);
209 CREATE INDEX bug_ver_src_pkg_id_src_ver_id_idx ON bug_ver(src_pkg,src_ver_id);
210 CREATE INDEX bug_ver_src_ver_id_idx ON bug_ver(src_ver_id);
211 CREATE UNIQUE INDEX ON bug_ver(bug,ver_string,found);
212 INSERT INTO table_comments VALUES ('bug_ver','Bug versions');
213 INSERT INTO column_comments VALUES ('bug_ver','bug','Bug number');
214 INSERT INTO column_comments VALUES ('bug_ver','ver_string','Version string');
215 INSERT INTO column_comments VALUES ('bug_ver','src_pkg','Source package id (matches src_pkg table)');
216 INSERT INTO column_comments VALUES ('bug_ver','src_ver_id','Source package version id (matches src_ver table)');
217 INSERT INTO column_comments VALUES ('bug_ver','found','True if this is a found version; false if this is a fixed version');
218 INSERT INTO column_comments VALUES ('bug_ver','creation','Time that this entry was created');
219 INSERT INTO column_comments VALUES ('bug_ver','last_modified','Time that this entry was modified');
220
221
222 CREATE TABLE arch (
223        id SERIAL PRIMARY KEY,
224        arch TEXT NOT NULL UNIQUE
225 );
226 INSERT INTO table_comments VALUES ('arch','Architectures');
227 INSERT INTO column_comments VALUES ('arch','id','Architecture id');
228 INSERT INTO column_comments VALUES ('arch','arch','Architecture name');
229
230
231 CREATE TABLE bin_pkg (
232        id SERIAL PRIMARY KEY,
233        pkg TEXT NOT NULL UNIQUE
234 );
235 INSERT INTO table_comments VALUES ('bin_pkg','Binary packages');
236 INSERT INTO column_comments VALUES ('bin_pkg','id','Binary package id');
237 INSERT INTO column_comments VALUES ('bin_pkg','pkg','Binary package name');
238
239
240 CREATE TABLE bin_ver(
241        id SERIAL PRIMARY KEY,
242        bin_pkg INT NOT NULL REFERENCES bin_pkg
243             ON UPDATE CASCADE ON DELETE CASCADE,
244        src_ver_id INT NOT NULL REFERENCES src_ver
245             ON UPDATE CASCADE ON DELETE CASCADE,
246        arch_id INT NOT NULL REFERENCES arch
247             ON UPDATE CASCADE ON DELETE CASCADE,
248        ver public.debversion NOT NULL
249 );
250 CREATE INDEX bin_ver_ver_idx ON bin_ver(ver);
251 CREATE UNIQUE INDEX bin_ver_bin_pkg_id_arch_idx ON bin_ver(bin_pkg,arch_id,ver);
252 CREATE UNIQUE INDEX bin_ver_src_ver_id_arch_idx ON bin_ver(src_ver_id,arch_id);
253 CREATE INDEX bin_ver_bin_pkg_id_idx ON bin_ver(bin_pkg);
254 CREATE INDEX bin_ver_src_ver_id_idx ON bin_ver(src_ver_id);
255 INSERT INTO table_comments VALUES ('bin_ver','Binary versions');
256 INSERT INTO column_comments VALUES ('bin_ver','id','Binary version id');
257 INSERT INTO column_comments VALUES ('bin_ver','bin_pkg','Binary package id (matches bin_pkg)');
258 INSERT INTO column_comments VALUES ('bin_ver','src_ver_id','Source version (matchines src_ver)');
259 INSERT INTO column_comments VALUES ('bin_ver','arch_id','Architecture id (matches arch)');
260 INSERT INTO column_comments VALUES ('bin_ver','ver','Binary version');
261
262 CREATE TABLE tag (
263        id SERIAL PRIMARY KEY,
264        tag TEXT NOT NULL UNIQUE,
265        obsolete BOOLEAN DEFAULT FALSE
266 );
267 INSERT INTO table_comments VALUES ('tag','Bug tags');
268 INSERT INTO column_comments VALUES ('tag','id','Tag id');
269 INSERT INTO column_comments VALUES ('tag','tag','Tag name');
270 INSERT INTO column_comments VALUES ('tag','obsolete','Whether a tag is obsolete (should not be set on new bugs)');
271
272 CREATE TABLE bug_tag (
273        id SERIAL PRIMARY KEY,
274        bug INT NOT NULL REFERENCES bug,
275        tag INT NOT NULL REFERENCES tag
276 );
277 INSERT INTO table_comments VALUES ('bug_tag','Bug <-> tag mapping');
278 INSERT INTO column_comments VALUES ('bug_tag','bug','Bug id (matches bug)');
279 INSERT INTO column_comments VALUES ('bug_tag','tag','Tag id (matches tag)');
280
281 CREATE UNIQUE INDEX bug_tag_bug_tag_id ON bug_tag (bug,tag);
282 CREATE INDEX bug_tag_tag_id ON bug_tag (tag);
283 CREATE INDEX bug_tag_bug_id ON bug_tag (bug);
284
285
286
287 CREATE TABLE bug_binpackage (
288        id SERIAL PRIMARY KEY,
289        bug INT NOT NULL REFERENCES bug,
290        bin_pkg INT NOT NULL REFERENCES bin_pkg
291 );
292 CREATE UNIQUE INDEX bug_binpackage_id_pkg_id ON bug_binpackage(bug,bin_pkg);
293 INSERT INTO table_comments VALUES ('bug_binpackage','Bug <-> binary package mapping');
294 INSERT INTO column_comments VALUES ('bug_binpackage','bug','Bug id (matches bug)');
295 INSERT INTO column_comments VALUES ('bug_binpackage','bin_pkg','Binary package id (matches bin_pkg)');
296
297 CREATE TABLE bug_srcpackage (
298        id SERIAL PRIMARY KEY,
299        bug INT NOT NULL REFERENCES bug,
300        src_pkg INT NOT NULL REFERENCES src_pkg ON UPDATE CASCADE ON DELETE CASCADE
301 );
302 CREATE UNIQUE INDEX bug_srcpackage_id_pkg_id ON bug_srcpackage(bug,src_pkg);
303 INSERT INTO table_comments VALUES ('bug_srcpackage','Bug <-> source package mapping');
304 INSERT INTO column_comments VALUES ('bug_srcpackage','bug','Bug id (matches bug)');
305 INSERT INTO column_comments VALUES ('bug_srcpackage','src_pkg','Source package id (matches src_pkg)');
306
307 CREATE VIEW bug_package (bug,pkg_id,pkg_type,package) AS
308        SELECT b.bug,b.bin_pkg,'binary',bp.pkg FROM bug_binpackage b JOIN bin_pkg bp ON bp.id=b.bin_pkg UNION
309               SELECT s.bug,s.src_pkg,'source',sp.pkg FROM bug_srcpackage s JOIN src_pkg sp ON sp.id=s.src_pkg;
310
311 CREATE VIEW binary_versions (src_pkg, src_ver, bin_pkg, arch, bin_ver) AS
312        SELECT sp.pkg AS src_pkg, sv.ver AS src_ver, bp.pkg AS bin_pkg, a.arch AS arch, b.ver AS bin_ver,
313        svb.ver AS src_ver_based_on, spb.pkg AS src_pkg_based_on
314        FROM bin_ver b JOIN arch a ON b.arch_id = a.id
315                       JOIN bin_pkg bp ON b.bin_pkg  = bp.id
316                       JOIN src_ver sv ON b.src_ver_id  = sv.id
317                       JOIN src_pkg sp ON sv.src_pkg = sp.id
318                       LEFT OUTER JOIN src_ver svb ON sv.based_on = svb.id
319                       LEFT OUTER JOIN src_pkg spb ON spb.id = svb.src_pkg;
320
321 CREATE TABLE suite (
322        id SERIAL PRIMARY KEY,
323        suite_name TEXT NOT NULL UNIQUE,
324        version TEXT,
325        codename TEXT,
326        active BOOLEAN DEFAULT TRUE);
327 CREATE INDEX ON suite(codename);
328 CREATE INDEX ON suite(version);
329 INSERT INTO table_comments VALUES ('suite','Debian Release Suite (stable, testing, etc.)');
330 INSERT INTO column_comments VALUES ('suite','id','Suite id');
331 INSERT INTO column_comments VALUES ('suite','suite_name','Suite name');
332 INSERT INTO column_comments VALUES ('suite','version','Suite version; NULL if there is no appropriate version');
333 INSERT INTO column_comments VALUES ('suite','codename','Suite codename');
334 INSERT INTO column_comments VALUES ('suite','active','TRUE if the suite is still accepting uploads');
335
336 CREATE TABLE bin_associations (
337        id SERIAL PRIMARY KEY,
338        suite INT NOT NULL REFERENCES suite ON DELETE CASCADE ON UPDATE CASCADE,
339        bin INT NOT NULL REFERENCES bin_ver ON DELETE CASCADE ON UPDATE CASCADE,
340        created TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
341        modified TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL
342 );
343 INSERT INTO table_comments VALUES ('bin_associations','Binary <-> suite associations');
344 INSERT INTO column_comments VALUES ('bin_associations','id','Binary <-> suite association id');
345 INSERT INTO column_comments VALUES ('bin_associations','suite','Suite id (matches suite)');
346 INSERT INTO column_comments VALUES ('bin_associations','bin','Binary version id (matches bin_ver)');
347 INSERT INTO column_comments VALUES ('bin_associations','created','Time this binary package entered this suite');
348 INSERT INTO column_comments VALUES ('bin_associations','modified','Time this entry was modified');
349
350 CREATE TABLE src_associations (
351        id SERIAL PRIMARY KEY,
352        suite INT NOT NULL REFERENCES suite ON DELETE CASCADE ON UPDATE CASCADE,
353        source INT NOT NULL REFERENCES src_ver ON DELETE CASCADE ON UPDATE CASCADE,
354        created TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
355        modified TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL
356 );
357 INSERT INTO table_comments VALUES ('src_associations','Source <-> suite associations');
358 INSERT INTO column_comments VALUES ('src_associations','id','Source <-> suite association id');
359 INSERT INTO column_comments VALUES ('src_associations','suite','Suite id (matches suite)');
360 INSERT INTO column_comments VALUES ('src_associations','source','Source version id (matches src_ver)');
361 INSERT INTO column_comments VALUES ('src_associations','created','Time this source package entered this suite');
362 INSERT INTO column_comments VALUES ('src_associations','modified','Time this entry was modified');
363
364
365
366 CREATE TYPE bug_status_type AS ENUM ('pending','forwarded','pending-fixed','fixed','absent','done');
367 CREATE TABLE bug_status_cache (
368        id SERIAL PRIMARY KEY,
369        bug INT NOT NULL REFERENCES bug ON DELETE CASCADE ON UPDATE CASCADE,
370        suite INT REFERENCES suite ON DELETE CASCADE ON UPDATE CASCADE,
371        arch INT REFERENCES arch ON DELETE CASCADE ON UPDATE CASCADE,
372        status bug_status_type NOT NULL,
373        modified TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
374        asof TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL
375 );
376 CREATE UNIQUE INDEX ON bug_status_cache(bug,suite,arch);
377 CREATE INDEX ON bug_status_cache(bug);
378 CREATE INDEX ON bug_status_cache(status);
379 INSERT INTO table_comments  VALUES ('bug_status_cache','Source <-> suite associations');
380 INSERT INTO column_comments VALUES ('bug_status_cache','id','Source <-> suite association id');
381 INSERT INTO column_comments VALUES ('bug_status_cache','bug','Source <-> suite association id');
382 INSERT INTO column_comments VALUES ('bug_status_cache','suite','Source <-> suite association id');
383 INSERT INTO column_comments VALUES ('bug_status_cache','arch','Source <-> suite association id');
384 INSERT INTO column_comments VALUES ('bug_status_cache','status','Source <-> suite association id');
385 INSERT INTO column_comments VALUES ('bug_status_cache','modified','Source <-> suite association id');
386 INSERT INTO column_comments VALUES ('bug_status_cache','asof','Source <-> suite association id');
387
388
389
390 CREATE TABLE message (
391        id SERIAL PRIMARY KEY,
392        msgid TEXT,
393        from_complete TEXT,
394        from_addr TEXT,
395        to_complete TEXT,
396        to_addr TEXT,
397        subject TEXT NOT NULL DEFAULT '',
398        sent_date TIMESTAMP WITH TIME ZONE,
399        refs TEXT NOT NULL DEFAULT '',
400        spam_score FLOAT,
401        is_spam BOOLEAN DEFAULT FALSE
402 );
403 INSERT INTO table_comments VALUES ('message','Messages sent to bugs');
404 INSERT INTO column_comments VALUES ('message','id','Message id');
405 INSERT INTO column_comments VALUES ('message','msgid','Message id header');
406 INSERT INTO column_comments VALUES ('message','from_complete','Complete from header of message');
407 INSERT INTO column_comments VALUES ('message','from_addr','Address(es) of From: headers');
408 INSERT INTO column_comments VALUES ('message','to_complete','Complete to header of message');
409 INSERT INTO column_comments VALUES ('message','to_addr','Address(es) of To: header');
410 INSERT INTO column_comments VALUES ('message','subject','Subject of the message');
411 INSERT INTO column_comments VALUES ('message','sent_date','Time/date message was sent (from Date header)');
412 INSERT INTO column_comments VALUES ('message','refs','Contents of References: header');
413 INSERT INTO column_comments VALUES ('message','spam_score','Spam score from spamassassin');
414 INSERT INTO column_comments VALUES ('message','is_spam','True if this message was spam and should not be shown');
415
416 CREATE INDEX ON message(msgid);
417
418 CREATE TABLE message_refs (
419        id SERIAL PRIMARY KEY,
420        message INT NOT NULL REFERENCES message ON DELETE CASCADE ON UPDATE CASCADE,
421        refs INT NOT NULL REFERENCES message ON DELETE CASCADE ON UPDATE CASCADE,
422        inferred BOOLEAN DEFAULT FALSE,
423        primary_ref BOOLEAN DEFAULT FALSE,
424        CONSTRAINT message_doesnt_reference_itself CHECK (message <> refs)
425 );
426 CREATE UNIQUE INDEX ON message_refs(message,refs);
427 CREATE INDEX ON message_refs(refs);
428 CREATE INDEX ON message_refs(message);
429 INSERT INTO table_comments VALUES ('message_refs','Message references');
430 INSERT INTO column_comments VALUES ('message_refs','message','Message id (matches message)');
431 INSERT INTO column_comments VALUES ('message_refs','refs','Reference id (matches message)');
432 INSERT INTO column_comments VALUES ('message_refs','inferred','TRUE if this message reference was reconstructed; primarily of use for messages which lack In-Reply-To: or References: headers');
433 INSERT INTO column_comments VALUES ('message_refs','primary_ref','TRUE if this message->ref came from In-Reply-To: or similar.');
434
435
436
437 CREATE TABLE correspondent_full_name(
438        id SERIAL PRIMARY KEY,
439        correspondent INT NOT NULL REFERENCES correspondent ON DELETE CASCADE ON UPDATE CASCADE,
440        full_name TEXT NOT NULL
441 );
442 CREATE UNIQUE INDEX ON correspondent_full_name(correspondent,full_name);
443
444 INSERT INTO table_comments VALUES ('correspondent_full_name','Full names of BTS correspondents');
445 INSERT INTO column_comments VALUES ('correspondent_full_name','id','Correspondent full name id');
446 INSERT INTO column_comments VALUES ('correspondent_full_name','correpsondent','Correspondent ID (matches correspondent)');
447 INSERT INTO column_comments VALUES ('correspondent_full_name','full_name','Correspondent full name (includes e-mail address)');
448
449 CREATE TYPE message_correspondent_type AS ENUM ('to','from','envfrom','cc');
450
451 CREATE TABLE message_correspondent (
452        id SERIAL PRIMARY KEY,
453        message INT NOT NULL REFERENCES message ON DELETE CASCADE ON UPDATE CASCADE,
454        correspondent INT NOT NULL REFERENCES correspondent ON DELETE CASCADE ON UPDATE CASCADE,
455        correspondent_type message_correspondent_type NOT NULL DEFAULT 'to'
456 );
457 INSERT INTO table_comments VALUES ('message_correspondent','Linkage between correspondent and message');
458 INSERT INTO column_comments VALUES ('message_correspondent','message','Message id (matches message)');
459 INSERT INTO column_comments VALUES ('message_correspondent','correspondent','Correspondent (matches correspondent)');
460 INSERT INTO column_comments VALUES ('message_correspondent','correspondent_type','Type of correspondent (to, from, envfrom, cc, etc.)');
461
462 CREATE UNIQUE INDEX ON message_correspondent(message,correspondent,correspondent_type);
463 CREATE INDEX ON message_correspondent(correspondent);
464 CREATE INDEX ON message_correspondent(message);
465
466 CREATE TABLE bug_message (
467        id SERIAL PRIMARY KEY,
468        bug INT NOT NULL REFERENCES bug ON DELETE CASCADE ON UPDATE CASCADE,
469        message INT NOT NULL REFERENCES message ON DELETE CASCADE ON UPDATE CASCADE,
470        message_number INT NOT NULL,
471        bug_log_offset INT,
472        offset_valid TIMESTAMP WITH TIME ZONE
473 );
474 INSERT INTO table_comments VALUES ('bug_mesage','Mapping between a bug and a message');
475 INSERT INTO column_comments VALUES ('bug_message','bug','Bug id (matches bug)');
476 INSERT INTO column_comments VALUES ('bug_message','message','Message id (matches message)');
477 INSERT INTO column_comments VALUES ('bug_message','message_number','Message number in the bug log');
478 INSERT INTO column_comments VALUES ('bug_message','bug_log_offset','Byte offset in the bug log');
479 INSERT INTO column_comments VALUES ('bug_message','offset_valid','Time offset was valid');
480