~launchpad-pqm/launchpad/devel

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
--
-- This will DESTROY your database and create a fresh one
--

/*

  TODO

        - re-evalutate some of the "text" field types, they might need to be "bytea"
	  unless we can guarantee utf-8
        - re-evaluate the relationship table names, see if there isn't a better name for each of them
	- add sample data for the schemas
	- make sure names are only [a-z][0-9][-.+] and can only start with [a-z]
	- present the database as a set of Interfaces

  CHANGES

  v0.94:
        - rename soyuz.sql to launchpad.sql
	- make Schema.extensible DEFAULT false (thanks spiv)
  v0.93:
        - add a manifest to Sourcepackage and Product, for the mutable HEAD manifest
	- add a manifest to CodeRelease
	- rename includeas to entrytype in ManifestEntry
	- remove "part" from ManifestEntry
	- add hints in Manifest table so sourcerer knows how to name patch branches
	- fix my brain dead constraints for mutual exlcusivity on branch/changeset specs
	- for a ManifestEntry, branch AND changeset can now both be null, to allow for Scott's virtual entries
	- add the Packaging table to indicate the relationship between a Product and a Sourcepackage
  v0.92:
        - make Schema and Label have name, title, description
        - added filenames for UpstreamreleaseFile, SourcepackageFile and BinarypackageBuildFile
        - linked BinarypackageBuild to DistroRelease instead of DistroArchRelease
        - add the Country table for a list of countries
	- add the SpokenIn table to link countries and languages
        - rename TranslationProject to TranslationEffort
        - add iscurrent (boolean) field to the POTFiles table, current POTFiles
	    will be displayed in project summary pages.
        - add ChangesetFile, ChangesetFilename and ChangesetFileHash tables
        - rename Release to CodeRelease (and all dependent tables)
        - refactor Processor and ProcessorFamily:
	  - the distroarchrelease now has a processorfamily field
	  - the binarypackagebuild (deb) now records its processor
	- refactor the allocation of binarypackagebuild's (debs) to distroarchrelease's
	  - create a new table BinarypackageUpload that stores the packagearchivestatus
	  - remove that status from the BinarypackageBuild table
	- refactor sourcepackage upload status
	  - move changes and urgency to sourcepackagerelease
	  - add builddependsindep so sourcepackagerelease

  v0.91:
        - remove Translation_POTFile_Relationship
	- ...and replace with a "project" field in POTFile
	- add a commenttext field to the POTMsgIDSighting table so we can track comments in POT files too

  v0.9:
         6 July 2004
       - first versioned release
*/

/*
  DESTROY ALL TABLES
*/
DROP TABLE SpokenIn CASCADE;
DROP TABLE Country CASCADE;
DROP TABLE BugMessageSighting CASCADE;
DROP TABLE TranslationEffort_POTFile_Relationship CASCADE;
DROP TABLE POComment CASCADE;
DROP TABLE Branch_Relationship CASCADE;
DROP TABLE BugSystem CASCADE;
DROP TABLE BugWatch CASCADE;
DROP TABLE RosettaPOTranslationSighting CASCADE;
DROP TABLE BugAttachment CASCADE;
DROP TABLE BugAttachment_Relationship CASCADE;
DROP TABLE License CASCADE;
DROP TABLE Bug_Relationship CASCADE;
DROP TABLE BugMessage CASCADE;
DROP TABLE POTranslationSighting CASCADE;
DROP TABLE BugRef CASCADE;
DROP TABLE Bug CASCADE;
DROP TABLE Packaging CASCADE;
DROP TABLE SourcepackageReleaseFile CASCADE;
DROP TABLE Sourcepackage_Relationship CASCADE;
DROP TABLE SourcepackageRelease CASCADE;
DROP TABLE CodeReleaseBugStatus CASCADE;
DROP TABLE SourcepackageLabel CASCADE;
DROP TABLE SourcepackageBugStatus CASCADE;
DROP TABLE Bug_Sourcepackage_Relationship CASCADE;
DROP TABLE SourcepackageUpload CASCADE;
DROP TABLE Sourcepackage CASCADE;
DROP TABLE BinarypackageBuildFile CASCADE;
DROP TABLE BinarypackageUpload CASCADE;
DROP TABLE BinarypackageBuild CASCADE;
DROP TABLE Binarypackage CASCADE;
DROP TABLE ProductBugStatus CASCADE;
DROP TABLE Branch CASCADE;
DROP TABLE ArchConfig CASCADE;
DROP TABLE ArchConfigEntry CASCADE;
DROP TABLE BugActivity CASCADE;
DROP TABLE ArchArchiveLocation CASCADE;
DROP TABLE POTranslation CASCADE;
DROP TABLE BugSystemType CASCADE;
DROP TABLE POTSubscription CASCADE;
DROP TABLE ChangesetFileHash CASCADE;
DROP TABLE ChangesetFile CASCADE;
DROP TABLE ChangesetFileName CASCADE;
DROP TABLE Changeset CASCADE;
DROP TABLE ArchArchive CASCADE;
DROP TABLE UpstreamReleaseFile CASCADE;
DROP TABLE UpstreamRelease CASCADE;
DROP TABLE CodeRelease CASCADE;
DROP TABLE CodeRelease_Relationship CASCADE;
DROP TABLE POTInheritance CASCADE;
DROP TABLE POTMsgIDSighting CASCADE;
DROP TABLE Manifest CASCADE;
DROP TABLE ProductLabel CASCADE;
DROP TABLE Product CASCADE;
DROP TABLE POFile CASCADE;
DROP TABLE POTFile CASCADE;
DROP TABLE Project_Relationship;
DROP TABLE POMsgID CASCADE;
DROP TABLE Language CASCADE;
DROP TABLE BugLabel CASCADE;
DROP TABLE TranslationEffort CASCADE;
DROP TABLE Project CASCADE;
DROP TABLE Project_TranslationEffort_Relationship CASCADE;
DROP TABLE Person CASCADE;
DROP TABLE EmailAddress CASCADE;
DROP TABLE TranslationFilter CASCADE;
DROP TABLE BranchLabel CASCADE;
DROP TABLE ManifestEntry CASCADE;
DROP TABLE GPGKey CASCADE;
DROP TABLE ArchUserID CASCADE;
DROP TABLE Membership CASCADE;
DROP TABLE WikiName CASCADE;
DROP TABLE JabberID CASCADE;
DROP TABLE IRCID CASCADE;
DROP TABLE PersonLabel CASCADE;
DROP TABLE TeamParticipation CASCADE;
DROP TABLE Schema CASCADE;
DROP TABLE Label CASCADE;
DROP TABLE Distribution CASCADE;
DROP TABLE DistroRelease CASCADE;
DROP TABLE DistroArchRelease CASCADE;
DROP TABLE ProcessorFamily CASCADE;
DROP TABLE Builder CASCADE;
DROP TABLE Processor CASCADE;
DROP TABLE SoyuzFileHash CASCADE;
DROP TABLE SoyuzFile CASCADE;
DROP TABLE OSFileInPackage CASCADE;
DROP TABLE OSFile;



