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