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