/*
  Person
  This is a person in the Soyuz system. A Person can also be a
  team if the teamowner is not NULL. Note that we will create a
  Person entry whenever we see an email address we didn't know
  about, or a GPG key we didn't know about... and if we later
  link that to a real Soyuz person we will update all the tables
  that refer to that temporary person.

  A Person is one of these automatically created people if it
  has a NULL password and is not a team.
  
  It's created first so that a Schema can have an owner, we'll
  then define Schemas and Labels a bit later.
*/
CREATE TABLE Person (
  person                serial PRIMARY KEY,
  presentationname      text,
  givenname             text,
  familyname            text,
  password              text,
  teamowner             integer REFERENCES Person,
  teamdescription       text,
  karma                 integer,
  karmatimestamp        timestamp
);

INSERT INTO Person ( presentationname, givenname, familyname ) VALUES ( 'Mark Shuttleworth', 'Mark', 'Shuttleworth' );     -- 1
INSERT INTO Person ( presentationname, givenname, familyname ) VALUES ( 'Dave Miller', 'David', 'Miller' );                -- 2
INSERT INTO Person ( presentationname, givenname, familyname ) VALUES ( 'Colin Watson', 'Colin', 'Watson' );               -- 3
INSERT INTO Person ( presentationname, givenname, familyname ) VALUES ( 'Steve Alexander', 'Steve', 'Alexander' );         -- 4
INSERT INTO Person ( presentationname, givenname, familyname ) VALUES ( 'Scott James Remnant', 'Scott James', 'Remnant' ); -- 5
INSERT INTO Person ( presentationname, givenname, familyname ) VALUES ( 'Robert Collins', 'Robert', 'Collins' );           -- 6


/*
  REVELATION. THE SOYUZ METADATA
*/


/*
  Schema
  This is the (finger finger) "metadata" (finger finger)
  which makes us... muahaha... distinctive... muahaha,
  muahahaha, muahahahahahaa....

  And yes, I'm not yet sure if my database model for this
  is on crack. Comments please. MS 24/06/04
*/
CREATE TABLE Schema (
  schema         serial PRIMARY KEY,
  name           text NOT NULL,
  title          text NOT NULL,
  description    text NOT NULL,
  owner          integer NOT NULL REFERENCES Person,
  extensible     boolean NOT NULL DEFAULT false
);



/*
  Label
  The set of labels in all schemas
*/
CREATE TABLE Label (
  label          serial PRIMARY KEY,
  schema         integer NOT NULL REFERENCES Schema,
  name           text NOT NULL,
  title          text NOT NULL,
  description    text NOT NULL
);




/*
  EmailAddress
  A table of email addresses for Soyuz people.
*/
CREATE TABLE EmailAddress (
  emailid     serial PRIMARY KEY,
  email       text NOT NULL UNIQUE,
  person      integer NOT NULL REFERENCES Person,
  label       integer NOT NULL REFERENCES Label
);



/*
  GPGKey
  A table of GPGKeys, mapping them to Soyuz users.
*/
CREATE TABLE GPGKey (
  gpgkey      serial PRIMARY KEY,
  person      integer NOT NULL REFERENCES Person,
  keyid       text NOT NULL UNIQUE,
  fingerprint text NOT NULL UNIQUE,
  pubkey      text NOT NULL,
  revoked     boolean NOT NULL
);



/*
  ArchUserID
  A table of Arch user id's
*/
CREATE TABLE ArchUserID (
  person     integer NOT NULL REFERENCES Person,
  archuserid text NOT NULL UNIQUE
);



/*
  WikiName
  The identity a person uses on one of the Soyuz wiki's.
*/
CREATE TABLE WikiName (
  person     integer NOT NULL REFERENCES Person,
  wiki       text NOT NULL,
  wikiname   text NOT NULL,
  UNIQUE ( wiki, wikiname )
);



/*
  JabberID
  A person's Jabber ID on our network.
*/
CREATE TABLE JabberID (
  person      integer NOT NULL REFERENCES Person,
  jabberid    text NOT NULL UNIQUE
);



/*
  IrcID
  A person's irc nick's.
*/
CREATE TABLE IRCID (
  person       integer NOT NULL REFERENCES Person,
  network      text NOT NULL,
  nickname     text NOT NULL
);




/*
  PersonLabel
  A neat way to attache tags to people...
*/
CREATE TABLE PersonLabel (
  person       integer NOT NULL REFERENCES Person,
  label        integer NOT NULL REFERENCES Label
);



/*
  Membership
  A table of memberships. It's only valid to have a membership
  in a team, not a non-team person.
*/
CREATE TABLE Membership (
  person      integer NOT NULL REFERENCES Person,
  team        integer NOT NULL REFERENCES Person,
  label       integer NOT NULL REFERENCES Label,
  status      integer NOT NULL REFERENCES Label,
  PRIMARY KEY ( person, team )
);



/*
  TeamParticipation
  This is a table which shows all the memberships
  of a person. Effectively it collapses team hierarchies
  and flattens them to a straight team-person relation.
  People are also members of themselves. This allows
  us to query against a person entry elsewhere in Soyuz
  and quickly find the things a person is an owner of.
*/
CREATE TABLE TeamParticipation (
  team         integer NOT NULL REFERENCES Person,
  person       integer NOT NULL REFERENCES Person,
  PRIMARY KEY ( team, person )
);



/*
  BUTTRESS. THE ARCH REPOSITORY.
  This is the Soyuz subsystem that handles the storing and
  cataloguing of all of our Arch branches.
*/



/*
  ArchArchive
  A table of all known Arch Archives.
*/
CREATE TABLE ArchArchive (
  archive       serial PRIMARY KEY,
  name          text NOT NULL,
  title         text NOT NULL,
  description   text NOT NULL,
  visible       boolean NOT NULL,
  owner         integer REFERENCES Person
);



/*
  ArchArchiveLocation
  A table of known Arch archive locations.
*/
CREATE TABLE ArchArchiveLocation (
  archive       integer NOT NULL REFERENCES ArchArchive,
  archivetype   integer NOT NULL REFERENCES Label, -- the Arch archive type
  url           text NOT NULL,
  gpgsigned     boolean NOT NULL
);



/*
  Branch
  An Arch Branch in the Soyuz system.
*/
CREATE TABLE Branch (
  branch                 serial PRIMARY KEY,
  archive                integer NOT NULL REFERENCES ArchArchive,
  categorybranchversion  text NOT NULL,
  title                  text NOT NULL,
  description            text NOT NULL,
  visible                boolean NOT NULL,
  owner                  integer REFERENCES Person
);


/*
  Changeset
  An Arch changeset.
*/
CREATE TABLE Changeset (
  changeset      serial PRIMARY KEY,
  branch         integer NOT NULL REFERENCES Branch,
  createdate     timestamp NOT NULL,
  logmessage     text NOT NULL,
  author         integer REFERENCES Person,
  gpgkey         integer REFERENCES GPGKey
);



/*
  ChangesetFileName
  A filename in an arch changeset.
*/
CREATE TABLE ChangesetFileName (
  changesetfilename     serial PRIMARY KEY,
  filename              text NOT NULL UNIQUE
);



/*
  ChangesetFile
  A file in an arch changeset.
*/
CREATE TABLE ChangesetFile (
  changesetfile      serial PRIMARY KEY,
  changeset          integer NOT NULL REFERENCES Changeset,
  changesetfilename  integer NOT NULL REFERENCES ChangesetFileName,
  filecontents       bytea NOT NULL,
  filesize           integer NOT NULL,
  UNIQUE ( changeset, changesetfilename )
);



/*
  ChangesetFileHash
  A cryptographic hash of a changeset file.
*/
CREATE TABLE ChangesetFileHash (
  changesetfile     integer NOT NULL REFERENCES ChangesetFile,
  hashalg           integer NOT NULL REFERENCES Label,
  hash              bytea NOT NULL
);



/*
  Branch_Relationship
  A table of relationships between branches. For example:
  "src is a debianization-branch-of dst"
  "src is-a-patch-branch-of dst
*/
CREATE TABLE Branch_Relationship (
  src        integer NOT NULL REFERENCES Branch,
  dst        integer NOT NULL REFERENCES Branch,
  label      integer NOT NULL REFERENCES Label,
  PRIMARY KEY ( src, dst )
);




/*
  BranchLabel
  A table of labels on branches.
*/
CREATE TABLE BranchLabel (
  branch       int NOT NULL REFERENCES Branch,
  label        int NOT NULL REFERENCES Label
);




/*
  Manifest
  A release manifest. This is sort of an Arch config
  on steroids. A Manifest is a set of ManifestEntry's
*/
CREATE TABLE Manifest (
  manifest         serial PRIMARY KEY,
  creationdate     timestamp NOT NULL,
  brancharchive    integer REFERENCES ArchArchive, --
  branchcategory   text,                           -- Where to put new patch-branches
  branchversion    text                            --
);




/*
  ManifestEntry
  An entry in a Manifest. each entry specifies either a branch or
  a specific changeset (revision) on a branch, as well as how that
  piece of code (revision) is brought into the release.
*/
CREATE TABLE ManifestEntry (
  manifest        integer NOT NULL REFERENCES Manifest,
  sequence        integer NOT NULL,
  branch          integer REFERENCES Branch,
  changeset       integer REFERENCES Changeset,
  entrytype       integer NOT NULL REFERENCES Label,
  path            text NOT NULL,
  patchon         integer NOT NULL,
  -- sequence must be a positive integer
  CHECK ( sequence > 0 ),
  -- EITHER branch OR changeset:
  CHECK ( NOT ( branch IS NOT NULL AND changeset IS NOT NULL ) ),
  -- the "patchon" must be another manifestentry from the same
  -- manifest, and a different sequence
  -- XXX no idea how to express this constraint, help!
  -- the primary key is the combination of manifest and sequence
  PRIMARY KEY ( manifest, sequence )
);



/*
  FLOSS. THE OPEN SOURCE WORLD
  This is the Soyuz subsystem that models the open source world
  of projects and products.
*/


/*
 The Project table. This stores information about an open
 source project, which can be translated or packaged, or
 about which bugs can be filed.
*/
CREATE TABLE Project (
    project      serial PRIMARY KEY,
    owner        integer NOT NULL REFERENCES Person,
    name         text NOT NULL UNIQUE,
    title        text NOT NULL,
    description  text,
    homepage     text
    );


/*
 The Project_Relationship table. This stores information about
 the relationships between open source projects. For example,
 the Gnome project aggregates the GnomeMeeting project.
*/
CREATE TABLE Project_Relationship (
  src           integer NOT NULL REFERENCES Project,
  dst           integer NOT NULL REFERENCES Project,
  relationship  text NOT NULL,
  value         text
);



/*
  Product
  A table of project products. A product is something that
  can be built, or a branch of code that is useful elsewhere, or
  a set of docs... some distinct entity. Products can be made
  up of other products, but that is not reflected in this
  database. For example, Firefax includes Gecko, both are
  products.
*/
CREATE TABLE Product (
  product       serial PRIMARY KEY,
  project       integer NOT NULL REFERENCES Project,
  owner         integer NOT NULL REFERENCES Person,
  name          text NOT NULL,
  title         text NOT NULL,
  description   text NOT NULL,
  homepage      text,
  manifest      integer REFERENCES Manifest,
  UNIQUE ( project, name )
);



/*
  ProductLabel
  A label or metadata on a Product.
*/
CREATE TABLE ProductLabel (
  product  integer NOT NULL REFERENCES Product,
  label      integer NOT NULL REFERENCES Label,
  PRIMARY KEY ( product, label )
);



/*
  UpstreamRelease
  A specific tarball release of Upstream.
*/
CREATE TABLE UpstreamRelease (
  upstreamrelease  serial PRIMARY KEY,
  product        integer NOT NULL REFERENCES Product,
  releasedate      timestamp NOT NULL,
  name             text NOT NULL,
  gsvname          text,
  description      text,
  owner            integer REFERENCES Person
);


/*
   BUTTRESS phase 2
*/


/*
  ArchConfig
  A table to model Arch configs.
*/
CREATE TABLE ArchConfig (
  archconfig       serial PRIMARY KEY,
  name             text NOT NULL,
  title            text NOT NULL,
  description      text NOT NULL,
  upstreamrelease  integer REFERENCES UpstreamRelease,
  owner            integer REFERENCES Person
);



/*
  ArchConfigEntry
  A table to represent the entries in an Arch config. Each
  row is a separate entry in the arch config.
*/
CREATE TABLE ArchConfigEntry (
  archconfig    integer NOT NULL REFERENCES ArchConfig,
  path          text NOT NULL,
  branch        integer REFERENCES Branch,
  changeset     integer REFERENCES Changeset,
  -- EITHER branch OR changeset:
  CHECK ( NOT ( branch IS NULL AND changeset IS NULL ) ),
  CHECK ( NOT ( branch IS NOT NULL AND changeset IS NOT NULL ) )
);



/*
  LOGISTIX. THE PACKAGES AND DISTRIBUTION MANAGER.
  Nicknamed after UPS (United Parcel Service) this is the
  Soyuz subsystem that deals with distribution and packages.
*/



/*
  ProcessorFamily
  A family of CPU's, which are all compatible. In other words, code
  compiled for any one of these processors will run on any of the
  others.
*/
CREATE TABLE ProcessorFamily (
  processorfamily    serial PRIMARY KEY,
  name               text NOT NULL UNIQUE,
  title              text NOT NULL,
  description        text NOT NULL,
  owner              integer NOT NULL REFERENCES Person
);



/*
  Processor
  This is a table of system architectures. A DistroArchRelease needs
  to be one of these.
*/
CREATE TABLE Processor (
  processor          serial PRIMARY KEY,
  family             integer NOT NULL REFERENCES ProcessorFamily,
  name               text NOT NULL UNIQUE,
  title              text NOT NULL,
  description        text NOT NULL,
  owner              integer NOT NULL REFERENCES Person
);



/*
  Builder
  An Ubuntu build daemon.
*/
CREATE TABLE Builder (
  builder            serial PRIMARY KEY,
  processor          integer NOT NULL REFERENCES Processor,
  fqdn               text NOT NULL,
  name               text NOT NULL,
  title              text NOT NULL,
  description        integer NOT NULL REFERENCES Person,
  UNIQUE ( fqdn, name )
);



/*
  Distribution
  An open source distribution. Collection of packages, the reason
  for Soyuz existence.
*/
CREATE TABLE Distribution (
  distribution     serial PRIMARY KEY,
  name             text NOT NULL,
  title            text NOT NULL,
  description      text NOT NULL,
  components       integer NOT NULL REFERENCES Schema,
  sections         integer NOT NULL REFERENCES Schema,
  owner            integer NOT NULL REFERENCES Person
);



/*
  DistroRelease
  These are releases of the various distributions in the system. For
  example: warty, hoary, grumpy, woody, potato, slink, sarge, fc1,
  fc2.
*/
CREATE TABLE DistroRelease (
  distrorelease   serial PRIMARY KEY,
  distribution    integer NOT NULL REFERENCES Distribution,
  name            text NOT NULL, -- "warty"
  title           text NOT NULL, -- "Ubuntu 4.10 (The Warty Warthog Release)"
  description     text NOT NULL,
  version         text NOT NULL, -- "4.10"
  releasestate    integer NOT NULL REFERENCES Label
);




/*
  DistroArchRelease
  This is a distrorelease for a particular architecture, for example,
  warty-i386.
*/
CREATE TABLE DistroArchRelease (
  distroarchrelease serial PRIMARY KEY,
  distrorelease     integer NOT NULL REFERENCES DistroRelease,
  processor         integer NOT NULL REFERENCES Processor,
  architecturetag   text NOT NULL,
  releasestatus     integer NOT NULL REFERENCES Label,
  releasedate       timestamp,
  owner             integer NOT NULL REFERENCES Person
);



/*
  SoyuzFile
  The Soyuz system keeps copies of all the files that are used to make
  up a distribution, such as deb's and tarballs and .dsc files and .spec
  files and CodeRelease files... these are represented by this table.
*/
CREATE TABLE SoyuzFile (
  soyuzfile        serial PRIMARY KEY,
  filename         text NOT NULL,
  filesize         integer NOT NULL
);



/*
  SoyuzFileHash
  A hash (cryptographic digest) on the file. We can support multiple
  different hashes with different algorithms. Initially we'll just 
  use SHA1, but if that gets broken we can trivially switch to another
  algorithm.

  The hash is not required to be UNIQUE but Oscar should flag duplicates
  for inspection by hand. Note that the combination of filesize and hash
  should be unique or there is something very weird going on. Or we just hit
  the crypto lottery and found a collision.
*/
CREATE TABLE SoyuzFileHash (
  soyuzfile       integer NOT NULL REFERENCES SoyuzFile,
  hashalg         integer NOT NULL REFERENCES Label,
  hash            bytea NOT NULL
);



/*
  UpstreamReleaseFile
  A file from an Upstream CodeRelease. Usually this would be a tarball.
*/
CREATE TABLE UpstreamReleaseFile (
  upstreamrelease integer NOT NULL REFERENCES UpstreamRelease,
  soyuzfile       integer NOT NULL REFERENCES SoyuzFile,
  filetype        integer NOT NULL REFERENCES Label,
  filename        text NOT NULL
);



/*
  Sourcepackage
  A distribution source package. In RedHat or Debian this is the name
  of the source package, in Gentoo it's the Ebuild name.
*/
CREATE TABLE Sourcepackage (
  sourcepackage    serial PRIMARY KEY,
  maintainer       integer NOT NULL REFERENCES Person,
  name             text NOT NULL,
  title            text NOT NULL,
  description      text NOT NULL,
  manifest         integer REFERENCES Manifest
);



/*
  Sourcepackage_Relationship
  The relationship between two source packages. For example, if a source
  package in Ubuntu is derived from a source package in Debian, we would
  reflect that here.
*/
CREATE TABLE Sourcepackage_Relationship (
  src       integer NOT NULL REFERENCES Sourcepackage,
  dst       integer NOT NULL REFERENCES Sourcepackage,
  label     integer NOT NULL REFERENCES Sourcepackage,
  CHECK ( src <> dst )
);



/*
  SourcepackageLabel
  A tag or label on a source package.
*/
CREATE TABLE SourcepackageLabel (
  sourcepackage     integer NOT NULL REFERENCES Sourcepackage,
  label             integer NOT NULL REFERENCES Label
);




/*
  Packaging
  This is really the relationship between a Product and a
  Sourcepackage. For example, it allows us to say that
  the apache2 source package is a packaging of the
  httpd Product from the Apache Group.
*/
CREATE TABLE Packaging (
  product         integer NOT NULL REFERENCES Product,
  sourcepackage   integer NOT NULL REFERENCES Sourcepackage,
  label           integer NOT NULL REFERENCES Label
);




/*
  SourcepackageRelease
  A SourcepackageRelease is a specific release of a Sourcepackage, which is
  associated with one or more distribution releases. So apache2__2.0.48-3 can
  be in both ubuntu/warty and debian/sarge.
*/
CREATE TABLE SourcepackageRelease (
  sourcepackagerelease   serial PRIMARY KEY,
  sourcepackage          integer NOT NULL REFERENCES Sourcepackage,
  srcpackageformat       integer NOT NULL REFERENCES Label,
  creator                integer NOT NULL REFERENCES Person,
  version                text NOT NULL, -- "2.0.48-3"
  dateuploaded           timestamp NOT NULL,
  urgency                integer NOT NULL REFERENCES Label,
  dscsigningkey          integer REFERENCES GPGKey,
  component              integer REFERENCES Label,
  changelog              text,
  changes                text,
  builddepends           text,
  builddependsindep      text,
  architecturehintlist   text
);



/*
  SourcepackageReleaseFile
  A file associated with a sourcepackagerelease. For example, could be
  a .dsc file, or an orig.tar.gz, or a diff.gz...
*/
CREATE TABLE SourcepackageReleaseFile (
  sourcepackagerelease  integer NOT NULL REFERENCES SourcepackageRelease,
  soyuzfile             integer NOT NULL REFERENCES SoyuzFile,
  filetype              integer NOT NULL REFERENCES Label,
  filename              text NOT NULL
);



/*
  SourcepackageUpload
  This table indicates which sourcepackagereleases are present in a
  given distrorelease. It also indicates their status in that release
  (for example, whether or not that sourcepackagerelease has been
  withdrawn, or is currently published, in that archive).
*/
CREATE TABLE SourcepackageUpload (
  distrorelease          integer NOT NULL REFERENCES DistroRelease,
  sourcepackagerelease   integer NOT NULL REFERENCES SourcepackageRelease,
  packagereleasestatus   integer NOT NULL REFERENCES Label,
  PRIMARY KEY ( distrorelease, sourcepackagerelease )
);



/*
  Binarypackage
  This is a binary package... not an actual built package (that
  is a BinarypackageBuild) but the concept of that binary package.
  It stores the name of the binary package, together with other
  details. Note that different distributions might well have
  different binary packages with the same name. In fact, a single
  distribution might have binary packages with the same name at
  different times, that have entirely different source packages
  and hence maintainers.
*/
CREATE TABLE Binarypackage (
  binarypackage    serial PRIMARY KEY,
  name             text NOT NULL,
  title            text NOT NULL,
  description      text NOT NULL
);




/*
  BinarypackageBuild
  This is an actual package, built on a specific architecture,
  ready for installation.
*/
CREATE TABLE BinarypackageBuild (
  binarypackagebuild     serial PRIMARY KEY,
  sourcepackagerelease   integer NOT NULL REFERENCES SourcepackageRelease,
  binarypackage          integer NOT NULL REFERENCES Binarypackage,
  processor              integer NOT NULL REFERENCES Processor,
  binpackageformat       integer NOT NULL REFERENCES Label,
  version                text NOT NULL,
  builddate              timestamp NOT NULL,
  gpgsigningkey          integer REFERENCES GPGKey,
  component              integer REFERENCES Label,
  section                integer REFERENCES Label,
  priority               integer REFERENCES Label,
  shlibdeps              text,
  depends                text,
  recommends             text,
  suggests               text,
  conflicts              text,
  replaces               text,
  provides               text,
  essential              boolean,
  installedsize          integer
);



/*
  BinarypackageBuildFile
  This is a file associated with a built binary package. Could
  be a .deb or an rpm, or something similar from a gentoo box.
*/
CREATE TABLE BinarypackageBuildFile (
  binarypackagebuild     integer NOT NULL REFERENCES BinarypackageBuild,
  soyuzfile              integer NOT NULL REFERENCES SoyuzFile,
  filetype               integer NOT NULL REFERENCES Label,
  filename               text NOT NULL
);



/*
  BinarypackageUpload
  This table records the status of a binarypackagebuild (deb) in a
  distrorelease (woody)
*/
CREATE TABLE BinarypackageUpload (
  binarypackagebuild     integer NOT NULL REFERENCES BinarypackageBuild,
  distrorelease          integer NOT NULL REFERENCES DistroRelease,
  packagestatus          integer NOT NULL REFERENCES Label
);




/*
  LIBRARIAN. TRACKING UPSTREAM AND SOURCE PACKAGE RELEASES.
  This section is devoted to data that tracks upstream and distribution
  SOURCE PACKAGE releases. So, for example, Apache 2.0.48 is an
  UpstreamRelease. Apache 2.0.48-3 is a Debian SourcepackageRelease.
  We have data tables for both of those, and the CodeRelease table is
  the data that is common to any kind of CodeRelease. This subsystem also
  keeps track of the actual files associated with CodeReleases, such as
  tarballs and deb's and .dsc files and changelog files...
*/



/*
  CodeRelease
  A release of software. Could be an Upstream release or
  a SourcepackageRelease.
*/
CREATE TABLE CodeRelease (
  coderelease          serial PRIMARY KEY,
  upstreamrelease      integer REFERENCES UpstreamRelease,
  sourcepackagerelease integer REFERENCES SourcepackageRelease,
  manifest             integer REFERENCES Manifest,
  CHECK ( NOT ( upstreamrelease IS NULL AND sourcepackagerelease IS NULL ) ),
  CHECK ( NOT ( upstreamrelease IS NOT NULL AND sourcepackagerelease IS NOT NULL ) )
); -- EITHER upstreamrelease OR sourcepackagerelease must not be NULL



/*
  CodeRelease_Relationship
  Maps the relationships between releases (upstream and
  sourcepackage).
*/
CREATE TABLE CodeRelease_Relationship (
  src       integer NOT NULL REFERENCES CodeRelease,
  dst       integer NOT NULL REFERENCES CodeRelease,
  label     integer NOT NULL REFERENCES Label,
  PRIMARY KEY ( src, dst )
);




/*
  OSFile
  This is a file in one of the OS's managed in Soyuz.
*/
CREATE TABLE OSFile (
  osfile    serial PRIMARY KEY,
  path      text NOT NULL UNIQUE
);



/*
  OSFileInPackage
  This table tells us all the files that are in a given binary package
  build. It also includes information about the files, such as their
  unix permissions, and whether or not they are a conf file.
*/
CREATE TABLE OSFileInPackage (
  osfile               integer NOT NULL REFERENCES OSFile,
  binarypackagebuild   integer NOT NULL REFERENCES BinarypackageBuild,
  unixperms            integer NOT NULL,
  conffile             boolean NOT NULL,
  createdby            boolean NOT NULL
);



/*
  ROSETTA. THE TRANSLATION SUPER-PORTAL
  This is the Soyuz subsystem that coordinates and manages
  the translation of open source software and documentation.
*/



/*
  TranslationFilter
  A set of "sunglasses" through which we see translations. We only want
  to see translations that are compatible with this filter in terms
  of licence, review and contribution criteria. This will not be
  implemented in Rosetta v1.0
*/
CREATE TABLE TranslationFilter (
  translationfilter serial PRIMARY KEY,
  owner             integer NOT NULL REFERENCES Person,
  title             text,
  description       text
);



/*
 The TranslationEffort table. Stores information about each active
 translation effort. Note, a translationeffort is an aggregation of
 works. For example, the Gnome Translation Project, which aims to
 translate the PO files for many gnome applications. This is a point
 for the translation team to rally around.
*/
CREATE TABLE TranslationEffort (
  translationeffort     serial PRIMARY KEY,
  owner                 integer NOT NULL REFERENCES Person,
  title                 text NOT NULL,
  description           text NOT NULL,
  translationfilter     integer REFERENCES TranslationFilter
);




/*
  Project_TranslationEffort_Relationship
  Maps the way a translation project is related to an open source
  project.
*/
CREATE TABLE Project_TranslationEffort_Relationship (
  project             integer NOT NULL REFERENCES Project,
  translationeffort   integer NOT NULL REFERENCES TranslationEffort,
  label               integer NOT NULL REFERENCES Label,
  PRIMARY KEY ( project, translationeffort )
);




/*
  POTInheritance
  A handle on an inheritance sequence for POT files.
*/
CREATE TABLE POTInheritance (
  potinheritance        serial PRIMARY KEY,
  title                 text,
  description           text
);



/*
  License
  A license. We need quite a bit more in the long term
  to track licence compatibility etc.
*/
CREATE TABLE License (
  license               serial PRIMARY KEY,
  legalese              text NOT NULL
);


/*
  POTFile
  A PO Template File, which is the first thing that Rosetta will set
  about translating.
*/
CREATE TABLE POTFile (
  potfile               serial PRIMARY KEY,
  project               integer NOT NULL REFERENCES Project,
  branch                integer REFERENCES Branch,
  changeset             integer REFERENCES Changeset,
  name                  text NOT NULL UNIQUE,
  title                 text NOT NULL,
  description           text NOT NULL,
  copyright             text NOT NULL,
  license               integer NOT NULL REFERENCES License,
  datecreated           timestamp NOT NULL,
  path                  text NOT NULL,
  iscurrent             boolean NOT NULL,
  defaultinheritance    integer REFERENCES POTInheritance,
  defaultfilter         integer REFERENCES TranslationFilter,
  owner                 integer REFERENCES Person,
  -- EITHER branch OR changeset:
  CHECK ( NOT ( branch IS NULL AND changeset IS NULL ) ),
  CHECK ( NOT ( branch IS NOT NULL AND changeset IS NOT NULL ) )
);



/*
  POMsgID
  A PO or POT File MessageID
*/
CREATE TABLE POMsgID (
  pomsgid              serial PRIMARY KEY,
  msgid                text UNIQUE
);



/*
  POTranslation
  A PO translation. This is just a piece of text, where the
  "translation" might in fact be the original language.
*/
CREATE TABLE POTranslation (
  potranslation         serial PRIMARY KEY,
  text                  text
);



/*
  Language
  A table of languages, for Rosetta.
*/
CREATE TABLE Language (
  language              serial PRIMARY KEY,
  code                  text NOT NULL UNIQUE,
  englishname           text,
  nativename            text
);




/*
  Country
  A list of countries.
*/
CREATE TABLE Country (
  country             serial PRIMARY KEY,
  iso3166code2        text NOT NULL,
  iso3166code3        text NOT NULL,
  name                text NOT NULL,
  title               text NOT NULL,
  description         text NOT NULL
);



/*
  SpokenIn
  A table linking countries the languages spoken in them.
*/
CREATE TABLE SpokenIn (
  language           integer NOT NULL REFERENCES Language,
  country            integer NOT NULL REFERENCES Country,
  PRIMARY KEY ( language, country )
);



/*
  POFile
  A PO File. This is a language-specific set of translations.
*/
CREATE TABLE POFile (
  pofile               serial PRIMARY KEY,
  potfile              integer NOT NULL REFERENCES POTFile,
  language             integer NOT NULL REFERENCES Language,
  title                text,
  description          text,
  topcomment           text,  -- the comment at the top of the file
  header               text,  -- the contents of the NULL msgstr
  lasttranslator       integer REFERENCES Person,
  license              integer REFERENCES License,
  completeness         integer  -- between 0 and 100
);



/*
  POTMsgIDSighting
  Table that documents the sighting of a particular msgid in a pot file.
*/
CREATE TABLE POTMsgIDSighting (
  potfile             integer NOT NULL REFERENCES POTFile,
  pomsgid             integer NOT NULL REFERENCES POMsgID,
  firstseen           timestamp NOT NULL,
  lastseen            timestamp NOT NULL,
  iscurrent           boolean NOT NULL,
  commenttext         text,
  singular            integer REFERENCES POMsgID, -- if this is not NULL then it's part of a tuple
  PRIMARY KEY ( potfile, pomsgid )
);



/*
  POTranslationSighting
  A sighting of a translation in a PO file IN REVISION CONTROL. This
  is contrasted with a RosettaPOTranslationSighting, which is a
  translation given to us for a potfile/language.
*/
CREATE TABLE POTranslationSighting (
  potranslationsighting serial PRIMARY KEY,
  pofile                integer NOT NULL REFERENCES POFile,
  pomsgid               integer NOT NULL REFERENCES POMsgID,
  potranslation         integer NOT NULL REFERENCES POTranslation,
  license               integer NOT NULL REFERENCES License,
  fuzzy                 boolean NOT NULL,
  rosettaprovided       boolean NOT NULL,
  firstseen             timestamp NOT NULL,
  lastseen              timestamp NOT NULL,
  iscurrent             boolean NOT NULL,
  commenttext           text,
  pluralform            integer,
  CHECK ( pluralform >= 0 )
);



/*
  RosettaPOTranslationSighting
  A record of a translation given to Rosetta through the web, or
  web service, or otherwise.
*/
CREATE TABLE RosettaPOTranslationSighting (
  rosettapotranslation serial PRIMARY KEY,
  person               integer NOT NULL REFERENCES Person,
  potfile              integer NOT NULL REFERENCES POTFile,
  pomsgid              integer NOT NULL REFERENCES POMsgID,
  language             integer NOT NULL REFERENCES Language,
  potranslation        integer NOT NULL REFERENCES POTranslation,
  license              integer NOT NULL REFERENCES License,
  dateprovided         timestamp NOT NULL,
  datetouched          timestamp NOT NULL,
  pluralform           integer,
  CHECK ( pluralform >= 0 )
);



/*
  POComment
  A table of comments provided by translators and the translation
  system (these are extracted from PO files as well as provided to
  us through the web and web services API).
*/
CREATE TABLE POComment (
  pocomment           serial PRIMARY KEY,
  potfile             integer NOT NULL REFERENCES POTFile,
  pomsgid             integer REFERENCES POMsgID,
  language            integer REFERENCES Language,
  potranslation       integer REFERENCES POTranslation,
  commenttext         text NOT NULL,
  date                timestamp NOT NULL,
  person              integer REFERENCES Person
);




/*
  TranslationEffort_POTFile_Relationship
  A translation project incorporates a POTfile that is under translation.
  The inheritance pointer allows this project to specify a custom
  translation inheritance sequence.
*/
CREATE TABLE TranslationEffort_POTFile_Relationship (
  translationeffort integer NOT NULL REFERENCES TranslationEffort ON DELETE CASCADE,
  potfile            integer NOT NULL REFERENCES POTFile,
  potinheritance     integer REFERENCES POTInheritance,
  UNIQUE (translationeffort , potfile)
);



/*
  Project_POTFile_Relationship
  Captures the relationship between a Project and a translated POTFile.
CREATE TABLE Project_POTFile_Relationship (
  project            integer NOT NULL REFERENCES Project,
  potfile            integer NOT NULL REFERENCES POTFile,
  label              integer NOT NULL REFERENCES Label
);
*/




/*
  POTSubscription
  Records the people who have subscribed to a POT File. They can
  subscribe to the POT file and get all the PO files, or just the PO
  files for a specific language.
*/
CREATE TABLE POTSubscription (
  potsubscription      serial PRIMARY KEY,
  person               integer NOT NULL REFERENCES Person,
  language             integer REFERENCES Language,
  notificationinterval interval NOT NULL,
  lastnotified         timestamp,
  potinheritance       integer REFERENCES POTInheritance,
  translationfilter    integer REFERENCES TranslationFilter
);



/*
  BOOGER. THE ISSUE TRACKING SYSTEM.
  This is the Soyuz subsystem that handled bugs and issue
  tracking for all the distributions we know about.
*/


/*
  Bug
  The core bug entry. A Booger.
*/
CREATE TABLE Bug (
  bug                     serial PRIMARY KEY,
  datecreated             timestamp NOT NULL,
  summary                 text NOT NULL,
  description             text NOT NULL,
  owner                   integer NOT NULL,
  duplicateof             integer REFERENCES Bug,
  communityscore          integer NOT NULL,
  communitytimestamp      timestamp NOT NULL,
  activityscore           integer NOT NULL,
  activitytimestamp       timestamp NOT NULL,
  hits                    integer NOT NULL,
  hitstimestamp           timestamp NOT NULL
);



/*
  CodeReleaseBugStatus
  This is a bug status scorecard. It's not a global status for the
  bug, this is usually attached to a release, or a sourcepackage in
  a distro. So these tell you the status of a bug SOMEWHERE. The
  pointer to this tells you which bug, and on what thing (the 
  SOMEWHERE) the status is being described.
*/
CREATE TABLE CodeReleaseBugStatus (
  bug              integer NOT NULL REFERENCES Bug,
  coderelease      integer NOT NULL REFERENCES CodeRelease,
  explicit         boolean NOT NULL,
  bugstatus        integer NOT NULL REFERENCES Label,
  priority         integer NOT NULL REFERENCES Label,
  severity         integer NOT NULL REFERENCES Label,
  reportedby       integer NOT NULL REFERENCES Person,
  verifiedby       integer NOT NULL REFERENCES Person,
  lastmodifiedby   integer NOT NULL REFERENCES Person,
  PRIMARY KEY ( bug, coderelease )
);



/*
  SourcepackageBugStatus
  The status of a bug with regard to a source package. This is different
  to the status on a specific release, because it includes the concept
  of workflow or prognosis ("what we intend to do with this bug") while
  the release bug status is static ("is the bug present or not").
*/
CREATE TABLE SourcepackageBugStatus (
  bug                integer NOT NULL REFERENCES Bug,
  sourcepackage      integer NOT NULL REFERENCES Sourcepackage,
  bugstatus          integer NOT NULL REFERENCES Label,
  binarypackagename  text,
  wontfix            boolean NOT NULL,
  PRIMARY KEY ( bug, sourcepackage )
);



/*
  Bug_Sourcepackage_Relationship
  This is a mapping of the relationship between a bug and a source
  package. Note that there is another similar table, the SourcepackageBugStatus,
  that is dedicated to the status of a bug in a source package. This one is
  a bit more subtle. For example, you might put an intry in this table to
  indicate that a bug "victimises" a source package. In other words, the
  bug itself does not appear in this sourcepackage, but the functionality
  of the sourcepackage is somehow impacted by the bug.
*/
CREATE TABLE Bug_Sourcepackage_Relationship (
  bug                integer NOT NULL REFERENCES Bug,
  sourcepackage      integer NOT NULL REFERENCES Sourcepackage,
  label              integer NOT NULL REFERENCES Label
);



/*
  ProductBugStatus
  The status of a bug with regard to a product. This is different
  to the status on a specific release, because it includes the concept
  of workflow or prognosis ("what we intend to do with this bug") while
  the release bug status is static ("is the bug present or not").
*/
CREATE TABLE ProductBugStatus (
  bug                integer NOT NULL REFERENCES Bug,
  product            integer NOT NULL REFERENCES Sourcepackage,
  bugstatus          integer NOT NULL REFERENCES Label,
  binarypackagename  text,
  wontfix            boolean NOT NULL,
  PRIMARY KEY ( bug, product )
);



/*
  BugActivity
  A log of all the things that have happened to a bug, as Dave wants
  to keep track of it.
*/
CREATE TABLE BugActivity (
  bug           integer NOT NULL REFERENCES Bug,
  activitydate  timestamp NOT NULL,
  person        integer NOT NULL,
  whatchanged   text NOT NULL,
  oldvalue      text NOT NULL,
  newvalue      text NOT NULL,
  message       text NOT NULL
);
-- XXX this does not have a primary key, theory says it needs one!




/*
  BugRef
  A table of external references for a bug, that are NOT remote
  bug system references, except where the remote bug system is
  not supported by the BugWatch table.
*/
CREATE TABLE BugRef (
  bugref      serial PRIMARY KEY,
  bug         integer NOT NULL REFERENCES Bug,
  bugreftype  integer NOT NULL REFERENCES Label,
  data        text NOT NULL,
  description text NOT NULL,
  owner       integer NOT NULL REFERENCES Person
);



/*
  BugSystemType
  This is a table of bug tracking system types. We don't have much
  version granularity (Bugzilla 2.15 is treated the same as Bugzilla 2.17
  unless you create them as two separate bug system types). This table is
  used by the BugSystem table to indicate the type of a remote bug system.
*/
CREATE TABLE BugSystemType (
  bugsystemtype   serial PRIMARY KEY,
  title           text NOT NULL,
  description     text NOT NULL,
  homepage        text,
  product         integer REFERENCES Product, -- A Soyuz Product if it exists
  owner           integer NOT NULL REFERENCES Person -- who knows most about these
);
/*
INSERT INTO BugSystemType VALUES ( 1, "Bugzilla", "Dave Miller's Labour of Love, the Godfather of Open Source project issue tracking.", "http://www.bugzilla.org", NULL, 2 );
INSERT INTO BugSystemType VALUES ( 2, "DebBugs", "The Debian bug tracking system, ugly as sin but fast and productive as a rabbit in high heels.", "http://bugs.debian.org", NULL, 3 );
INSERT INTO BugSystemType VALUES ( 3, "RoundUp", "Python-based open source bug tracking system with an elegant design and reputation for cleanliness and usability.", NULL, 4 );
*/


/*
  BugSystem
  A table of remote bug systems (for example, Debian's DebBugs, and
  Mozilla's Bugzilla, and SourceForge's tracker...). The baseurl is the
  top of the bug system's tree, from which the URL to a given bug
  status can be determined.
*/
CREATE TABLE BugSystem (
  bugsystem        serial PRIMARY KEY,
  bugsystemtype    integer NOT NULL REFERENCES BugSystemType,
  name             text NOT NULL,
  description      text NOT NULL,
  baseurl          text NOT NULL,
  owner            integer NOT NULL REFERENCES Person
);



/*
  BugWatch
  This is a table of bugs in remote bug systems (for example, upstream
  bugzilla's) which we want to monitor for status changes.
*/
CREATE TABLE BugWatch (
  bugwatch         serial PRIMARY KEY,
  bugsystem        integer NOT NULL REFERENCES BugSystem,
  remotebug        text NOT NULL, -- unique identifier of bug in that system
  remotestatus     text NOT NULL, -- textual representation of status
  lastchanged      timestamp NOT NULL,
  lastchecked      timestamp NOT NULL,
  owner            integer NOT NULL REFERENCES Person,
  datecreated      timestamp NOT NULL
);




/*
  BugAttachment
  A table of attachments to bugs. These are typically patches, screenshots,
  mockups, or other documents.
*/
CREATE TABLE BugAttachment (
  bugattachment   serial PRIMARY KEY,
  owner           integer NOT NULL REFERENCES Person,
  content         text NOT NULL,
  title           text NOT NULL,
  description     text NOT NULL,
  mimetype        text,
  replaces        integer REFERENCES BugAttachment
);



/*
  BugAttachment_Relationship
  A link between bug and attachment that carries some type
  of relationship.
*/
CREATE TABLE BugAttachment_Relationship (
  bug            integer NOT NULL REFERENCES Bug,
  bugattachment  integer NOT NULL REFERENCES BugAttachment,
  label          integer NOT NULL REFERENCES Label,
  PRIMARY KEY ( bug, bugattachment )
);



/*
  BugLabel
  Allows us to attache arbitrary metadata to a bug.
*/
CREATE TABLE BugLabel (
  bug       integer NOT NULL REFERENCES Bug,
  label     integer NOT NULL REFERENCES Label,
  PRIMARY KEY ( bug, label )
);




/*
  Bug_Relationship
  The relationship between two bugs, with a label.
*/
CREATE TABLE Bug_Relationship (
  src        integer NOT NULL REFERENCES Bug,
  dst        integer NOT NULL REFERENCES Bug,
  label      integer NOT NULL REFERENCES Label
);




/*
  BugMessage
  A table of messages about bugs. Could be from the web
  forum, or from email, we don't care and treat them both
  equally. A message can apply to multiple forums.
*/
CREATE TABLE BugMessage (
  bugmessage           serial PRIMARY KEY,
  msgdate              timestamp NOT NULL,
  message              text NOT NULL, -- the message or full email with headers
  person               int REFERENCES Person, -- NULL if we don't know it
  senderemail          text, -- NULL if this came through the web
  parent               int REFERENCES BugMessage, -- gives us threading
  distribution         int REFERENCES Distribution,
  rfc822msgid          text
);



/*
  BugMessageSighting
*/
CREATE TABLE BugMessageSighting (
  bug        integer NOT NULL REFERENCES Bug,
  bugmessage integer NOT NULL REFERENCES BugMessage
);