~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
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
-- Generated Tue Dec  6 20:57:32 2011 UTC

SET client_min_messages TO ERROR;
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

CREATE SCHEMA todrop;


CREATE SCHEMA ts2;


CREATE PROCEDURAL LANGUAGE plpgsql;


CREATE PROCEDURAL LANGUAGE plpythonu;


SET search_path = public, pg_catalog;

CREATE TYPE debversion;


CREATE FUNCTION debversionin(cstring) RETURNS debversion
    LANGUAGE internal IMMUTABLE STRICT
    AS $$textin$$;


CREATE FUNCTION debversionout(debversion) RETURNS cstring
    LANGUAGE internal IMMUTABLE STRICT
    AS $$textout$$;


CREATE FUNCTION debversionrecv(internal) RETURNS debversion
    LANGUAGE internal STABLE STRICT
    AS $$textrecv$$;


CREATE FUNCTION debversionsend(debversion) RETURNS bytea
    LANGUAGE internal STABLE STRICT
    AS $$textsend$$;


CREATE TYPE debversion (
    INTERNALLENGTH = variable,
    INPUT = debversionin,
    OUTPUT = debversionout,
    RECEIVE = debversionrecv,
    SEND = debversionsend,
    CATEGORY = 'S',
    ALIGNMENT = int4,
    STORAGE = extended
);


COMMENT ON TYPE debversion IS 'Debian package version number';


CREATE TYPE pgstattuple_type AS (
	table_len bigint,
	tuple_count bigint,
	tuple_len bigint,
	tuple_percent double precision,
	dead_tuple_count bigint,
	dead_tuple_len bigint,
	dead_tuple_percent double precision,
	free_space bigint,
	free_percent double precision
);


SET search_path = ts2, pg_catalog;

CREATE DOMAIN gtsq AS text;


CREATE DOMAIN gtsvector AS pg_catalog.gtsvector;


CREATE TYPE statinfo AS (
	word text,
	ndoc integer,
	nentry integer
);


CREATE TYPE tokenout AS (
	tokid integer,
	token text
);


CREATE TYPE tokentype AS (
	tokid integer,
	alias text,
	descr text
);


CREATE TYPE tsdebug AS (
	ts_name text,
	tok_type text,
	description text,
	token text,
	dict_name text[],
	tsvector pg_catalog.tsvector
);


CREATE DOMAIN tsquery AS pg_catalog.tsquery;


CREATE DOMAIN tsvector AS pg_catalog.tsvector;


SET search_path = public, pg_catalog;

CREATE FUNCTION activity() RETURNS SETOF pg_stat_activity
    LANGUAGE sql SECURITY DEFINER
    SET search_path TO public
    AS $$
    SELECT
        datid, datname, procpid, usesysid, usename,
        CASE
            WHEN current_query LIKE '<IDLE>%'
                OR current_query LIKE 'autovacuum:%'
                THEN current_query
            ELSE
                '<HIDDEN>'
        END AS current_query,
        waiting, xact_start, query_start,
        backend_start, client_addr, client_port
    FROM pg_catalog.pg_stat_activity;
$$;


COMMENT ON FUNCTION activity() IS 'SECURITY DEFINER wrapper around pg_stat_activity allowing unprivileged users to access most of its information.';


CREATE FUNCTION add_test_openid_identifier(account_ integer) RETURNS boolean
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    -- The generated OpenIdIdentifier is not a valid OpenId Identity URL
    -- and does not match tokens generated by the Canonical SSO. They
    -- are only useful to the test suite, and access to this stored
    -- procedure on production does not allow you to compromise
    -- accounts.
    INSERT INTO OpenIdIdentifier (identifier, account)
    VALUES ('test' || CAST(account_ AS text), account_);
    RETURN TRUE;
EXCEPTION
    WHEN unique_violation THEN
        RETURN FALSE;
END;
$$;


COMMENT ON FUNCTION add_test_openid_identifier(account_ integer) IS 'Add an OpenIdIdentifier to an account that can be used to login in the test environment. These identifiers are not usable on production or staging.';


CREATE FUNCTION assert_patch_applied(major integer, minor integer, patch integer) RETURNS boolean
    LANGUAGE plpythonu STABLE
    AS $$
    rv = plpy.execute("""
        SELECT * FROM LaunchpadDatabaseRevision
        WHERE major=%d AND minor=%d AND patch=%d
        """ % (major, minor, patch))
    if len(rv) == 0:
        raise Exception(
            'patch-%d-%02d-%d not applied.' % (major, minor, patch))
    else:
        return True
$$;


COMMENT ON FUNCTION assert_patch_applied(major integer, minor integer, patch integer) IS 'Raise an exception if the given database patch has not been applied.';


CREATE FUNCTION bug_maintain_bug_summary() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    -- There is no INSERT logic, as a bug will not have any summary
    -- information until BugTask rows have been attached.
    IF TG_OP = 'UPDATE' THEN
        IF OLD.duplicateof IS DISTINCT FROM NEW.duplicateof
            OR OLD.private IS DISTINCT FROM NEW.private
            OR (OLD.latest_patch_uploaded IS NULL)
                <> (NEW.latest_patch_uploaded IS NULL) THEN
            PERFORM unsummarise_bug(OLD);
            PERFORM summarise_bug(NEW);
        END IF;

    ELSIF TG_OP = 'DELETE' THEN
        PERFORM unsummarise_bug(OLD);
    END IF;

    PERFORM bug_summary_flush_temp_journal();
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION bug_maintain_bug_summary() IS 'AFTER trigger on bug maintaining the bugs summaries in bugsummary.';


CREATE FUNCTION valid_bug_name(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $_$
    import re
    name = args[0]
    pat = r"^[a-z][a-z0-9+\.\-]+$"
    if re.match(pat, name):
        return 1
    return 0
$_$;


COMMENT ON FUNCTION valid_bug_name(text) IS 'validate a bug name

    As per valid_name, except numeric-only names are not allowed (including
    names that look like floats).';


SET default_tablespace = '';

SET default_with_oids = false;

CREATE TABLE bug (
    id integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    name text,
    title text NOT NULL,
    description text NOT NULL,
    owner integer NOT NULL,
    duplicateof integer,
    fti ts2.tsvector,
    private boolean DEFAULT false NOT NULL,
    security_related boolean DEFAULT false NOT NULL,
    date_last_updated timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_made_private timestamp without time zone,
    who_made_private integer,
    date_last_message timestamp without time zone,
    number_of_duplicates integer DEFAULT 0 NOT NULL,
    message_count integer DEFAULT 0 NOT NULL,
    users_affected_count integer DEFAULT 0,
    users_unaffected_count integer DEFAULT 0,
    heat integer DEFAULT 0 NOT NULL,
    heat_last_updated timestamp without time zone,
    latest_patch_uploaded timestamp without time zone,
    access_policy integer,
    CONSTRAINT notduplicateofself CHECK ((NOT (id = duplicateof))),
    CONSTRAINT sane_description CHECK (((ltrim(description) <> ''::text) AND (char_length(description) <= 50000))),
    CONSTRAINT valid_bug_name CHECK (valid_bug_name(name))
);


COMMENT ON TABLE bug IS 'A software bug that requires fixing. This particular bug may be linked to one or more products or source packages to identify the location(s) that this bug is found.';


COMMENT ON COLUMN bug.name IS 'A lowercase name uniquely identifying the bug';


COMMENT ON COLUMN bug.description IS 'A detailed description of the bug. Initially this will be set to the contents of the initial email or bug filing comment, but later it can be edited to give a more accurate description of the bug itself rather than the symptoms observed by the reporter.';


COMMENT ON COLUMN bug.private IS 'Is this bug private? If so, only explicit subscribers will be able to see it';


COMMENT ON COLUMN bug.security_related IS 'Is this bug a security issue?';


COMMENT ON COLUMN bug.date_last_message IS 'When the last BugMessage was attached to this Bug. Maintained by a trigger on the BugMessage table.';


COMMENT ON COLUMN bug.number_of_duplicates IS 'The number of bugs marked as duplicates of this bug, populated by a trigger after setting the duplicateof of bugs.';


COMMENT ON COLUMN bug.message_count IS 'The number of messages (currently just comments) on this bugbug, maintained by the set_bug_message_count_t trigger.';


COMMENT ON COLUMN bug.users_affected_count IS 'The number of users affected by this bug, maintained by the set_bug_users_affected_count_t trigger.';


COMMENT ON COLUMN bug.heat IS 'The relevance of this bug. This value is computed periodically using bug_affects_person and other bug values.';


COMMENT ON COLUMN bug.heat_last_updated IS 'The time this bug''s heat was last updated, or NULL if the heat has never yet been updated.';


COMMENT ON COLUMN bug.latest_patch_uploaded IS 'The time when the most recent patch has been attached to this bug or NULL if no patches are attached';


CREATE FUNCTION bug_row(bug_id integer) RETURNS bug
    LANGUAGE sql STABLE
    AS $_$
    SELECT * FROM Bug WHERE id=$1;
$_$;


COMMENT ON FUNCTION bug_row(bug_id integer) IS 'Helper for manually testing functions requiring a bug row as input. eg. SELECT * FROM bugsummary_tags(bug_row(1))';


CREATE TABLE bugsummary (
    id integer NOT NULL,
    count integer DEFAULT 0 NOT NULL,
    product integer,
    productseries integer,
    distribution integer,
    distroseries integer,
    sourcepackagename integer,
    viewed_by integer,
    tag text,
    status integer NOT NULL,
    milestone integer,
    importance integer NOT NULL,
    has_patch boolean NOT NULL,
    fixed_upstream boolean NOT NULL,
    CONSTRAINT bugtask_assignment_checks CHECK (CASE WHEN (product IS NOT NULL) THEN ((((productseries IS NULL) AND (distribution IS NULL)) AND (distroseries IS NULL)) AND (sourcepackagename IS NULL)) WHEN (productseries IS NOT NULL) THEN (((distribution IS NULL) AND (distroseries IS NULL)) AND (sourcepackagename IS NULL)) WHEN (distribution IS NOT NULL) THEN (distroseries IS NULL) WHEN (distroseries IS NOT NULL) THEN true ELSE false END)
);


CREATE FUNCTION bug_summary_dec(bugsummary) RETURNS void
    LANGUAGE sql
    AS $_$
    -- We own the row reference, so in the absence of bugs this cannot
    -- fail - just decrement the row.
    UPDATE BugSummary SET count = count + $1.count
    WHERE
        ((product IS NULL AND $1.product IS NULL)
            OR product = $1.product)
        AND ((productseries IS NULL AND $1.productseries IS NULL)
            OR productseries = $1.productseries)
        AND ((distribution IS NULL AND $1.distribution IS NULL)
            OR distribution = $1.distribution)
        AND ((distroseries IS NULL AND $1.distroseries IS NULL)
            OR distroseries = $1.distroseries)
        AND ((sourcepackagename IS NULL AND $1.sourcepackagename IS NULL)
            OR sourcepackagename = $1.sourcepackagename)
        AND ((viewed_by IS NULL AND $1.viewed_by IS NULL)
            OR viewed_by = $1.viewed_by)
        AND ((tag IS NULL AND $1.tag IS NULL)
            OR tag = $1.tag)
        AND status = $1.status
        AND ((milestone IS NULL AND $1.milestone IS NULL)
            OR milestone = $1.milestone)
        AND importance = $1.importance
        AND has_patch = $1.has_patch
        AND fixed_upstream = $1.fixed_upstream;
$_$;


COMMENT ON FUNCTION bug_summary_dec(bugsummary) IS 'UPSERT into bugsummary incrementing one row';


CREATE FUNCTION bug_summary_flush_temp_journal() RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE
    d bugsummary%ROWTYPE;
BEGIN
    -- may get called even though no summaries were made (for simplicity in the
    -- callers)
    PERFORM ensure_bugsummary_temp_journal();
    FOR d IN SELECT * FROM bugsummary_temp_journal LOOP
        PERFORM bugsummary_journal_ins(d);
    END LOOP;
    TRUNCATE bugsummary_temp_journal;
END;
$$;


COMMENT ON FUNCTION bug_summary_flush_temp_journal() IS 'flush the temporary bugsummary journal into the bugsummary table';


CREATE FUNCTION bug_summary_inc(d bugsummary) RETURNS void
    LANGUAGE plpgsql
    AS $_$
BEGIN
    -- Shameless adaption from postgresql manual
    LOOP
        -- first try to update the row
        UPDATE BugSummary SET count = count + d.count
        WHERE
            ((product IS NULL AND $1.product IS NULL)
                OR product = $1.product)
            AND ((productseries IS NULL AND $1.productseries IS NULL)
                OR productseries = $1.productseries)
            AND ((distribution IS NULL AND $1.distribution IS NULL)
                OR distribution = $1.distribution)
            AND ((distroseries IS NULL AND $1.distroseries IS NULL)
                OR distroseries = $1.distroseries)
            AND ((sourcepackagename IS NULL AND $1.sourcepackagename IS NULL)
                OR sourcepackagename = $1.sourcepackagename)
            AND ((viewed_by IS NULL AND $1.viewed_by IS NULL)
                OR viewed_by = $1.viewed_by)
            AND ((tag IS NULL AND $1.tag IS NULL)
                OR tag = $1.tag)
            AND status = $1.status
            AND ((milestone IS NULL AND $1.milestone IS NULL)
                OR milestone = $1.milestone)
            AND importance = $1.importance
            AND has_patch = $1.has_patch
            AND fixed_upstream = $1.fixed_upstream;
        IF found THEN
            RETURN;
        END IF;
        -- not there, so try to insert the key
        -- if someone else inserts the same key concurrently,
        -- we could get a unique-key failure
        BEGIN
            INSERT INTO BugSummary(
                count, product, productseries, distribution,
                distroseries, sourcepackagename, viewed_by, tag,
                status, milestone,
                importance, has_patch, fixed_upstream)
            VALUES (
                d.count, d.product, d.productseries, d.distribution,
                d.distroseries, d.sourcepackagename, d.viewed_by, d.tag,
                d.status, d.milestone,
                d.importance, d.has_patch, d.fixed_upstream);
            RETURN;
        EXCEPTION WHEN unique_violation THEN
            -- do nothing, and loop to try the UPDATE again
        END;
    END LOOP;
END;
$_$;


COMMENT ON FUNCTION bug_summary_inc(d bugsummary) IS 'UPSERT into bugsummary incrementing one row';


CREATE FUNCTION bug_summary_temp_journal_ins(d bugsummary) RETURNS void
    LANGUAGE plpgsql
    AS $$
BEGIN
    INSERT INTO BugSummary_Temp_Journal(
        count, product, productseries, distribution,
        distroseries, sourcepackagename, viewed_by, tag,
        status, milestone, importance, has_patch, fixed_upstream)
    VALUES (
        d.count, d.product, d.productseries, d.distribution,
        d.distroseries, d.sourcepackagename, d.viewed_by, d.tag,
        d.status, d.milestone, d.importance, d.has_patch, d.fixed_upstream);
    RETURN;
END;
$$;


COMMENT ON FUNCTION bug_summary_temp_journal_ins(d bugsummary) IS 'Insert a BugSummary into the temporary journal';


CREATE FUNCTION bug_update_heat_copy_to_bugtask() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF NEW.heat != OLD.heat THEN
        UPDATE bugtask SET heat=NEW.heat WHERE bugtask.bug=NEW.id;
    END IF;
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION bug_update_heat_copy_to_bugtask() IS 'Copies bug heat to bugtasks when the bug is changed. Runs on UPDATE only because INSERTs do not have bugtasks at the point of insertion.';


CREATE FUNCTION bug_update_latest_patch_uploaded(integer) RETURNS void
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $_$
BEGIN
    UPDATE bug SET latest_patch_uploaded =
        (SELECT max(message.datecreated)
            FROM message, bugattachment
            WHERE bugattachment.message=message.id AND
                bugattachment.bug=$1 AND
                bugattachment.type=1)
        WHERE bug.id=$1;
END;
$_$;


CREATE FUNCTION bug_update_latest_patch_uploaded_on_delete() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    PERFORM bug_update_latest_patch_uploaded(OLD.bug);
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


CREATE FUNCTION bug_update_latest_patch_uploaded_on_insert_update() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    PERFORM bug_update_latest_patch_uploaded(NEW.bug);
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


CREATE FUNCTION bugmessage_copy_owner_from_message() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF TG_OP = 'INSERT' THEN
        IF NEW.owner is NULL THEN
            UPDATE BugMessage
            SET owner = Message.owner FROM
            Message WHERE
            Message.id = NEW.message AND
            BugMessage.id = NEW.id;
        END IF;
    ELSIF NEW.message != OLD.message THEN
        UPDATE BugMessage
        SET owner = Message.owner FROM
        Message WHERE
        Message.id = NEW.message AND
        BugMessage.id = NEW.id;
    END IF;
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION bugmessage_copy_owner_from_message() IS 'Copies the message owner into bugmessage when bugmessage changes.';


CREATE FUNCTION bugsubscription_maintain_bug_summary() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    -- This trigger only works if we are inserting, updating or deleting
    -- a single row per statement.
    IF TG_OP = 'INSERT' THEN
        IF NOT (bug_row(NEW.bug)).private THEN
            -- Public subscriptions are not aggregated.
            RETURN NEW;
        END IF;
        IF TG_WHEN = 'BEFORE' THEN
            PERFORM unsummarise_bug(bug_row(NEW.bug));
        ELSE
            PERFORM summarise_bug(bug_row(NEW.bug));
        END IF;
        PERFORM bug_summary_flush_temp_journal();
        RETURN NEW;
    ELSIF TG_OP = 'DELETE' THEN
        IF NOT (bug_row(OLD.bug)).private THEN
            -- Public subscriptions are not aggregated.
            RETURN OLD;
        END IF;
        IF TG_WHEN = 'BEFORE' THEN
            PERFORM unsummarise_bug(bug_row(OLD.bug));
        ELSE
            PERFORM summarise_bug(bug_row(OLD.bug));
        END IF;
        PERFORM bug_summary_flush_temp_journal();
        RETURN OLD;
    ELSE
        IF (OLD.person IS DISTINCT FROM NEW.person
            OR OLD.bug IS DISTINCT FROM NEW.bug) THEN
            IF TG_WHEN = 'BEFORE' THEN
                IF (bug_row(OLD.bug)).private THEN
                    -- Public subscriptions are not aggregated.
                    PERFORM unsummarise_bug(bug_row(OLD.bug));
                END IF;
                IF OLD.bug <> NEW.bug AND (bug_row(NEW.bug)).private THEN
                    -- Public subscriptions are not aggregated.
                    PERFORM unsummarise_bug(bug_row(NEW.bug));
                END IF;
            ELSE
                IF (bug_row(OLD.bug)).private THEN
                    -- Public subscriptions are not aggregated.
                    PERFORM summarise_bug(bug_row(OLD.bug));
                END IF;
                IF OLD.bug <> NEW.bug AND (bug_row(NEW.bug)).private THEN
                    -- Public subscriptions are not aggregated.
                    PERFORM summarise_bug(bug_row(NEW.bug));
                END IF;
            END IF;
        END IF;
        PERFORM bug_summary_flush_temp_journal();
        RETURN NEW;
    END IF;
END;
$$;


COMMENT ON FUNCTION bugsubscription_maintain_bug_summary() IS 'AFTER trigger on bugsubscription maintaining the bugs summaries in bugsummary.';


CREATE FUNCTION bugsummary_journal_ins(d bugsummary) RETURNS void
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF d.count <> 0 THEN
        INSERT INTO BugSummaryJournal (
            count, product, productseries, distribution,
            distroseries, sourcepackagename, viewed_by, tag,
            status, milestone,
            importance, has_patch, fixed_upstream)
        VALUES (
            d.count, d.product, d.productseries, d.distribution,
            d.distroseries, d.sourcepackagename, d.viewed_by, d.tag,
            d.status, d.milestone,
            d.importance, d.has_patch, d.fixed_upstream);
    END IF;
END;
$$;


COMMENT ON FUNCTION bugsummary_journal_ins(d bugsummary) IS 'Add an entry into BugSummaryJournal';


CREATE FUNCTION bugsummary_locations(bug_row bug) RETURNS SETOF bugsummary
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF BUG_ROW.duplicateof IS NOT NULL THEN
        RETURN;
    END IF;
    RETURN QUERY
        SELECT
            CAST(NULL AS integer) AS id,
            CAST(1 AS integer) AS count,
            product, productseries, distribution, distroseries,
            sourcepackagename, person AS viewed_by, tag, status, milestone,
            importance,
            BUG_ROW.latest_patch_uploaded IS NOT NULL AS has_patch,
            (EXISTS (
                SELECT TRUE FROM BugTask AS RBT
                WHERE
                    RBT.bug = tasks.bug
                    -- This would just be 'RBT.id <> tasks.id', except
                    -- that the records from tasks are summaries and not
                    -- real bugtasks, and do not have an id.
                    AND (RBT.product IS DISTINCT FROM tasks.product
                        OR RBT.productseries
                            IS DISTINCT FROM tasks.productseries
                        OR RBT.distribution IS DISTINCT FROM tasks.distribution
                        OR RBT.distroseries IS DISTINCT FROM tasks.distroseries
                        OR RBT.sourcepackagename
                            IS DISTINCT FROM tasks.sourcepackagename)
                    -- Flagged as INVALID, FIXCOMMITTED or FIXRELEASED
                    -- via a bugwatch, or FIXCOMMITTED or FIXRELEASED on
                    -- the product.
                    AND ((bugwatch IS NOT NULL AND status IN (17, 25, 30))
                        OR (bugwatch IS NULL AND product IS NOT NULL
                            AND status IN (25, 30))))
                )::boolean AS fixed_upstream
        FROM bugsummary_tasks(BUG_ROW) AS tasks
        JOIN bugsummary_tags(BUG_ROW) AS bug_tags ON TRUE
        LEFT OUTER JOIN bugsummary_viewers(BUG_ROW) AS bug_viewers ON TRUE;
END;
$$;


COMMENT ON FUNCTION bugsummary_locations(bug_row bug) IS 'Calculate what BugSummary rows should exist for a given Bug.';


CREATE FUNCTION bugsummary_rollup_journal(batchsize integer DEFAULT NULL::integer) RETURNS void
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
DECLARE
    d bugsummary%ROWTYPE;
    max_id integer;
BEGIN
    -- Lock so we don't content with other invokations of this
    -- function. We can happily lock the BugSummary table for writes
    -- as this function is the only thing that updates that table.
    -- BugSummaryJournal remains unlocked so nothing should be blocked.
    LOCK TABLE BugSummary IN ROW EXCLUSIVE MODE;

    IF batchsize IS NULL THEN
        SELECT MAX(id) INTO max_id FROM BugSummaryJournal;
    ELSE
        SELECT MAX(id) INTO max_id FROM (
            SELECT id FROM BugSummaryJournal ORDER BY id LIMIT batchsize
            ) AS Whatever;
    END IF;

    FOR d IN
        SELECT
            NULL as id,
            SUM(count),
            product,
            productseries,
            distribution,
            distroseries,
            sourcepackagename,
            viewed_by,
            tag,
            status,
            milestone,
            importance,
            has_patch,
            fixed_upstream
        FROM BugSummaryJournal
        WHERE id <= max_id
        GROUP BY
            product, productseries, distribution, distroseries,
            sourcepackagename, viewed_by, tag, status, milestone,
            importance, has_patch, fixed_upstream
        HAVING sum(count) <> 0
    LOOP
        IF d.count < 0 THEN
            PERFORM bug_summary_dec(d);
        ELSIF d.count > 0 THEN
            PERFORM bug_summary_inc(d);
        END IF;
    END LOOP;

    -- Clean out any counts we reduced to 0.
    DELETE FROM BugSummary WHERE count=0;
    -- Clean out the journal entries we have handled.
    DELETE FROM BugSummaryJournal WHERE id <= max_id;
END;
$$;


COMMENT ON FUNCTION bugsummary_rollup_journal(batchsize integer) IS 'Collate and migrate rows from BugSummaryJournal to BugSummary';


CREATE FUNCTION valid_name(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $$
    import re
    name = args[0]
    pat = r"^[a-z0-9][a-z0-9\+\.\-]*\Z"
    if re.match(pat, name):
        return 1
    return 0
$$;


COMMENT ON FUNCTION valid_name(text) IS 'validate a name.

    Names must contain only lowercase letters, numbers, ., & -. They
    must start with an alphanumeric. They are ASCII only. Names are useful
    for mneumonic identifiers such as nicknames and as URL components.
    This specification is the same as the Debian product naming policy.

    Note that a valid name might be all integers, so there is a possible
    namespace conflict if URL traversal is possible by name as well as id.';


CREATE TABLE bugtag (
    id integer NOT NULL,
    bug integer NOT NULL,
    tag text NOT NULL,
    CONSTRAINT valid_tag CHECK (valid_name(tag))
);


COMMENT ON TABLE bugtag IS 'Attaches simple text tags to a bug.';


COMMENT ON COLUMN bugtag.bug IS 'The bug the tags is attached to.';


COMMENT ON COLUMN bugtag.tag IS 'The text representation of the tag.';


CREATE FUNCTION bugsummary_tags(bug_row bug) RETURNS SETOF bugtag
    LANGUAGE sql STABLE
    AS $_$
    SELECT * FROM BugTag WHERE BugTag.bug = $1.id
    UNION ALL
    SELECT NULL::integer, $1.id, NULL::text;
$_$;


COMMENT ON FUNCTION bugsummary_tags(bug_row bug) IS 'Return (bug, tag) for all tags + (bug, NULL::text)';


CREATE TABLE bugtask (
    id integer NOT NULL,
    bug integer NOT NULL,
    product integer,
    distribution integer,
    distroseries integer,
    sourcepackagename integer,
    binarypackagename integer,
    status integer NOT NULL,
    importance integer DEFAULT 5 NOT NULL,
    assignee integer,
    date_assigned timestamp without time zone,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone),
    owner integer NOT NULL,
    milestone integer,
    bugwatch integer,
    fti ts2.tsvector,
    targetnamecache text,
    date_confirmed timestamp without time zone,
    date_inprogress timestamp without time zone,
    date_closed timestamp without time zone,
    productseries integer,
    date_incomplete timestamp without time zone,
    date_left_new timestamp without time zone,
    date_triaged timestamp without time zone,
    date_fix_committed timestamp without time zone,
    date_fix_released timestamp without time zone,
    date_left_closed timestamp without time zone,
    heat_rank integer DEFAULT 0 NOT NULL,
    date_milestone_set timestamp without time zone,
    heat integer DEFAULT 0 NOT NULL,
    CONSTRAINT bugtask_assignment_checks CHECK (CASE WHEN (product IS NOT NULL) THEN ((((productseries IS NULL) AND (distribution IS NULL)) AND (distroseries IS NULL)) AND (sourcepackagename IS NULL)) WHEN (productseries IS NOT NULL) THEN (((distribution IS NULL) AND (distroseries IS NULL)) AND (sourcepackagename IS NULL)) WHEN (distribution IS NOT NULL) THEN (distroseries IS NULL) WHEN (distroseries IS NOT NULL) THEN true ELSE false END)
);


COMMENT ON TABLE bugtask IS 'Links a given Bug to a particular (sourcepackagename, distro) or product.';


COMMENT ON COLUMN bugtask.bug IS 'The bug that is assigned to this (sourcepackagename, distro) or product.';


COMMENT ON COLUMN bugtask.product IS 'The product in which this bug shows up.';


COMMENT ON COLUMN bugtask.distribution IS 'The distro of the named sourcepackage.';


COMMENT ON COLUMN bugtask.sourcepackagename IS 'The name of the sourcepackage in which this bug shows up.';


COMMENT ON COLUMN bugtask.binarypackagename IS 'The name of the binary package built from the source package. This column may only contain a value if this bug task is linked to a sourcepackage (not a product)';


COMMENT ON COLUMN bugtask.status IS 'The general health of the bug, e.g. Accepted, Rejected, etc.';


COMMENT ON COLUMN bugtask.importance IS 'The importance of fixing the bug.';


COMMENT ON COLUMN bugtask.assignee IS 'The person who has been assigned to fix this bug in this product or (sourcepackagename, distro)';


COMMENT ON COLUMN bugtask.date_assigned IS 'The date on which the bug in this (sourcepackagename, distro) or product was assigned to someone to fix';


COMMENT ON COLUMN bugtask.datecreated IS 'A timestamp for the creation of this bug assignment. Note that this is not the date the bug was created (though it might be), it''s the date the bug was assigned to this product, which could have come later.';


COMMENT ON COLUMN bugtask.milestone IS 'A way to mark a bug for grouping purposes, e.g. to say it needs to be fixed by version 1.2';


COMMENT ON COLUMN bugtask.bugwatch IS 'This column allows us to link a bug
task to a bug watch. In other words, we are connecting the state of the task
to the state of the bug in a different bug tracking system. To the best of
our ability we''ll try and keep the bug task syncronised with the state of
the remote bug watch.';


COMMENT ON COLUMN bugtask.targetnamecache IS 'A cached value of the target name of this bugtask, to make it easier to sort and search on the target name.';


COMMENT ON COLUMN bugtask.date_confirmed IS 'The date when this bug transitioned from an unconfirmed status to a confirmed one. If the state regresses to a one that logically occurs before Confirmed, e.g., Unconfirmed, this date is cleared.';


COMMENT ON COLUMN bugtask.date_inprogress IS 'The date on which this bug transitioned from not being in progress to a state >= In Progress. If the status moves back to a pre-In Progress state, this date is cleared';


COMMENT ON COLUMN bugtask.date_closed IS 'The date when this bug transitioned to a resolved state, e.g., Rejected, Fix Released, etc. If the state changes back to a pre-closed state, this date is cleared';


COMMENT ON COLUMN bugtask.productseries IS 'The product series to which the bug is targeted';


COMMENT ON COLUMN bugtask.date_left_new IS 'The date when this bug first transitioned out of the NEW status.';


COMMENT ON COLUMN bugtask.date_triaged IS 'The date when this bug transitioned to a status >= TRIAGED.';


COMMENT ON COLUMN bugtask.date_fix_committed IS 'The date when this bug transitioned to a status >= FIXCOMMITTED.';


COMMENT ON COLUMN bugtask.date_fix_released IS 'The date when this bug transitioned to a FIXRELEASED status.';


COMMENT ON COLUMN bugtask.date_left_closed IS 'The date when this bug last transitioned out of a CLOSED status.';


COMMENT ON COLUMN bugtask.heat_rank IS 'The heat bin in which this bugtask appears, as a value from the BugTaskHeatRank enumeration.';


COMMENT ON COLUMN bugtask.date_milestone_set IS 'The date when this bug was targed to the milestone that is currently set.';


CREATE FUNCTION bugsummary_tasks(bug_row bug) RETURNS SETOF bugtask
    LANGUAGE plpgsql STABLE
    AS $$
DECLARE
    bt bugtask%ROWTYPE;
    r record;
BEGIN
    bt.bug = BUG_ROW.id;

    -- One row only for each target permutation - need to ignore other fields
    -- like date last modified to deal with conjoined masters and multiple
    -- sourcepackage tasks in a distro.
    FOR r IN
        SELECT
            product, productseries, distribution, distroseries,
            sourcepackagename, status, milestone, importance, bugwatch
        FROM BugTask WHERE bug=BUG_ROW.id
        UNION -- Implicit DISTINCT
        SELECT
            product, productseries, distribution, distroseries,
            NULL, status, milestone, importance, bugwatch
        FROM BugTask WHERE bug=BUG_ROW.id AND sourcepackagename IS NOT NULL
    LOOP
        bt.product = r.product;
        bt.productseries = r.productseries;
        bt.distribution = r.distribution;
        bt.distroseries = r.distroseries;
        bt.sourcepackagename = r.sourcepackagename;
        bt.status = r.status;
        bt.milestone = r.milestone;
        bt.importance = r.importance;
        bt.bugwatch = r.bugwatch;
        RETURN NEXT bt;
    END LOOP;
END;
$$;


COMMENT ON FUNCTION bugsummary_tasks(bug_row bug) IS 'Return all tasks for the bug + all sourcepackagename tasks again with the sourcepackagename squashed';


CREATE TABLE bugsubscription (
    id integer NOT NULL,
    person integer NOT NULL,
    bug integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    subscribed_by integer NOT NULL,
    bug_notification_level integer DEFAULT 40 NOT NULL
);


COMMENT ON TABLE bugsubscription IS 'A subscription by a Person to a bug.';


COMMENT ON COLUMN bugsubscription.bug_notification_level IS 'The level of notifications which the Person will receive from this subscription.';


CREATE FUNCTION bugsummary_viewers(bug_row bug) RETURNS SETOF bugsubscription
    LANGUAGE sql STABLE
    AS $_$
    SELECT *
    FROM BugSubscription
    WHERE
        bugsubscription.bug=$1.id
        AND $1.private IS TRUE;
$_$;


COMMENT ON FUNCTION bugsummary_viewers(bug_row bug) IS 'Return (bug, viewer) for all viewers if private, nothing otherwise';


CREATE FUNCTION bugtag_maintain_bug_summary() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF TG_OP = 'INSERT' THEN
        IF TG_WHEN = 'BEFORE' THEN
            PERFORM unsummarise_bug(bug_row(NEW.bug));
        ELSE
            PERFORM summarise_bug(bug_row(NEW.bug));
        END IF;
        PERFORM bug_summary_flush_temp_journal();
        RETURN NEW;
    ELSIF TG_OP = 'DELETE' THEN
        IF TG_WHEN = 'BEFORE' THEN
            PERFORM unsummarise_bug(bug_row(OLD.bug));
        ELSE
            PERFORM summarise_bug(bug_row(OLD.bug));
        END IF;
        PERFORM bug_summary_flush_temp_journal();
        RETURN OLD;
    ELSE
        IF TG_WHEN = 'BEFORE' THEN
            PERFORM unsummarise_bug(bug_row(OLD.bug));
            IF OLD.bug <> NEW.bug THEN
                PERFORM unsummarise_bug(bug_row(NEW.bug));
            END IF;
        ELSE
            PERFORM summarise_bug(bug_row(OLD.bug));
            IF OLD.bug <> NEW.bug THEN
                PERFORM summarise_bug(bug_row(NEW.bug));
            END IF;
        END IF;
        PERFORM bug_summary_flush_temp_journal();
        RETURN NEW;
    END IF;
END;
$$;


COMMENT ON FUNCTION bugtag_maintain_bug_summary() IS 'AFTER trigger on bugtag maintaining the bugs summaries in bugsummary.';


CREATE FUNCTION bugtask_maintain_bug_summary() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    -- This trigger only works if we are inserting, updating or deleting
    -- a single row per statement.

    -- Unlike bug_maintain_bug_summary, this trigger does not have access
    -- to the old bug when invoked as an AFTER trigger. To work around this
    -- we install this trigger as both a BEFORE and an AFTER trigger.
    IF TG_OP = 'INSERT' THEN
        IF TG_WHEN = 'BEFORE' THEN
            PERFORM unsummarise_bug(bug_row(NEW.bug));
        ELSE
            PERFORM summarise_bug(bug_row(NEW.bug));
        END IF;
        PERFORM bug_summary_flush_temp_journal();
        RETURN NEW;

    ELSIF TG_OP = 'DELETE' THEN
        IF TG_WHEN = 'BEFORE' THEN
            PERFORM unsummarise_bug(bug_row(OLD.bug));
        ELSE
            PERFORM summarise_bug(bug_row(OLD.bug));
        END IF;
        PERFORM bug_summary_flush_temp_journal();
        RETURN OLD;

    ELSE
        IF (OLD.product IS DISTINCT FROM NEW.product
            OR OLD.productseries IS DISTINCT FROM NEW.productseries
            OR OLD.distribution IS DISTINCT FROM NEW.distribution
            OR OLD.distroseries IS DISTINCT FROM NEW.distroseries
            OR OLD.sourcepackagename IS DISTINCT FROM NEW.sourcepackagename
            OR OLD.status IS DISTINCT FROM NEW.status
            OR OLD.importance IS DISTINCT FROM NEW.importance
            OR OLD.bugwatch IS DISTINCT FROM NEW.bugwatch
            OR OLD.milestone IS DISTINCT FROM NEW.milestone) THEN

            IF TG_WHEN = 'BEFORE' THEN
                PERFORM unsummarise_bug(bug_row(OLD.bug));
                IF OLD.bug <> NEW.bug THEN
                    PERFORM unsummarise_bug(bug_row(NEW.bug));
                END IF;
            ELSE
                PERFORM summarise_bug(bug_row(OLD.bug));
                IF OLD.bug <> NEW.bug THEN
                    PERFORM summarise_bug(bug_row(NEW.bug));
                END IF;
            END IF;
        END IF;
        PERFORM bug_summary_flush_temp_journal();
        RETURN NEW;
    END IF;
END;
$$;


COMMENT ON FUNCTION bugtask_maintain_bug_summary() IS 'Both BEFORE & AFTER trigger on bugtask maintaining the bugs summaries in bugsummary.';


CREATE FUNCTION calculate_bug_heat(bug_id integer) RETURNS integer
    LANGUAGE plpythonu STABLE STRICT
    AS $$
    from datetime import datetime

    class BugHeatConstants:
        PRIVACY = 150
        SECURITY = 250
        DUPLICATE = 6
        AFFECTED_USER = 4
        SUBSCRIBER = 2

    def get_max_heat_for_bug(bug_id):
        results = plpy.execute("""
            SELECT MAX(
                GREATEST(Product.max_bug_heat,
                         DistributionSourcePackage.max_bug_heat))
                    AS max_heat
            FROM BugTask
            LEFT OUTER JOIN ProductSeries ON
                BugTask.productseries = ProductSeries.id
            LEFT OUTER JOIN Product ON (
                BugTask.product = Product.id
                OR ProductSeries.product = Product.id)
            LEFT OUTER JOIN DistroSeries ON
                BugTask.distroseries = DistroSeries.id
            LEFT OUTER JOIN Distribution ON (
                BugTask.distribution = Distribution.id
                OR DistroSeries.distribution = Distribution.id)
            LEFT OUTER JOIN DistributionSourcePackage ON (
                BugTask.sourcepackagename =
                    DistributionSourcePackage.sourcepackagename)
            WHERE
                BugTask.bug = %s""" % bug_id)

        return results[0]['max_heat']

    # It would be nice to be able to just SELECT * here, but we need the
    # timestamps to be in a format that datetime.fromtimestamp() will
    # understand.
    bug_data = plpy.execute("""
        SELECT
            duplicateof,
            private,
            security_related,
            number_of_duplicates,
            users_affected_count,
            EXTRACT(epoch from datecreated)
                AS timestamp_date_created,
            EXTRACT(epoch from date_last_updated)
                AS timestamp_date_last_updated,
            EXTRACT(epoch from date_last_message)
                AS timestamp_date_last_message
        FROM Bug WHERE id = %s""" % bug_id)

    if bug_data.nrows() == 0:
        raise Exception("Bug %s doesn't exist." % bug_id)

    bug = bug_data[0]
    if bug['duplicateof'] is not None:
        return None

    heat = {}
    heat['dupes'] = (
        BugHeatConstants.DUPLICATE * bug['number_of_duplicates'])
    heat['affected_users'] = (
        BugHeatConstants.AFFECTED_USER *
        bug['users_affected_count'])

    if bug['private']:
        heat['privacy'] = BugHeatConstants.PRIVACY
    if bug['security_related']:
        heat['security'] = BugHeatConstants.SECURITY

    # Get the heat from subscribers, both direct and via duplicates.
    subs_from_dupes = plpy.execute("""
        SELECT COUNT(DISTINCT BugSubscription.person) AS sub_count
        FROM BugSubscription, Bug
        WHERE Bug.id = BugSubscription.bug
            AND (Bug.id = %s OR Bug.duplicateof = %s)"""
        % (bug_id, bug_id))

    heat['subcribers'] = (
        BugHeatConstants.SUBSCRIBER
        * subs_from_dupes[0]['sub_count'])

    total_heat = sum(heat.values())

    # Bugs decay over time. Every day the bug isn't touched its heat
    # decreases by 1%.
    date_last_updated = datetime.fromtimestamp(
        bug['timestamp_date_last_updated'])
    days_since_last_update = (datetime.utcnow() - date_last_updated).days
    total_heat = int(total_heat * (0.99 ** days_since_last_update))

    if days_since_last_update > 0:
        # Bug heat increases by a quarter of the maximum bug heat
        # divided by the number of days since the bug's creation date.
        date_created = datetime.fromtimestamp(
            bug['timestamp_date_created'])

        if bug['timestamp_date_last_message'] is not None:
            date_last_message = datetime.fromtimestamp(
                bug['timestamp_date_last_message'])
            oldest_date = max(date_last_updated, date_last_message)
        else:
            date_last_message = None
            oldest_date = date_last_updated

        days_since_last_activity = (datetime.utcnow() - oldest_date).days
        days_since_created = (datetime.utcnow() - date_created).days
        max_heat = get_max_heat_for_bug(bug_id)
        if max_heat is not None and days_since_created > 0:
            total_heat = (
                total_heat + (max_heat * 0.25 / days_since_created))

    return int(total_heat)
$$;


CREATE FUNCTION cursor_fetch(cur refcursor, n integer) RETURNS SETOF record
    LANGUAGE plpgsql
    AS $$
DECLARE
    r record;
    count integer;
BEGIN
    FOR count IN 1..n LOOP
        FETCH FORWARD FROM cur INTO r;
        IF NOT FOUND THEN
            RETURN;
        END IF;
        RETURN NEXT r;
    END LOOP;
END;
$$;


COMMENT ON FUNCTION cursor_fetch(cur refcursor, n integer) IS 'Fetch the next n items from a cursor. Work around for not being able to use FETCH inside a SELECT statement.';


CREATE FUNCTION debversion(character) RETURNS debversion
    LANGUAGE internal IMMUTABLE STRICT
    AS $$rtrim1$$;


CREATE FUNCTION debversion_cmp(version1 debversion, version2 debversion) RETURNS integer
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/debversion', 'debversion_cmp';


COMMENT ON FUNCTION debversion_cmp(version1 debversion, version2 debversion) IS 'Compare Debian versions';


CREATE FUNCTION debversion_eq(version1 debversion, version2 debversion) RETURNS boolean
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/debversion', 'debversion_eq';


COMMENT ON FUNCTION debversion_eq(version1 debversion, version2 debversion) IS 'debversion equal';


CREATE FUNCTION debversion_ge(version1 debversion, version2 debversion) RETURNS boolean
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/debversion', 'debversion_ge';


COMMENT ON FUNCTION debversion_ge(version1 debversion, version2 debversion) IS 'debversion greater-than-or-equal';


CREATE FUNCTION debversion_gt(version1 debversion, version2 debversion) RETURNS boolean
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/debversion', 'debversion_gt';


COMMENT ON FUNCTION debversion_gt(version1 debversion, version2 debversion) IS 'debversion greater-than';


CREATE FUNCTION debversion_hash(debversion) RETURNS integer
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/debversion', 'debversion_hash';


CREATE FUNCTION debversion_larger(version1 debversion, version2 debversion) RETURNS debversion
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/debversion', 'debversion_larger';


CREATE FUNCTION debversion_le(version1 debversion, version2 debversion) RETURNS boolean
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/debversion', 'debversion_le';


COMMENT ON FUNCTION debversion_le(version1 debversion, version2 debversion) IS 'debversion less-than-or-equal';


CREATE FUNCTION debversion_lt(version1 debversion, version2 debversion) RETURNS boolean
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/debversion', 'debversion_lt';


COMMENT ON FUNCTION debversion_lt(version1 debversion, version2 debversion) IS 'debversion less-than';


CREATE FUNCTION debversion_ne(version1 debversion, version2 debversion) RETURNS boolean
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/debversion', 'debversion_ne';


COMMENT ON FUNCTION debversion_ne(version1 debversion, version2 debversion) IS 'debversion not equal';


CREATE FUNCTION debversion_smaller(version1 debversion, version2 debversion) RETURNS debversion
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/debversion', 'debversion_smaller';


CREATE FUNCTION debversion_sort_key(version text) RETURNS text
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $_$
    # If this method is altered, then any functional indexes using it
    # need to be rebuilt.
    import re

    VERRE = re.compile("(?:([0-9]+):)?(.+?)(?:-([^-]+))?$")

    MAP = "0123456789ABCDEFGHIJKLMNOPQRSTUV"

    epoch, version, release = VERRE.match(args[0]).groups()
    key = []
    for part, part_weight in ((epoch, 3000), (version, 2000), (release, 1000)):
        if not part:
            continue
        i = 0
        l = len(part)
        while i != l:
            c = part[i]
            if c.isdigit():
                key.append(part_weight)
                j = i
                while i != l and part[i].isdigit(): i += 1
                key.append(part_weight+int(part[j:i] or "0"))
            elif c == "~":
                key.append(0)
                i += 1
            elif c.isalpha():
                key.append(part_weight+ord(c))
                i += 1
            else:
                key.append(part_weight+256+ord(c))
                i += 1
        if not key or key[-1] != part_weight:
            key.append(part_weight)
            key.append(part_weight)
    key.append(1)

    # Encode our key and return it
    #
    result = []
    for value in key:
        if not value:
            result.append("000")
        else:
            element = []
            while value:
                element.insert(0, MAP[value & 0x1F])
                value >>= 5
            element_len = len(element)
            if element_len < 3:
                element.insert(0, "0"*(3-element_len))
            elif element_len == 3:
                pass
            elif element_len < 35:
                element.insert(0, MAP[element_len-4])
                element.insert(0, "X")
            elif element_len < 1027:
                element.insert(0, MAP[(element_len-4) & 0x1F])
                element.insert(0, MAP[(element_len-4) & 0x3E0])
                element.insert(0, "Y")
            else:
                raise ValueError("Number too large")
            result.extend(element)
    return "".join(result)
$_$;


COMMENT ON FUNCTION debversion_sort_key(version text) IS 'Return a string suitable for sorting debian version strings on';


CREATE FUNCTION ensure_bugsummary_temp_journal() RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE
BEGIN
    CREATE TEMPORARY TABLE bugsummary_temp_journal (
        LIKE bugsummary ) ON COMMIT DROP;
    ALTER TABLE bugsummary_temp_journal ALTER COLUMN id DROP NOT NULL;
EXCEPTION
    WHEN duplicate_table THEN
        NULL;
END;
$$;


COMMENT ON FUNCTION ensure_bugsummary_temp_journal() IS 'Create a temporary table bugsummary_temp_journal if it does not exist.';


CREATE FUNCTION generate_openid_identifier() RETURNS text
    LANGUAGE plpythonu
    AS $$
    from random import choice

    # Non display confusing characters.
    chars = '34678bcdefhkmnprstwxyzABCDEFGHJKLMNPQRTWXY'

    # Character length of tokens. Can be increased, decreased or even made
    # random - Launchpad does not care. 7 means it takes 40 bytes to store
    # a null-terminated Launchpad identity URL on the current domain name.
    length=7

    loop_count = 0
    while loop_count < 20000:
        # Generate a random openid_identifier
        oid = ''.join(choice(chars) for count in range(length))

        # Check if the oid is already in the db, although this is pretty
        # unlikely
        rv = plpy.execute("""
            SELECT COUNT(*) AS num FROM Account WHERE openid_identifier = '%s'
            """ % oid, 1)
        if rv[0]['num'] == 0:
            return oid
        loop_count += 1
        if loop_count == 1:
            plpy.warning(
                'Clash generating unique openid_identifier. '
                'Increase length if you see this warning too much.')
    plpy.error(
        "Unable to generate unique openid_identifier. "
        "Need to increase length of tokens.")
$$;


CREATE FUNCTION getlocalnodeid() RETURNS integer
    LANGUAGE plpgsql STABLE SECURITY DEFINER
    SET search_path TO public
    AS $$
    DECLARE
        v_node_id integer;
    BEGIN
        SELECT INTO v_node_id _sl.getlocalnodeid('_sl');
        RETURN v_node_id;
    EXCEPTION
        WHEN invalid_schema_name THEN
            RETURN NULL;
    END;
$$;


COMMENT ON FUNCTION getlocalnodeid() IS 'Return the replication node id for this node, or NULL if not a replicated installation.';


CREATE FUNCTION is_blacklisted_name(text, integer) RETURNS boolean
    LANGUAGE sql STABLE STRICT SECURITY DEFINER
    SET search_path TO public
    AS $_$
    SELECT COALESCE(name_blacklist_match($1, $2)::boolean, FALSE);
$_$;


COMMENT ON FUNCTION is_blacklisted_name(text, integer) IS 'Return TRUE if any regular expressions stored in the NameBlacklist table match the givenname, otherwise return FALSE.';


CREATE FUNCTION is_person(text) RETURNS boolean
    LANGUAGE sql STABLE STRICT
    AS $_$
    SELECT count(*)>0 FROM Person WHERE name=$1 AND teamowner IS NULL;
$_$;


COMMENT ON FUNCTION is_person(text) IS 'True if the given name identifies a person in the Person table';


CREATE FUNCTION is_printable_ascii(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $_$
    import re, string
    try:
        text = args[0].decode("ASCII")
    except UnicodeError:
        return False
    if re.search(r"^[%s]*$" % re.escape(string.printable), text) is None:
        return False
    return True
$_$;


COMMENT ON FUNCTION is_printable_ascii(text) IS 'True if the string is pure printable US-ASCII';


CREATE FUNCTION is_team(integer) RETURNS boolean
    LANGUAGE sql STABLE STRICT
    AS $_$
    SELECT count(*)>0 FROM Person WHERE id=$1 AND teamowner IS NOT NULL;
$_$;


COMMENT ON FUNCTION is_team(integer) IS 'True if the given id identifies a team in the Person table';


CREATE FUNCTION is_team(text) RETURNS boolean
    LANGUAGE sql STABLE STRICT
    AS $_$
    SELECT count(*)>0 FROM Person WHERE name=$1 AND teamowner IS NOT NULL;
$_$;


COMMENT ON FUNCTION is_team(text) IS 'True if the given name identifies a team in the Person table';


CREATE FUNCTION lp_mirror_account_ins() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    INSERT INTO lp_Account (id, openid_identifier)
    VALUES (NEW.id, NEW.openid_identifier);
    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_account_upd() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF OLD.id <> NEW.id OR OLD.openid_identifier <> NEW.openid_identifier THEN
        UPDATE lp_Account
        SET id = NEW.id, openid_identifier = NEW.openid_identifier
        WHERE id = OLD.id;
    END IF;
    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_del() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    EXECUTE 'DELETE FROM lp_' || TG_TABLE_NAME || ' WHERE id=' || OLD.id;
    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_openididentifier_del() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
DECLARE
    next_identifier text;
BEGIN
    SELECT INTO next_identifier identifier FROM OpenIdIdentifier
    WHERE account = OLD.account AND identifier <> OLD.identifier
    ORDER BY date_created DESC LIMIT 1;

    IF next_identifier IS NOT NULL THEN
        UPDATE lp_account SET openid_identifier = next_identifier
        WHERE openid_identifier = OLD.identifier;
    ELSE
        DELETE FROM lp_account WHERE openid_identifier = OLD.identifier;
    END IF;

    DELETE FROM lp_OpenIdIdentifier WHERE identifier = OLD.identifier;

    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_openididentifier_ins() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    -- Support obsolete lp_Account.openid_identifier as best we can
    -- until ISD migrates to using lp_OpenIdIdentifier.
    UPDATE lp_account SET openid_identifier = NEW.identifier
    WHERE id = NEW.account;
    IF NOT found THEN
        INSERT INTO lp_account (id, openid_identifier)
        VALUES (NEW.account, NEW.identifier);
    END IF;

    INSERT INTO lp_OpenIdIdentifier (identifier, account, date_created)
    VALUES (NEW.identifier, NEW.account, NEW.date_created);

    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_openididentifier_upd() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF OLD.identifier <> NEW.identifier THEN
        UPDATE lp_Account SET openid_identifier = NEW.identifier
        WHERE openid_identifier = OLD.identifier;
    END IF;
    UPDATE lp_OpenIdIdentifier
    SET
        identifier = NEW.identifier,
        account = NEW.account,
        date_created = NEW.date_created
    WHERE identifier = OLD.identifier;
    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_person_ins() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    INSERT INTO lp_Person (
        id, displayname, teamowner, teamdescription, name, language, fti,
        defaultmembershipperiod, defaultrenewalperiod, subscriptionpolicy,
        merged, datecreated, homepage_content, icon, mugshot,
        hide_email_addresses, creation_rationale, creation_comment,
        registrant, logo, renewal_policy, personal_standing,
        personal_standing_reason, mail_resumption_date,
        mailing_list_auto_subscribe_policy, mailing_list_receive_duplicates,
        visibility, verbose_bugnotifications, account)
    VALUES (
        NEW.id, NEW.displayname, NEW.teamowner, NULL,
        NEW.name, NEW.language, NEW.fti, NEW.defaultmembershipperiod,
        NEW.defaultrenewalperiod, NEW.subscriptionpolicy,
        NEW.merged, NEW.datecreated, NULL, NEW.icon,
        NEW.mugshot, NEW.hide_email_addresses, NEW.creation_rationale,
        NEW.creation_comment, NEW.registrant, NEW.logo, NEW.renewal_policy,
        NEW.personal_standing, NEW.personal_standing_reason,
        NEW.mail_resumption_date, NEW.mailing_list_auto_subscribe_policy,
        NEW.mailing_list_receive_duplicates, NEW.visibility,
        NEW.verbose_bugnotifications, NEW.account);
    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_person_upd() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    UPDATE lp_Person
    SET id = NEW.id,
        displayname = NEW.displayname,
        teamowner = NEW.teamowner,
        teamdescription = NULL,
        name = NEW.name,
        language = NEW.language,
        fti = NEW.fti,
        defaultmembershipperiod = NEW.defaultmembershipperiod,
        defaultrenewalperiod = NEW.defaultrenewalperiod,
        subscriptionpolicy = NEW.subscriptionpolicy,
        merged = NEW.merged,
        datecreated = NEW.datecreated,
        homepage_content = NULL,
        icon = NEW.icon,
        mugshot = NEW.mugshot,
        hide_email_addresses = NEW.hide_email_addresses,
        creation_rationale = NEW.creation_rationale,
        creation_comment = NEW.creation_comment,
        registrant = NEW.registrant,
        logo = NEW.logo,
        renewal_policy = NEW.renewal_policy,
        personal_standing = NEW.personal_standing,
        personal_standing_reason = NEW.personal_standing_reason,
        mail_resumption_date = NEW.mail_resumption_date,
        mailing_list_auto_subscribe_policy
            = NEW.mailing_list_auto_subscribe_policy,
        mailing_list_receive_duplicates = NEW.mailing_list_receive_duplicates,
        visibility = NEW.visibility,
        verbose_bugnotifications = NEW.verbose_bugnotifications,
        account = NEW.account
    WHERE id = OLD.id;
    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_personlocation_ins() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    INSERT INTO lp_PersonLocation SELECT NEW.*;
    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_personlocation_upd() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    UPDATE lp_PersonLocation
    SET id = NEW.id,
        date_created = NEW.date_created,
        person = NEW.person,
        latitude = NEW.latitude,
        longitude = NEW.longitude,
        time_zone = NEW.time_zone,
        last_modified_by = NEW.last_modified_by,
        date_last_modified = NEW.date_last_modified,
        visible = NEW.visible,
        locked = NEW.locked
    WHERE id = OLD.id;
    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_teamparticipation_ins() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    INSERT INTO lp_TeamParticipation SELECT NEW.*;
    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION lp_mirror_teamparticipation_upd() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    UPDATE lp_TeamParticipation
    SET id = NEW.id,
        team = NEW.team,
        person = NEW.person
    WHERE id = OLD.id;
    RETURN NULL; -- Ignored for AFTER triggers.
END;
$$;


CREATE FUNCTION maintain_transitively_private() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF TG_OP = 'UPDATE' THEN
        IF (NEW.stacked_on IS NOT DISTINCT FROM OLD.stacked_on
            AND NEW.private IS NOT DISTINCT FROM OLD.private) THEN
            RETURN NULL;
        END IF;
    END IF;
    PERFORM update_transitively_private(NEW.id);
    RETURN NULL;
END;
$$;


COMMENT ON FUNCTION maintain_transitively_private() IS 'Trigger maintaining the Branch transitively_private column';


CREATE FUNCTION message_copy_owner_to_bugmessage() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF NEW.owner != OLD.owner THEN
        UPDATE BugMessage
        SET owner = NEW.owner
        WHERE
        BugMessage.message = NEW.id;
    END IF;
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION message_copy_owner_to_bugmessage() IS 'Copies the message owner into bugmessage when message changes.';


CREATE FUNCTION message_copy_owner_to_questionmessage() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF NEW.owner != OLD.owner THEN
        UPDATE QuestionMessage
        SET owner = NEW.owner
        WHERE
        QuestionMessage.message = NEW.id;
    END IF;
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION message_copy_owner_to_questionmessage() IS 'Copies the message owner into questionmessage when message changes.';


CREATE FUNCTION milestone_sort_key(dateexpected timestamp without time zone, name text) RETURNS text
    LANGUAGE plpythonu IMMUTABLE
    AS $$
    # If this method is altered, then any functional indexes using it
    # need to be rebuilt.
    import re
    import datetime

    date_expected, name = args

    def substitute_filled_numbers(match):
        return match.group(0).zfill(5)

    name = re.sub(u'\d+', substitute_filled_numbers, name)
    if date_expected is None:
        # NULL dates are considered to be in the future.
        date_expected = datetime.datetime(datetime.MAXYEAR, 1, 1)
    return '%s %s' % (date_expected, name)
$$;


COMMENT ON FUNCTION milestone_sort_key(dateexpected timestamp without time zone, name text) IS 'Sort by the Milestone dateexpected and name. If the dateexpected is NULL, then it is converted to a date far in the future, so it will be sorted as a milestone in the future.';


CREATE FUNCTION mv_branch_distribution_update() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF OLD.id != NEW.id THEN
        RAISE EXCEPTION 'Cannot change Distribution.id';
    END IF;
    IF OLD.name != NEW.name THEN
        UPDATE Branch SET unique_name = NULL
        FROM DistroSeries
        WHERE Branch.distroseries = Distroseries.id
            AND Distroseries.distribution = NEW.id;
    END IF;
    RETURN NULL;
END;
$$;


COMMENT ON FUNCTION mv_branch_distribution_update() IS 'Maintain Branch name cache when Distribution is modified.';


CREATE FUNCTION mv_branch_distroseries_update() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF OLD.id != NEW.id THEN
        RAISE EXCEPTION 'Cannot change Distroseries.id';
    END IF;
    IF OLD.name != NEW.name THEN
        UPDATE Branch SET unique_name = NULL
        WHERE Branch.distroseries = NEW.id;
    END IF;
    RETURN NULL;
END;
$$;


COMMENT ON FUNCTION mv_branch_distroseries_update() IS 'Maintain Branch name cache when Distroseries is modified.';


CREATE FUNCTION mv_branch_person_update() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    v_branch RECORD;
BEGIN
    IF OLD.id != NEW.id THEN
        RAISE EXCEPTION 'Cannot change Person.id';
    END IF;
    IF OLD.name != NEW.name THEN
        UPDATE Branch SET owner_name = NEW.name WHERE owner = NEW.id;
    END IF;
    RETURN NULL;
END;
$$;


COMMENT ON FUNCTION mv_branch_person_update() IS 'Maintain Branch name cache when Person is modified.';


CREATE FUNCTION mv_branch_product_update() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    v_branch RECORD;
BEGIN
    IF OLD.id != NEW.id THEN
        RAISE EXCEPTION 'Cannot change Product.id';
    END IF;
    IF OLD.name != NEW.name THEN
        UPDATE Branch SET target_suffix = NEW.name WHERE product=NEW.id;
    END IF;
    RETURN NULL;
END;
$$;


COMMENT ON FUNCTION mv_branch_product_update() IS 'Maintain Branch name cache when Product is modified.';


CREATE FUNCTION mv_pillarname_distribution() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF TG_OP = 'INSERT' THEN
        INSERT INTO PillarName (name, distribution)
        VALUES (NEW.name, NEW.id);
    ELSIF NEW.name != OLD.name THEN
        UPDATE PillarName SET name=NEW.name WHERE distribution=NEW.id;
    END IF;
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION mv_pillarname_distribution() IS 'Trigger maintaining the PillarName table';


CREATE FUNCTION mv_pillarname_product() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF TG_OP = 'INSERT' THEN
        INSERT INTO PillarName (name, product, active)
        VALUES (NEW.name, NEW.id, NEW.active);
    ELSIF NEW.name != OLD.name OR NEW.active != OLD.active THEN
        UPDATE PillarName SET name=NEW.name, active=NEW.active
        WHERE product=NEW.id;
    END IF;
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION mv_pillarname_product() IS 'Trigger maintaining the PillarName table';


CREATE FUNCTION mv_pillarname_project() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF TG_OP = 'INSERT' THEN
        INSERT INTO PillarName (name, project, active)
        VALUES (NEW.name, NEW.id, NEW.active);
    ELSIF NEW.name != OLD.name or NEW.active != OLD.active THEN
        UPDATE PillarName SET name=NEW.name, active=NEW.active
        WHERE project=NEW.id;
    END IF;
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION mv_pillarname_project() IS 'Trigger maintaining the PillarName table';


CREATE FUNCTION mv_pofiletranslator_pomsgset() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF TG_OP = 'DELETE' THEN
        RAISE EXCEPTION
            'Deletions from POMsgSet not supported by the POFileTranslator materialized view';
    ELSIF TG_OP = 'UPDATE' THEN
        IF OLD.pofile != NEW.pofile THEN
            RAISE EXCEPTION
                'Changing POMsgSet.pofile not supported by the POFileTranslator materialized view';
        END IF;
    END IF;
    RETURN NEW;
END;
$$;


COMMENT ON FUNCTION mv_pofiletranslator_pomsgset() IS 'Trigger enforing no POMsgSet deletions or POMsgSet.pofile changes';


CREATE FUNCTION mv_pofiletranslator_posubmission() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    AS $$
DECLARE
    v_pofile INTEGER;
    v_trash_old BOOLEAN;
BEGIN
    -- If we are deleting a row, we need to remove the existing
    -- POFileTranslator row and reinsert the historical data if it exists.
    -- We also treat UPDATEs that change the key (person, pofile) the same
    -- as deletes. UPDATEs that don't change these columns are treated like
    -- INSERTs below.
    IF TG_OP = 'INSERT' THEN
        v_trash_old := FALSE;
    ELSIF TG_OP = 'DELETE' THEN
        v_trash_old := TRUE;
    ELSE -- UPDATE
        v_trash_old = (
            OLD.person != NEW.person OR OLD.pomsgset != NEW.pomsgset
            );
    END IF;

    IF v_trash_old THEN

        -- Delete the old record.
        DELETE FROM POFileTranslator USING POMsgSet
        WHERE POFileTranslator.pofile = POMsgSet.pofile
            AND POFileTranslator.person = OLD.person
            AND POMsgSet.id = OLD.pomsgset;

        -- Insert a past record if there is one.
        INSERT INTO POFileTranslator (
            person, pofile, latest_posubmission, date_last_touched
            )
            SELECT DISTINCT ON (POSubmission.person, POMsgSet.pofile)
                POSubmission.person, POMsgSet.pofile,
                POSubmission.id, POSubmission.datecreated
            FROM POSubmission, POMsgSet
            WHERE POSubmission.pomsgset = POMsgSet.id
                AND POSubmission.pomsgset = OLD.pomsgset
                AND POSubmission.person = OLD.person
            ORDER BY
                POSubmission.person, POMsgSet.pofile,
                POSubmission.datecreated DESC, POSubmission.id DESC;

        -- No NEW with DELETE, so we can short circuit and leave.
        IF TG_OP = 'DELETE' THEN
            RETURN NULL; -- Ignored because this is an AFTER trigger
        END IF;
    END IF;

    -- Get our new pofile id
    SELECT INTO v_pofile POMsgSet.pofile FROM POMsgSet
    WHERE POMsgSet.id = NEW.pomsgset;

    -- Standard 'upsert' loop to avoid race conditions.
    LOOP
        UPDATE POFileTranslator
            SET
                date_last_touched = CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
                latest_posubmission = NEW.id
            WHERE
                person = NEW.person
                AND pofile = v_pofile;
        IF found THEN
            RETURN NULL; -- Return value ignored as this is an AFTER trigger
        END IF;

        BEGIN
            INSERT INTO POFileTranslator (person, pofile, latest_posubmission)
            VALUES (NEW.person, v_pofile, NEW.id);
            RETURN NULL; -- Return value ignored as this is an AFTER trigger
        EXCEPTION WHEN unique_violation THEN
            -- do nothing
        END;
    END LOOP;
END;
$$;


COMMENT ON FUNCTION mv_pofiletranslator_posubmission() IS 'Trigger maintaining the POFileTranslator table';


CREATE FUNCTION mv_pofiletranslator_translationmessage() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
DECLARE
    v_trash_old BOOLEAN;
BEGIN
    -- If we are deleting a row, we need to remove the existing
    -- POFileTranslator row and reinsert the historical data if it exists.
    -- We also treat UPDATEs that change the key (submitter) the same
    -- as deletes. UPDATEs that don't change these columns are treated like
    -- INSERTs below.
    IF TG_OP = 'INSERT' THEN
        v_trash_old := FALSE;
    ELSIF TG_OP = 'DELETE' THEN
        v_trash_old := TRUE;
    ELSE -- UPDATE
        v_trash_old = (
            OLD.submitter != NEW.submitter
            );
    END IF;

    IF v_trash_old THEN
        -- Was this somebody's most-recently-changed message?
        -- If so, delete the entry for that change.
        DELETE FROM POFileTranslator
        WHERE latest_message = OLD.id;
        IF FOUND THEN
            -- We deleted the entry for somebody's latest contribution.
            -- Find that person's latest remaining contribution and
            -- create a new record for that.
            INSERT INTO POFileTranslator (
                person, pofile, latest_message, date_last_touched
                )
            SELECT DISTINCT ON (person, pofile.id)
                new_latest_message.submitter AS person,
                pofile.id,
                new_latest_message.id,
                greatest(new_latest_message.date_created,
                         new_latest_message.date_reviewed)
              FROM POFile
              JOIN TranslationTemplateItem AS old_template_item
                ON OLD.potmsgset = old_template_item.potmsgset AND
                   old_template_item.potemplate = pofile.potemplate AND
                   pofile.language = OLD.language
              JOIN TranslationTemplateItem AS new_template_item
                ON (old_template_item.potemplate =
                     new_template_item.potemplate)
              JOIN TranslationMessage AS new_latest_message
                ON new_latest_message.potmsgset =
                       new_template_item.potmsgset AND
                   new_latest_message.language = OLD.language
              LEFT OUTER JOIN POfileTranslator AS ExistingEntry
                ON ExistingEntry.person = OLD.submitter AND
                   ExistingEntry.pofile = POFile.id
              WHERE
                new_latest_message.submitter = OLD.submitter AND
                ExistingEntry IS NULL
              ORDER BY new_latest_message.submitter, pofile.id,
                       new_latest_message.date_created DESC,
                       new_latest_message.id DESC;
        END IF;

        -- No NEW with DELETE, so we can short circuit and leave.
        IF TG_OP = 'DELETE' THEN
            RETURN NULL; -- Ignored because this is an AFTER trigger
        END IF;
    END IF;

    -- Standard 'upsert' loop to avoid race conditions.
    LOOP
        UPDATE POFileTranslator
        SET
            date_last_touched = CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
            latest_message = NEW.id
        FROM POFile, TranslationTemplateItem
        WHERE person = NEW.submitter AND
              TranslationTemplateItem.potmsgset=NEW.potmsgset AND
              TranslationTemplateItem.potemplate=pofile.potemplate AND
              pofile.language=NEW.language AND
              POFileTranslator.pofile = pofile.id;
        IF found THEN
            RETURN NULL; -- Return value ignored as this is an AFTER trigger
        END IF;

        BEGIN
            INSERT INTO POFileTranslator (person, pofile, latest_message)
            SELECT DISTINCT ON (NEW.submitter, pofile.id)
                NEW.submitter, pofile.id, NEW.id
              FROM TranslationTemplateItem
              JOIN POFile
                ON pofile.language = NEW.language AND
                   pofile.potemplate = translationtemplateitem.potemplate
              WHERE
                TranslationTemplateItem.potmsgset = NEW.potmsgset;
            RETURN NULL; -- Return value ignored as this is an AFTER trigger
        EXCEPTION WHEN unique_violation THEN
            -- do nothing
        END;
    END LOOP;
END;
$$;


COMMENT ON FUNCTION mv_pofiletranslator_translationmessage() IS 'Trigger maintaining the POFileTranslator table';


CREATE FUNCTION mv_validpersonorteamcache_emailaddress() RETURNS trigger
    LANGUAGE plpythonu SECURITY DEFINER
    AS $_$
    # This trigger function keeps the ValidPersonOrTeamCache materialized
    # view in sync when updates are made to the EmailAddress table.
    # Note that if the corresponding person is a team, changes to this table
    # have no effect.
    PREF = 4 # Constant indicating preferred email address

    if not SD.has_key("delete_plan"):
        param_types = ["int4"]

        SD["is_team"] = plpy.prepare("""
            SELECT teamowner IS NOT NULL AS is_team FROM Person WHERE id = $1
            """, param_types)

        SD["delete_plan"] = plpy.prepare("""
            DELETE FROM ValidPersonOrTeamCache WHERE id = $1
            """, param_types)

        SD["insert_plan"] = plpy.prepare("""
            INSERT INTO ValidPersonOrTeamCache (id) VALUES ($1)
            """, param_types)

        SD["maybe_insert_plan"] = plpy.prepare("""
            INSERT INTO ValidPersonOrTeamCache (id)
            SELECT Person.id
            FROM Person
                JOIN EmailAddress ON Person.id = EmailAddress.person
                LEFT OUTER JOIN ValidPersonOrTeamCache
                    ON Person.id = ValidPersonOrTeamCache.id
            WHERE Person.id = $1
                AND ValidPersonOrTeamCache.id IS NULL
                AND status = %(PREF)d
                AND merged IS NULL
                -- AND password IS NOT NULL
            """ % vars(), param_types)

    def is_team(person_id):
        """Return true if person_id corresponds to a team"""
        if person_id is None:
            return False
        return plpy.execute(SD["is_team"], [person_id], 1)[0]["is_team"]

    class NoneDict:
        def __getitem__(self, key):
            return None

    old = TD["old"] or NoneDict()
    new = TD["new"] or NoneDict()

    #plpy.info("old.id     == %s" % old["id"])
    #plpy.info("old.person == %s" % old["person"])
    #plpy.info("old.status == %s" % old["status"])
    #plpy.info("new.id     == %s" % new["id"])
    #plpy.info("new.person == %s" % new["person"])
    #plpy.info("new.status == %s" % new["status"])

    # Short circuit if neither person nor status has changed
    if old["person"] == new["person"] and old["status"] == new["status"]:
        return

    # Short circuit if we are not mucking around with preferred email
    # addresses
    if old["status"] != PREF and new["status"] != PREF:
        return

    # Note that we have a constraint ensuring that there is only one
    # status == PREF email address per person at any point in time.
    # This simplifies our logic, as we know that if old.status == PREF,
    # old.person does not have any other preferred email addresses.
    # Also if new.status == PREF, we know new.person previously did not
    # have a preferred email address.

    if old["person"] != new["person"]:
        if old["status"] == PREF and not is_team(old["person"]):
            # old.person is no longer valid, unless they are a team
            plpy.execute(SD["delete_plan"], [old["person"]])
        if new["status"] == PREF and not is_team(new["person"]):
            # new["person"] is now valid, or unchanged if they are a team
            plpy.execute(SD["insert_plan"], [new["person"]])

    elif old["status"] == PREF and not is_team(old["person"]):
        # No longer valid, or unchanged if they are a team
        plpy.execute(SD["delete_plan"], [old["person"]])

    elif new["status"] == PREF and not is_team(new["person"]):
        # May now be valid, or unchanged if they are a team.
        plpy.execute(SD["maybe_insert_plan"], [new["person"]])
$_$;


COMMENT ON FUNCTION mv_validpersonorteamcache_emailaddress() IS 'A trigger for maintaining the ValidPersonOrTeamCache eager materialized view when changes are made to the EmailAddress table';


CREATE FUNCTION mv_validpersonorteamcache_person() RETURNS trigger
    LANGUAGE plpythonu SECURITY DEFINER
    AS $_$
    # This trigger function could be simplified by simply issuing
    # one DELETE followed by one INSERT statement. However, we want to minimize
    # expensive writes so we use this more complex logic.
    PREF = 4 # Constant indicating preferred email address

    if not SD.has_key("delete_plan"):
        param_types = ["int4"]

        SD["delete_plan"] = plpy.prepare("""
            DELETE FROM ValidPersonOrTeamCache WHERE id = $1
            """, param_types)

        SD["maybe_insert_plan"] = plpy.prepare("""
            INSERT INTO ValidPersonOrTeamCache (id)
            SELECT Person.id
            FROM Person
                LEFT OUTER JOIN EmailAddress
                    ON Person.id = EmailAddress.person AND status = %(PREF)d
                LEFT OUTER JOIN ValidPersonOrTeamCache
                    ON Person.id = ValidPersonOrTeamCache.id
            WHERE Person.id = $1
                AND ValidPersonOrTeamCache.id IS NULL
                AND merged IS NULL
                AND (teamowner IS NOT NULL OR EmailAddress.id IS NOT NULL)
            """ % vars(), param_types)

    new = TD["new"]
    old = TD["old"]

    # We should always have new, as this is not a DELETE trigger
    assert new is not None, 'New is None'

    person_id = new["id"]
    query_params = [person_id] # All the same

    # Short circuit if this is a new person (not team), as it cannot
    # be valid until a status == 4 EmailAddress entry has been created
    # (unless it is a team, in which case it is valid on creation)
    if old is None:
        if new["teamowner"] is not None:
            plpy.execute(SD["maybe_insert_plan"], query_params)
        return

    # Short circuit if there are no relevant changes
    if (new["teamowner"] == old["teamowner"]
        and new["merged"] == old["merged"]):
        return

    # This function is only dealing with updates to the Person table.
    # This means we do not have to worry about EmailAddress changes here

    if (new["merged"] is not None or new["teamowner"] is None):
        plpy.execute(SD["delete_plan"], query_params)
    else:
        plpy.execute(SD["maybe_insert_plan"], query_params)
$_$;


COMMENT ON FUNCTION mv_validpersonorteamcache_person() IS 'A trigger for maintaining the ValidPersonOrTeamCache eager materialized view when changes are made to the Person table';


CREATE FUNCTION name_blacklist_match(text, integer) RETURNS integer
    LANGUAGE plpythonu STABLE STRICT SECURITY DEFINER
    SET search_path TO public
    AS $_$
    import re
    name = args[0].decode("UTF-8")
    user_id = args[1]

    # Initialize shared storage, shared between invocations.
    if not SD.has_key("regexp_select_plan"):

        # All the blacklist regexps except the ones we are an admin
        # for. These we do not check since they are not blacklisted to us.
        SD["regexp_select_plan"] = plpy.prepare("""
            SELECT id, regexp FROM NameBlacklist
            WHERE admin IS NULL OR admin NOT IN (
                SELECT team FROM TeamParticipation
                WHERE person = $1)
            ORDER BY id
            """, ["integer"])

        # Storage for compiled regexps
        SD["compiled"] = {}

        # admins is a celebrity and its id is immutable.
        admins_id = plpy.execute(
            "SELECT id FROM Person WHERE name='admins'")[0]["id"]

        SD["admin_select_plan"] = plpy.prepare("""
            SELECT TRUE FROM TeamParticipation
            WHERE
                TeamParticipation.team = %d
                AND TeamParticipation.person = $1
            LIMIT 1
            """ % admins_id, ["integer"])

        # All the blacklist regexps except those that have an admin because
        # members of ~admin can use any name that any other admin can use.
        SD["admin_regexp_select_plan"] = plpy.prepare("""
            SELECT id, regexp FROM NameBlacklist
            WHERE admin IS NULL
            ORDER BY id
            """, ["integer"])


    compiled = SD["compiled"]

    # Names are never blacklisted for Lauchpad admins.
    if user_id is not None and plpy.execute(
        SD["admin_select_plan"], [user_id]).nrows() > 0:
        blacklist_plan = "admin_regexp_select_plan"
    else:
        blacklist_plan = "regexp_select_plan"

    for row in plpy.execute(SD[blacklist_plan], [user_id]):
        regexp_id = row["id"]
        regexp_txt = row["regexp"]
        if (compiled.get(regexp_id) is None
            or compiled[regexp_id][0] != regexp_txt):
            regexp = re.compile(
                regexp_txt, re.IGNORECASE | re.UNICODE | re.VERBOSE
                )
            compiled[regexp_id] = (regexp_txt, regexp)
        else:
            regexp = compiled[regexp_id][1]
        if regexp.search(name) is not None:
            return regexp_id
    return None
$_$;


COMMENT ON FUNCTION name_blacklist_match(text, integer) IS 'Return the id of the row in the NameBlacklist table that matches the given name, or NULL if no regexps in the NameBlacklist table match.';


CREATE FUNCTION null_count(p_values anyarray) RETURNS integer
    LANGUAGE plpgsql IMMUTABLE STRICT
    AS $$
DECLARE
    v_index integer;
    v_null_count integer := 0;
BEGIN
    FOR v_index IN array_lower(p_values,1)..array_upper(p_values,1) LOOP
        IF p_values[v_index] IS NULL THEN
            v_null_count := v_null_count + 1;
        END IF;
    END LOOP;
    RETURN v_null_count;
END;
$$;


COMMENT ON FUNCTION null_count(p_values anyarray) IS 'Return the number of NULLs in the first row of the given array.';


CREATE FUNCTION packageset_deleted_trig() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    DELETE FROM flatpackagesetinclusion
      WHERE parent = OLD.id AND child = OLD.id;

    -- A package set was deleted; it may have participated in package set
    -- inclusion relations in a sub/superset role; delete all inclusion
    -- relationships in which it participated.
    DELETE FROM packagesetinclusion
      WHERE parent = OLD.id OR child = OLD.id;
    RETURN OLD;
END;
$$;


COMMENT ON FUNCTION packageset_deleted_trig() IS 'Remove any DAG edges leading to/from the deleted package set.';


CREATE FUNCTION packageset_inserted_trig() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    -- A new package set was inserted; make it a descendent of itself in
    -- the flattened package set inclusion table in order to facilitate
    -- querying.
    INSERT INTO flatpackagesetinclusion(parent, child)
      VALUES (NEW.id, NEW.id);
    RETURN NULL;
END;
$$;


COMMENT ON FUNCTION packageset_inserted_trig() IS 'Insert self-referencing DAG edge when a new package set is inserted.';


CREATE FUNCTION packagesetinclusion_deleted_trig() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    -- A package set inclusion relationship was deleted i.e. a set M
    -- ceases to include another set N as a subset.
    -- For an explanation of the queries below please see page 5 of
    -- "Maintaining Transitive Closure of Graphs in SQL"
    -- http://www.comp.nus.edu.sg/~wongls/psZ/dlsw-ijit97-16.ps
    CREATE TEMP TABLE tmp_fpsi_suspect(
        parent integer NOT NULL,
        child integer NOT NULL);
    CREATE TEMP TABLE tmp_fpsi_trusted(
        parent integer NOT NULL,
        child integer NOT NULL);
    CREATE TEMP TABLE tmp_fpsi_good(
        parent integer NOT NULL,
        child integer NOT NULL);

    INSERT INTO tmp_fpsi_suspect (
        SELECT X.parent, Y.child
        FROM flatpackagesetinclusion X, flatpackagesetinclusion Y
        WHERE X.child = OLD.parent AND Y.parent = OLD.child
      UNION
        SELECT X.parent, OLD.child FROM flatpackagesetinclusion X
        WHERE X.child = OLD.parent
      UNION
        SELECT OLD.parent, X.child FROM flatpackagesetinclusion X
        WHERE X.parent = OLD.child
      UNION
        SELECT OLD.parent, OLD.child
        );

    INSERT INTO tmp_fpsi_trusted (
        SELECT parent, child FROM flatpackagesetinclusion
        EXCEPT
        SELECT parent, child FROM tmp_fpsi_suspect
      UNION
        SELECT parent, child FROM packagesetinclusion psi
        WHERE psi.parent != OLD.parent AND psi.child != OLD.child
        );

    INSERT INTO tmp_fpsi_good (
        SELECT parent, child FROM tmp_fpsi_trusted
      UNION
        SELECT T1.parent, T2.child
        FROM tmp_fpsi_trusted T1, tmp_fpsi_trusted T2
        WHERE T1.child = T2.parent
      UNION
        SELECT T1.parent, T3.child
        FROM tmp_fpsi_trusted T1, tmp_fpsi_trusted T2, tmp_fpsi_trusted T3
        WHERE T1.child = T2.parent AND T2.child = T3.parent
        );

    DELETE FROM flatpackagesetinclusion fpsi
    WHERE NOT EXISTS (
        SELECT * FROM tmp_fpsi_good T
        WHERE T.parent = fpsi.parent AND T.child = fpsi.child);

    DROP TABLE tmp_fpsi_good;
    DROP TABLE tmp_fpsi_trusted;
    DROP TABLE tmp_fpsi_suspect;

    RETURN OLD;
END;
$$;


COMMENT ON FUNCTION packagesetinclusion_deleted_trig() IS 'Maintain the transitive closure in the DAG when an edge leading to/from a package set is deleted.';


CREATE FUNCTION packagesetinclusion_inserted_trig() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    DECLARE
        parent_name text;
        child_name text;
        parent_distroseries text;
        child_distroseries text;
    BEGIN
        -- Make sure that the package sets being associated here belong
        -- to the same distro series.
        IF (SELECT parent.distroseries != child.distroseries
            FROM packageset parent, packageset child
            WHERE parent.id = NEW.parent AND child.id = NEW.child)
        THEN
            SELECT name INTO parent_name FROM packageset WHERE id = NEW.parent;
            SELECT name INTO child_name FROM packageset WHERE id = NEW.child;
            SELECT ds.name INTO parent_distroseries FROM packageset ps, distroseries ds WHERE ps.id = NEW.parent AND ps.distroseries = ds.id;
            SELECT ds.name INTO child_distroseries FROM packageset ps, distroseries ds WHERE ps.id = NEW.child AND ps.distroseries = ds.id;
            RAISE EXCEPTION 'Package sets % and % belong to different distro series (to % and % respectively) and thus cannot be associated.', child_name, parent_name, child_distroseries, parent_distroseries;
        END IF;

        IF EXISTS(
            SELECT * FROM flatpackagesetinclusion
            WHERE parent = NEW.child AND child = NEW.parent LIMIT 1)
        THEN
            SELECT name INTO parent_name FROM packageset WHERE id = NEW.parent;
            SELECT name INTO child_name FROM packageset WHERE id = NEW.child;
            RAISE EXCEPTION 'Package set % already includes %. Adding (% -> %) would introduce a cycle in the package set graph (DAG).', child_name, parent_name, parent_name, child_name;
        END IF;
    END;
    -- A new package set inclusion relationship was inserted i.e. a set M
    -- now includes another set N as a subset.
    -- For an explanation of the queries below please see page 4 of
    -- "Maintaining Transitive Closure of Graphs in SQL"
    -- http://www.comp.nus.edu.sg/~wongls/psZ/dlsw-ijit97-16.ps
    CREATE TEMP TABLE tmp_fpsi_new(
        parent integer NOT NULL,
        child integer NOT NULL);

    INSERT INTO tmp_fpsi_new (
        SELECT
            X.parent AS parent, NEW.child AS child
        FROM flatpackagesetinclusion X WHERE X.child = NEW.parent
      UNION
        SELECT
            NEW.parent AS parent, X.child AS child
        FROM flatpackagesetinclusion X WHERE X.parent = NEW.child
      UNION
        SELECT
            X.parent AS parent, Y.child AS child
        FROM flatpackagesetinclusion X, flatpackagesetinclusion Y
        WHERE X.child = NEW.parent AND Y.parent = NEW.child
        );
    INSERT INTO tmp_fpsi_new(parent, child) VALUES(NEW.parent, NEW.child);

    INSERT INTO flatpackagesetinclusion(parent, child) (
        SELECT
            parent, child FROM tmp_fpsi_new
        EXCEPT
        SELECT F.parent, F.child FROM flatpackagesetinclusion F
        );

    DROP TABLE tmp_fpsi_new;

    RETURN NULL;
END;
$$;


COMMENT ON FUNCTION packagesetinclusion_inserted_trig() IS 'Maintain the transitive closure in the DAG for a newly inserted edge leading to/from a package set.';


CREATE FUNCTION person_sort_key(displayname text, name text) RETURNS text
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $$
    # NB: If this implementation is changed, the person_sort_idx needs to be
    # rebuilt along with any other indexes using it.
    import re

    try:
        strip_re = SD["strip_re"]
    except KeyError:
        strip_re = re.compile("(?:[^\w\s]|[\d_])", re.U)
        SD["strip_re"] = strip_re

    displayname, name = args

    # Strip noise out of displayname. We do not have to bother with
    # name, as we know it is just plain ascii.
    displayname = strip_re.sub('', displayname.decode('UTF-8').lower())
    return ("%s, %s" % (displayname.strip(), name)).encode('UTF-8')
$$;


COMMENT ON FUNCTION person_sort_key(displayname text, name text) IS 'Return a string suitable for sorting people on, generated by stripping noise out of displayname and concatenating name';


CREATE FUNCTION pgstattuple(text) RETURNS pgstattuple_type
    LANGUAGE c STRICT
    AS '$libdir/pgstattuple', 'pgstattuple';


CREATE FUNCTION pgstattuple(oid) RETURNS pgstattuple_type
    LANGUAGE c STRICT
    AS '$libdir/pgstattuple', 'pgstattuplebyid';


CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler
    LANGUAGE c
    AS '$libdir/plpgsql', 'plpgsql_call_handler';


CREATE FUNCTION plpython_call_handler() RETURNS language_handler
    LANGUAGE c
    AS '$libdir/plpython', 'plpython_call_handler';


CREATE FUNCTION questionmessage_copy_owner_from_message() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF TG_OP = 'INSERT' THEN
        IF NEW.owner is NULL THEN
            UPDATE QuestionMessage
            SET owner = Message.owner FROM
            Message WHERE
            Message.id = NEW.message AND
            QuestionMessage.id = NEW.id;
        END IF;
    ELSIF NEW.message != OLD.message THEN
        UPDATE QuestionMessage
        SET owner = Message.owner FROM
        Message WHERE
        Message.id = NEW.message AND
        QuestionMessage.id = NEW.id;
    END IF;
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION questionmessage_copy_owner_from_message() IS 'Copies the message owner into QuestionMessage when QuestionMessage changes.';


CREATE FUNCTION replication_lag() RETURNS interval
    LANGUAGE plpgsql STABLE SECURITY DEFINER
    SET search_path TO public
    AS $$
    DECLARE
        v_lag interval;
    BEGIN
        SELECT INTO v_lag max(st_lag_time) FROM _sl.sl_status;
        RETURN v_lag;
    -- Slony-I not installed here - non-replicated setup.
    EXCEPTION
        WHEN invalid_schema_name THEN
            RETURN NULL;
        WHEN undefined_table THEN
            RETURN NULL;
    END;
$$;


COMMENT ON FUNCTION replication_lag() IS 'Returns the worst lag time in our cluster, or NULL if not a replicated installation. Only returns meaningful results on the lpmain replication set master.';


CREATE FUNCTION replication_lag(node_id integer) RETURNS interval
    LANGUAGE plpgsql STABLE SECURITY DEFINER
    SET search_path TO public
    AS $$
    DECLARE
        v_lag interval;
    BEGIN
        SELECT INTO v_lag st_lag_time FROM _sl.sl_status
            WHERE st_origin = _sl.getlocalnodeid('_sl')
                AND st_received = node_id;
        RETURN v_lag;
    -- Slony-I not installed here - non-replicated setup.
    EXCEPTION
        WHEN invalid_schema_name THEN
            RETURN NULL;
        WHEN undefined_table THEN
            RETURN NULL;
    END;
$$;


COMMENT ON FUNCTION replication_lag(node_id integer) IS 'Returns the lag time of the lpmain replication set to the given node, or NULL if not a replicated installation. The node id parameter can be obtained by calling getlocalnodeid() on the relevant database. This function only returns meaningful results on the lpmain replication set master.';


CREATE FUNCTION sane_version(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $_$
    import re
    if re.search("""^(?ix)
        [0-9a-z]
        ( [0-9a-z] | [0-9a-z.-]*[0-9a-z] )*
        $""", args[0]):
        return 1
    return 0
$_$;


COMMENT ON FUNCTION sane_version(text) IS 'A sane version number for use by ProductRelease and DistroRelease. We may make it less strict if required, but it would be nice if we can enforce simple version strings because we use them in URLs';


CREATE FUNCTION set_bug_date_last_message() RETURNS trigger
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
BEGIN
    IF TG_OP = 'INSERT' THEN
        UPDATE Bug
        SET date_last_message = CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
        WHERE Bug.id = NEW.bug;
    ELSE
        UPDATE Bug
        SET date_last_message = max_datecreated
        FROM (
            SELECT BugMessage.bug, max(Message.datecreated) AS max_datecreated
            FROM BugMessage, Message
            WHERE BugMessage.id <> OLD.id
                AND BugMessage.bug = OLD.bug
                AND BugMessage.message = Message.id
            GROUP BY BugMessage.bug
            ) AS MessageSummary
        WHERE Bug.id = MessageSummary.bug;
    END IF;
    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION set_bug_date_last_message() IS 'AFTER INSERT trigger on BugMessage maintaining the Bug.date_last_message column';


CREATE FUNCTION set_bug_message_count() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF TG_OP = 'UPDATE' THEN
        IF NEW.bug = OLD.bug THEN
            RETURN NULL; -- Ignored - this is an AFTER trigger.
        END IF;
    END IF;

    IF TG_OP <> 'DELETE' THEN
        UPDATE Bug SET message_count = message_count + 1
        WHERE Bug.id = NEW.bug;
    END IF;

    IF TG_OP <> 'INSERT' THEN
        UPDATE Bug SET message_count = message_count - 1
        WHERE Bug.id = OLD.bug;
    END IF;

    RETURN NULL; -- Ignored - this is an AFTER trigger.
END;
$$;


COMMENT ON FUNCTION set_bug_message_count() IS 'AFTER UPDATE trigger on BugAffectsPerson maintaining the Bug.users_affected_count column';


CREATE FUNCTION set_bug_number_of_duplicates() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    -- Short circuit on an update that doesn't change duplicateof
    IF TG_OP = 'UPDATE' THEN
        IF NEW.duplicateof = OLD.duplicateof THEN
            RETURN NULL; -- Ignored - this is an AFTER trigger
        END IF;
    END IF;

    -- For update or delete, possibly decrement a bug's dupe count
    IF TG_OP <> 'INSERT' THEN
        IF OLD.duplicateof IS NOT NULL THEN
            UPDATE Bug SET number_of_duplicates = number_of_duplicates - 1
                WHERE Bug.id = OLD.duplicateof;
        END IF;
    END IF;

    -- For update or insert, possibly increment a bug's dupe cout
    IF TG_OP <> 'DELETE' THEN
        IF NEW.duplicateof IS NOT NULL THEN
            UPDATE Bug SET number_of_duplicates = number_of_duplicates + 1
                WHERE Bug.id = NEW.duplicateof;
        END IF;
    END IF;

    RETURN NULL; -- Ignored - this is an AFTER trigger
END;
$$;


COMMENT ON FUNCTION set_bug_number_of_duplicates() IS 'AFTER UPDATE trigger on Bug maintaining the Bug.number_of_duplicates column';


CREATE FUNCTION set_bug_users_affected_count() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF TG_OP = 'INSERT' THEN
        IF NEW.affected = TRUE THEN
            UPDATE Bug
            SET users_affected_count = users_affected_count + 1
            WHERE Bug.id = NEW.bug;
        ELSE
            UPDATE Bug
            SET users_unaffected_count = users_unaffected_count + 1
            WHERE Bug.id = NEW.bug;
        END IF;
    END IF;

    IF TG_OP = 'DELETE' THEN
        IF OLD.affected = TRUE THEN
            UPDATE Bug
            SET users_affected_count = users_affected_count - 1
            WHERE Bug.id = OLD.bug;
        ELSE
            UPDATE Bug
            SET users_unaffected_count = users_unaffected_count - 1
            WHERE Bug.id = OLD.bug;
        END IF;
    END IF;

    IF TG_OP = 'UPDATE' THEN
        IF OLD.affected <> NEW.affected THEN
            IF NEW.affected THEN
                UPDATE Bug
                SET users_affected_count = users_affected_count + 1,
                    users_unaffected_count = users_unaffected_count - 1
                WHERE Bug.id = OLD.bug;
            ELSE
                UPDATE Bug
                SET users_affected_count = users_affected_count - 1,
                    users_unaffected_count = users_unaffected_count + 1
                WHERE Bug.id = OLD.bug;
            END IF;
        END IF;
    END IF;

    RETURN NULL;
END;
$$;


CREATE FUNCTION set_bugtask_date_milestone_set() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF TG_OP = 'INSERT' THEN
        -- If the inserted row as a milestone set, set date_milestone_set.
        IF NEW.milestone IS NOT NULL THEN
            UPDATE BugTask
            SET date_milestone_set = CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
            WHERE BugTask.id = NEW.id;
        END IF;
    END IF;

    IF TG_OP = 'UPDATE' THEN
        IF OLD.milestone IS NULL THEN
            -- If there was no milestone set, check if the new row has a
            -- milestone set and set date_milestone_set.
            IF NEW.milestone IS NOT NULL THEN
                UPDATE BugTask
                SET date_milestone_set = CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
                WHERE BugTask.id = NEW.id;
            END IF;
        ELSE
            IF NEW.milestone IS NULL THEN
                -- If the milestone was unset, clear date_milestone_set.
                UPDATE BugTask
                SET date_milestone_set = NULL
                WHERE BugTask.id = NEW.id;
            ELSE
                -- Update date_milestone_set if the bug task was
                -- targeted to another milestone.
                IF NEW.milestone != OLD.milestone THEN
                    UPDATE BugTask
                    SET date_milestone_set = CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
                    WHERE BugTask.id = NEW.id;
                END IF;

            END IF;
        END IF;
    END IF;

    RETURN NULL; -- Ignored - this is an AFTER trigger.
END;
$$;


COMMENT ON FUNCTION set_bugtask_date_milestone_set() IS 'Update BugTask.date_milestone_set when BugTask.milestone is changed.';


CREATE FUNCTION set_date_status_set() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF OLD.status <> NEW.status THEN
        NEW.date_status_set = CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
    END IF;
    RETURN NEW;
END;
$$;


COMMENT ON FUNCTION set_date_status_set() IS 'BEFORE UPDATE trigger on Account that maintains the Account.date_status_set column.';


CREATE FUNCTION set_openid_identifier() RETURNS trigger
    LANGUAGE plpythonu
    AS $$
    # If someone is trying to explicitly set the openid_identifier, let them.
    # This also causes openid_identifiers to be left alone if this is an
    # UPDATE trigger.
    if TD['new']['openid_identifier'] is not None:
        return None

    from random import choice

    # Non display confusing characters
    chars = '34678bcdefhkmnprstwxyzABCDEFGHJKLMNPQRTWXY'

    # character length of tokens. Can be increased, decreased or even made
    # random - Launchpad does not care. 7 means it takes 40 bytes to store
    # a null-terminated Launchpad identity URL on the current domain name.
    length=7

    loop_count = 0
    while loop_count < 20000:
        # Generate a random openid_identifier
        oid = ''.join(choice(chars) for count in range(length))

        # Check if the oid is already in the db, although this is pretty
        # unlikely
        rv = plpy.execute("""
            SELECT COUNT(*) AS num FROM Person WHERE openid_identifier = '%s'
            """ % oid, 1)
        if rv[0]['num'] == 0:
            TD['new']['openid_identifier'] = oid
            return "MODIFY"
        loop_count += 1
        if loop_count == 1:
            plpy.warning(
                'Clash generating unique openid_identifier. '
                'Increase length if you see this warning too much.')
    plpy.error(
        "Unable to generate unique openid_identifier. "
        "Need to increase length of tokens.")
$$;


CREATE FUNCTION set_shipit_normalized_address() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
    BEGIN
        NEW.normalized_address =
            lower(
                -- Strip off everything that's not alphanumeric
                -- characters.
                regexp_replace(
                    coalesce(NEW.addressline1, '') || ' ' ||
                    coalesce(NEW.addressline2, '') || ' ' ||
                    coalesce(NEW.city, ''),
                    '[^a-zA-Z0-9]+', '', 'g'));
        RETURN NEW;
    END;
$$;


COMMENT ON FUNCTION set_shipit_normalized_address() IS 'Store a normalized concatenation of the request''s address into the normalized_address column.';


CREATE FUNCTION sha1(text) RETURNS character
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $$
    import hashlib
    return hashlib.sha1(args[0]).hexdigest()
$$;


COMMENT ON FUNCTION sha1(text) IS 'Return the SHA1 one way cryptographic hash as a string of 40 hex digits';


CREATE FUNCTION summarise_bug(bug_row bug) RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE
    d bugsummary%ROWTYPE;
BEGIN
    PERFORM ensure_bugsummary_temp_journal();
    FOR d IN SELECT * FROM bugsummary_locations(BUG_ROW) LOOP
        d.count = 1;
        PERFORM bug_summary_temp_journal_ins(d);
    END LOOP;
END;
$$;


COMMENT ON FUNCTION summarise_bug(bug_row bug) IS 'AFTER summarise a bug row into bugsummary.';


CREATE FUNCTION ulower(text) RETURNS text
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $$
    return args[0].decode('utf8').lower().encode('utf8')
$$;


COMMENT ON FUNCTION ulower(text) IS 'Return the lower case version of a UTF-8 encoded string.';


CREATE FUNCTION unsummarise_bug(bug_row bug) RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE
    d bugsummary%ROWTYPE;
BEGIN
    PERFORM ensure_bugsummary_temp_journal();
    FOR d IN SELECT * FROM bugsummary_locations(BUG_ROW) LOOP
        d.count = -1;
        PERFORM bug_summary_temp_journal_ins(d);
    END LOOP;
END;
$$;


COMMENT ON FUNCTION unsummarise_bug(bug_row bug) IS 'AFTER unsummarise a bug row from bugsummary.';


CREATE FUNCTION update_branch_name_cache() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    needs_update boolean := FALSE;
BEGIN
    IF TG_OP = 'INSERT' THEN
        needs_update := TRUE;
    ELSIF (NEW.owner_name IS NULL
        OR NEW.unique_name IS NULL
        OR OLD.owner_name <> NEW.owner_name
        OR OLD.unique_name <> NEW.unique_name
        OR (NEW.target_suffix IS NULL <> OLD.target_suffix IS NULL)
        OR COALESCE(OLD.target_suffix, '') <> COALESCE(NEW.target_suffix, '')
        OR OLD.name <> NEW.name
        OR OLD.owner <> NEW.owner
        OR COALESCE(OLD.product, -1) <> COALESCE(NEW.product, -1)
        OR COALESCE(OLD.distroseries, -1) <> COALESCE(NEW.distroseries, -1)
        OR COALESCE(OLD.sourcepackagename, -1)
            <> COALESCE(NEW.sourcepackagename, -1)) THEN
        needs_update := TRUE;
    END IF;

    IF needs_update THEN
        SELECT
            Person.name AS owner_name,
            COALESCE(Product.name, SPN.name) AS target_suffix,
            '~' || Person.name || '/' || COALESCE(
                Product.name,
                Distribution.name || '/' || Distroseries.name
                    || '/' || SPN.name,
                '+junk') || '/' || NEW.name AS unique_name
        INTO NEW.owner_name, NEW.target_suffix, NEW.unique_name
        FROM Person
        LEFT OUTER JOIN DistroSeries ON NEW.distroseries = DistroSeries.id
        LEFT OUTER JOIN Product ON NEW.product = Product.id
        LEFT OUTER JOIN Distribution
            ON Distroseries.distribution = Distribution.id
        LEFT OUTER JOIN SourcepackageName AS SPN
            ON SPN.id = NEW.sourcepackagename
        WHERE Person.id = NEW.owner;
    END IF;

    RETURN NEW;
END;
$$;


COMMENT ON FUNCTION update_branch_name_cache() IS 'Maintain the cached name columns in Branch.';


CREATE FUNCTION update_database_disk_utilization() RETURNS void
    LANGUAGE sql SECURITY DEFINER
    SET search_path TO public
    AS $$
    INSERT INTO DatabaseDiskUtilization
    SELECT
        CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
        namespace, name,
        sub_namespace, sub_name,
        kind,
        (namespace || '.' ||  name || COALESCE(
                '/' || sub_namespace || '.' || sub_name, '')) AS sort,
        (stat).table_len,
        (stat).tuple_count,
        (stat).tuple_len,
        (stat).tuple_percent,
        (stat).dead_tuple_count,
        (stat).dead_tuple_len,
        (stat).dead_tuple_percent,
        (stat).free_space,
        (stat).free_percent
    FROM (
        SELECT
            pg_namespace.nspname AS namespace,
            pg_class.relname AS name,
            NULL AS sub_namespace,
            NULL AS sub_name,
            pg_class.relkind AS kind,
            pgstattuple(pg_class.oid) AS stat
        FROM pg_class, pg_namespace
        WHERE
            pg_class.relnamespace = pg_namespace.oid
            AND pg_class.relkind = 'r'
            AND pg_table_is_visible(pg_class.oid)

        UNION ALL
        
        SELECT
            pg_namespace_table.nspname AS namespace,
            pg_class_table.relname AS name,
            pg_namespace_index.nspname AS sub_namespace,
            pg_class_index.relname AS sub_name,
            pg_class_index.relkind AS kind,
            pgstattuple(pg_class_index.oid) AS stat
        FROM
            pg_namespace AS pg_namespace_table,
            pg_namespace AS pg_namespace_index,
            pg_class AS pg_class_table,
            pg_class AS pg_class_index,
            pg_index
        WHERE
            pg_class_index.relkind = 'i'
            AND pg_table_is_visible(pg_class_table.oid)
            AND pg_class_index.relnamespace = pg_namespace_index.oid
            AND pg_class_table.relnamespace = pg_namespace_table.oid
            AND pg_index.indexrelid = pg_class_index.oid
            AND pg_index.indrelid = pg_class_table.oid

        UNION ALL

        -- TOAST tables
        SELECT
            pg_namespace_table.nspname AS namespace,
            pg_class_table.relname AS name,
            pg_namespace_toast.nspname AS sub_namespace,
            pg_class_toast.relname AS sub_name,
            pg_class_toast.relkind AS kind,
            pgstattuple(pg_class_toast.oid) AS stat
        FROM
            pg_namespace AS pg_namespace_table,
            pg_namespace AS pg_namespace_toast,
            pg_class AS pg_class_table,
            pg_class AS pg_class_toast
        WHERE
            pg_class_toast.relnamespace = pg_namespace_toast.oid
            AND pg_table_is_visible(pg_class_table.oid)
            AND pg_class_table.relnamespace = pg_namespace_table.oid
            AND pg_class_toast.oid = pg_class_table.reltoastrelid

        UNION ALL

        -- TOAST indexes
        SELECT
            pg_namespace_table.nspname AS namespace,
            pg_class_table.relname AS name,
            pg_namespace_index.nspname AS sub_namespace,
            pg_class_index.relname AS sub_name,
            pg_class_index.relkind AS kind,
            pgstattuple(pg_class_index.oid) AS stat
        FROM
            pg_namespace AS pg_namespace_table,
            pg_namespace AS pg_namespace_index,
            pg_class AS pg_class_table,
            pg_class AS pg_class_index,
            pg_class AS pg_class_toast
        WHERE
            pg_class_table.relnamespace = pg_namespace_table.oid
            AND pg_table_is_visible(pg_class_table.oid)
            AND pg_class_index.relnamespace = pg_namespace_index.oid
            AND pg_class_table.reltoastrelid = pg_class_toast.oid
            AND pg_class_index.oid = pg_class_toast.reltoastidxid
        ) AS whatever;
$$;


CREATE FUNCTION update_database_stats() RETURNS void
    LANGUAGE plpythonu SECURITY DEFINER
    SET search_path TO public
    AS $_$
    import re
    import subprocess

    # Prune DatabaseTableStats and insert current data.
    # First, detect if the statistics have been reset.
    stats_reset = plpy.execute("""
        SELECT *
        FROM
            pg_catalog.pg_stat_user_tables AS NowStat,
            DatabaseTableStats AS LastStat
        WHERE
            LastStat.date_created = (
                SELECT max(date_created) FROM DatabaseTableStats)
            AND NowStat.schemaname = LastStat.schemaname
            AND NowStat.relname = LastStat.relname
            AND (
                NowStat.seq_scan < LastStat.seq_scan
                OR NowStat.idx_scan < LastStat.idx_scan
                OR NowStat.n_tup_ins < LastStat.n_tup_ins
                OR NowStat.n_tup_upd < LastStat.n_tup_upd
                OR NowStat.n_tup_del < LastStat.n_tup_del
                OR NowStat.n_tup_hot_upd < LastStat.n_tup_hot_upd)
        LIMIT 1
        """, 1).nrows() > 0
    if stats_reset:
        # The database stats have been reset. We cannot calculate
        # deltas because we do not know when this happened. So we trash
        # our records as they are now useless to us. We could be more
        # sophisticated about this, but this should only happen
        # when an admin explicitly resets the statistics or if the
        # database is rebuilt.
        plpy.notice("Stats wraparound. Purging DatabaseTableStats")
        plpy.execute("DELETE FROM DatabaseTableStats")
    else:
        plpy.execute("""
            DELETE FROM DatabaseTableStats
            WHERE date_created < (CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
                - CAST('21 days' AS interval));
            """)
    # Insert current data.
    plpy.execute("""
        INSERT INTO DatabaseTableStats
            SELECT
                CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
                schemaname, relname, seq_scan, seq_tup_read,
                coalesce(idx_scan, 0), coalesce(idx_tup_fetch, 0),
                n_tup_ins, n_tup_upd, n_tup_del,
                n_tup_hot_upd, n_live_tup, n_dead_tup, last_vacuum,
                last_autovacuum, last_analyze, last_autoanalyze
            FROM pg_catalog.pg_stat_user_tables;
        """)

    # Prune DatabaseCpuStats. Calculate CPU utilization information
    # and insert current data.
    plpy.execute("""
        DELETE FROM DatabaseCpuStats
        WHERE date_created < (CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
            - CAST('21 days' AS interval));
        """)
    dbname = plpy.execute(
        "SELECT current_database() AS dbname", 1)[0]['dbname']
    ps = subprocess.Popen(
        ["ps", "-C", "postgres", "--no-headers", "-o", "cp,args"],
        stdin=subprocess.PIPE, stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT)
    stdout, stderr = ps.communicate()
    cpus = {}
    # We make the username match non-greedy so the trailing \d eats
    # trailing digits from the database username. This collapses
    # lpnet1, lpnet2 etc. into just lpnet.
    ps_re = re.compile(
        r"(?m)^\s*(\d+)\spostgres:\s(\w+?)\d*\s%s\s" % dbname)
    for ps_match in ps_re.finditer(stdout):
        cpu, username = ps_match.groups()
        cpus[username] = int(cpu) + cpus.setdefault(username, 0)
    cpu_ins = plpy.prepare(
        "INSERT INTO DatabaseCpuStats (username, cpu) VALUES ($1, $2)",
        ["text", "integer"])
    for cpu_tuple in cpus.items():
        plpy.execute(cpu_ins, cpu_tuple)
$_$;


COMMENT ON FUNCTION update_database_stats() IS 'Copies rows from pg_stat_user_tables into DatabaseTableStats. We use a stored procedure because it is problematic for us to grant permissions on objects in the pg_catalog schema.';


CREATE FUNCTION update_replication_lag_cache() RETURNS boolean
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
    BEGIN
        DELETE FROM DatabaseReplicationLag;
        INSERT INTO DatabaseReplicationLag (node, lag)
            SELECT st_received, st_lag_time FROM _sl.sl_status
            WHERE st_origin = _sl.getlocalnodeid('_sl');
        RETURN TRUE;
    -- Slony-I not installed here - non-replicated setup.
    EXCEPTION
        WHEN invalid_schema_name THEN
            RETURN FALSE;
        WHEN undefined_table THEN
            RETURN FALSE;
    END;
$$;


COMMENT ON FUNCTION update_replication_lag_cache() IS 'Updates the DatabaseReplicationLag materialized view.';


CREATE FUNCTION update_transitively_private(start_branch integer, _root_branch integer DEFAULT NULL::integer, _root_transitively_private boolean DEFAULT NULL::boolean) RETURNS void
    LANGUAGE plpgsql SECURITY DEFINER
    SET search_path TO public
    AS $$
DECLARE
    root_transitively_private boolean := _root_transitively_private;
    root_branch int := _root_branch;
BEGIN
    IF root_transitively_private IS NULL THEN
        -- We can't just trust the transitively_private flag of the
        -- branch we are stacked on, as if we are updating multiple
        -- records they will be updated in an indeterminate order.
        -- We need a recursive query.
        UPDATE Branch SET transitively_private = (
            WITH RECURSIVE stacked_branches AS (
                SELECT
                    top_branch.id, top_branch.stacked_on, top_branch.private
                FROM Branch AS top_branch
                WHERE top_branch.id = start_branch
                UNION ALL
                SELECT
                    sub_branch.id, sub_branch.stacked_on, sub_branch.private
                FROM stacked_branches, Branch AS sub_branch
                WHERE
                    stacked_branches.stacked_on = sub_branch.id
                    AND stacked_branches.stacked_on != start_branch
                    -- Shortcircuit. No need to recurse if already private.
                    AND stacked_branches.private IS FALSE
                    )
            SELECT COUNT(*) > 0
            FROM stacked_branches
            WHERE private IS TRUE)
        WHERE Branch.id = start_branch
        RETURNING transitively_private INTO root_transitively_private;
        root_branch := start_branch;
    ELSE
        -- Now we have calculated the correct transitively_private flag
        -- we can trust it.
        UPDATE Branch SET
            transitively_private = GREATEST(private, root_transitively_private)
        WHERE id = root_branch;
    END IF;

    -- Recurse to branches stacked on this one.
    PERFORM update_transitively_private(
        start_branch, id, GREATEST(private, root_transitively_private))
    FROM Branch WHERE stacked_on = root_branch AND id != start_branch;
END;
$$;


COMMENT ON FUNCTION update_transitively_private(start_branch integer, _root_branch integer, _root_transitively_private boolean) IS 'A branch is transitively private if it is private or is stacked on any transitively private branches.';


CREATE FUNCTION valid_absolute_url(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $$
    from urlparse import urlparse, uses_netloc
    # Extend list of schemes that specify netloc. We can drop sftp
    # with Python 2.5 in the DB.
    if 'git' not in uses_netloc:
        uses_netloc.insert(0, 'sftp')
        uses_netloc.insert(0, 'bzr')
        uses_netloc.insert(0, 'bzr+ssh')
        uses_netloc.insert(0, 'ssh') # Mercurial
        uses_netloc.insert(0, 'git')
    (scheme, netloc, path, params, query, fragment) = urlparse(args[0])
    return bool(scheme and netloc)
$$;


COMMENT ON FUNCTION valid_absolute_url(text) IS 'Ensure the given test is a valid absolute URL, containing both protocol and network location';


CREATE FUNCTION valid_branch_name(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $$
    import re
    name = args[0]
    pat = r"^(?i)[a-z0-9][a-z0-9+\.\-@_]*\Z"
    if re.match(pat, name):
        return 1
    return 0
$$;


COMMENT ON FUNCTION valid_branch_name(text) IS 'validate a branch name.

    As per valid_name, except we allow uppercase and @';


CREATE FUNCTION valid_cve(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $_$
    import re
    name = args[0]
    pat = r"^(19|20)\d{2}-\d{4}$"
    if re.match(pat, name):
        return 1
    return 0
$_$;


COMMENT ON FUNCTION valid_cve(text) IS 'validate a common vulnerability number as defined on www.cve.mitre.org, minus the CAN- or CVE- prefix.';


CREATE FUNCTION valid_debian_version(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $_$
    import re
    m = re.search("""^(?ix)
        ([0-9]+:)?
        ([0-9a-z][a-z0-9+:.~-]*?)
        (-[a-z0-9+.~]+)?
        $""", args[0])
    if m is None:
        return 0
    epoch, version, revision = m.groups()
    if not epoch:
        # Can''t contain : if no epoch
        if ":" in version:
            return 0
    if not revision:
        # Can''t contain - if no revision
        if "-" in version:
            return 0
    return 1
$_$;


COMMENT ON FUNCTION valid_debian_version(text) IS 'validate a version number as per Debian Policy';


CREATE FUNCTION valid_fingerprint(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $$
    import re
    if re.match(r"[\dA-F]{40}", args[0]) is not None:
        return 1
    else:
        return 0
$$;


COMMENT ON FUNCTION valid_fingerprint(text) IS 'Returns true if passed a valid GPG fingerprint. Valid GPG fingerprints are a 40 character long hexadecimal number in uppercase.';


CREATE FUNCTION valid_keyid(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $$
    import re
    if re.match(r"[\dA-F]{8}", args[0]) is not None:
        return 1
    else:
        return 0
$$;


COMMENT ON FUNCTION valid_keyid(text) IS 'Returns true if passed a valid GPG keyid. Valid GPG keyids are an 8 character long hexadecimal number in uppercase (in reality, they are 16 characters long but we are using the ''common'' definition.';


CREATE FUNCTION valid_regexp(text) RETURNS boolean
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $$
    import re
    try:
        re.compile(args[0])
    except:
        return False
    else:
        return True
$$;


COMMENT ON FUNCTION valid_regexp(text) IS 'Returns true if the input can be compiled as a regular expression.';


CREATE FUNCTION version_sort_key(version text) RETURNS text
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $$
    # If this method is altered, then any functional indexes using it
    # need to be rebuilt.
    import re

    [version] = args

    def substitute_filled_numbers(match):
        # Prepend "~" so that version numbers will show up first
        # when sorted descending, i.e. [3, 2c, 2b, 1, c, b, a] instead
        # of [c, b, a, 3, 2c, 2b, 1]. "~" has the highest ASCII value
        # of visible ASCII characters.
        return '~' + match.group(0).zfill(5)

    return re.sub(u'\d+', substitute_filled_numbers, version)
$$;


COMMENT ON FUNCTION version_sort_key(version text) IS 'Sort a field as version numbers that do not necessarily conform to debian package versions (For example, when "2-2" should be considered greater than "1:1"). debversion_sort_key() should be used for debian versions. Numbers will be sorted after letters unlike typical ASCII, so that a descending sort will put the latest version number that starts with a number instead of a letter will be at the top. E.g. ascending is [a, z, 1, 9] and descending is [9, 1, z, a].';


CREATE FUNCTION you_are_your_own_member() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
    BEGIN
        INSERT INTO TeamParticipation (person, team)
            VALUES (NEW.id, NEW.id);
        RETURN NULL;
    END;
$$;


COMMENT ON FUNCTION you_are_your_own_member() IS 'Trigger function to ensure that every row added to the Person table gets a corresponding row in the TeamParticipation table, as per the TeamParticipationUsage page on the Launchpad wiki';


SET search_path = ts2, pg_catalog;

CREATE FUNCTION _ftq(text) RETURNS text
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $_$
        import re

        # I think this method would be more robust if we used a real
        # tokenizer and parser to generate the query string, but we need
        # something suitable for use as a stored procedure which currently
        # means no external dependancies.

        # Convert to Unicode
        query = args[0].decode('utf8')
        ## plpy.debug('1 query is %s' % repr(query))

        # Normalize whitespace
        query = re.sub("(?u)\s+"," ", query)

        # Convert AND, OR, NOT and - to tsearch2 punctuation
        query = re.sub(r"(?u)(?:^|\s)-([\w\(])", r" !\1", query)
        query = re.sub(r"(?u)\bAND\b", "&", query)
        query = re.sub(r"(?u)\bOR\b", "|", query)
        query = re.sub(r"(?u)\bNOT\b", " !", query)
        ## plpy.debug('2 query is %s' % repr(query))

        # Deal with unwanted punctuation. We convert strings of punctuation
        # inside words to a '-' character for the hypenation handling below
        # to deal with further. Outside of words we replace with whitespace.
        # We don't mess with -&|!()' as they are handled later.
        #punctuation = re.escape(r'`~@#$%^*+=[]{}:;"<>,.?\/')
        punctuation = r"[^\w\s\-\&\|\!\(\)']"
        query = re.sub(r"(?u)(\w)%s+(\w)" % (punctuation,), r"\1-\2", query)
        query = re.sub(r"(?u)%s+" % (punctuation,), " ", query)
        ## plpy.debug('3 query is %s' % repr(query))

        # Strip ! characters inside and at the end of a word
        query = re.sub(r"(?u)(?<=\w)[\!]+", " ", query)

        # Now that we have handle case sensitive booleans, convert to lowercase
        query = query.lower()

        # Convert foo-bar to ((foo&bar)|foobar) and foo-bar-baz to
        # ((foo&bar&baz)|foobarbaz)
        def hyphen_repl(match):
            bits = match.group(0).split("-")
            return "((%s)|%s)" % ("&".join(bits), "".join(bits))
        query = re.sub(r"(?u)\b\w+-[\w\-]+\b", hyphen_repl, query)
        ## plpy.debug('4 query is %s' % repr(query))

        # Any remaining - characters are spurious
        query = query.replace('-','')

        # Remove unpartnered bracket on the left and right
        query = re.sub(r"(?ux) ^ ( [^(]* ) \)", r"(\1)", query)
        query = re.sub(r"(?ux) \( ( [^)]* ) $", r"(\1)", query)

        # Remove spurious brackets
        query = re.sub(r"(?u)\(([^\&\|]*?)\)", r" \1 ", query)
        ## plpy.debug('5 query is %s' % repr(query))

        # Insert & between tokens without an existing boolean operator
        # ( not proceeded by (|&!
        query = re.sub(r"(?u)(?<![\(\|\&\!])\s*\(", "&(", query)
        ## plpy.debug('6 query is %s' % repr(query))
        # ) not followed by )|&
        query = re.sub(r"(?u)\)(?!\s*(\)|\||\&|\s*$))", ")&", query)
        ## plpy.debug('6.1 query is %s' % repr(query))
        # Whitespace not proceded by (|&! not followed by &|
        query = re.sub(r"(?u)(?<![\(\|\&\!\s])\s+(?![\&\|\s])", "&", query)
        ## plpy.debug('7 query is %s' % repr(query))

        # Detect and repair syntax errors - we are lenient because
        # this input is generally from users.

        # Fix unbalanced brackets
        openings = query.count("(")
        closings = query.count(")")
        if openings > closings:
            query = query + " ) "*(openings-closings)
        elif closings > openings:
            query = " ( "*(closings-openings) + query
        ## plpy.debug('8 query is %s' % repr(query))

        # Strip ' character that do not have letters on both sides
        query = re.sub(r"(?u)((?<!\w)'|'(?!\w))", "", query)

        # Brackets containing nothing but whitespace and booleans, recursive
        last = ""
        while last != query:
            last = query
            query = re.sub(r"(?u)\([\s\&\|\!]*\)", "", query)
        ## plpy.debug('9 query is %s' % repr(query))

        # An & or | following a (
        query = re.sub(r"(?u)(?<=\()[\&\|\s]+", "", query)
        ## plpy.debug('10 query is %s' % repr(query))

        # An &, | or ! immediatly before a )
        query = re.sub(r"(?u)[\&\|\!\s]*[\&\|\!]+\s*(?=\))", "", query)
        ## plpy.debug('11 query is %s' % repr(query))

        # An &,| or ! followed by another boolean.
        query = re.sub(r"(?ux) \s* ( [\&\|\!] ) [\s\&\|]+", r"\1", query)
        ## plpy.debug('12 query is %s' % repr(query))

        # Leading & or |
        query = re.sub(r"(?u)^[\s\&\|]+", "", query)
        ## plpy.debug('13 query is %s' % repr(query))

        # Trailing &, | or !
        query = re.sub(r"(?u)[\&\|\!\s]+$", "", query)
        ## plpy.debug('14 query is %s' % repr(query))

        # If we have nothing but whitespace and tsearch2 operators,
        # return NULL.
        if re.search(r"(?u)^[\&\|\!\s\(\)]*$", query) is not None:
            return None

        # Convert back to UTF-8
        query = query.encode('utf8')
        ## plpy.debug('15 query is %s' % repr(query))
        
        return query or None
        $_$;


CREATE FUNCTION _get_parser_from_curcfg() RETURNS text
    LANGUAGE sql IMMUTABLE STRICT
    AS $$select prsname::text from pg_catalog.pg_ts_parser p join pg_ts_config c on cfgparser = p.oid where c.oid = show_curcfg();$$;


CREATE FUNCTION concat(pg_catalog.tsvector, pg_catalog.tsvector) RETURNS pg_catalog.tsvector
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsvector_concat$$;


CREATE FUNCTION dex_init(internal) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_dex_init';


CREATE FUNCTION dex_lexize(internal, internal, integer) RETURNS internal
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_dex_lexize';


CREATE FUNCTION ftiupdate() RETURNS trigger
    LANGUAGE plpythonu
    AS $_$
    new = TD["new"]
    args = TD["args"][:]

    # Short circuit if none of the relevant columns have been
    # modified and fti is not being set to NULL (setting the fti
    # column to NULL is thus how we can force a rebuild of the fti
    # column).
    if TD["event"] == "UPDATE" and new["fti"] != None:
        old = TD["old"]
        relevant_modification = False
        for column_name in args[::2]:
            if new[column_name] != old[column_name]:
                relevant_modification = True
                break
        if not relevant_modification:
            return "OK"

    # Generate an SQL statement that turns the requested
    # column values into a weighted tsvector
    sql = []
    for i in range(0, len(args), 2):
        sql.append(
                "ts2.setweight(ts2.to_tsvector('default', coalesce("
                "substring(ltrim($%d) from 1 for 2500),'')),"
                "CAST($%d AS \"char\"))" % (i + 1, i + 2))
        args[i] = new[args[i]]

    sql = "SELECT %s AS fti" % "||".join(sql)

    # Execute and store in the fti column
    plan = plpy.prepare(sql, ["text", "char"] * (len(args)/2))
    new["fti"] = plpy.execute(plan, args, 1)[0]["fti"]

    # Tell PostgreSQL we have modified the data
    return "MODIFY"
$_$;


COMMENT ON FUNCTION ftiupdate() IS 'Trigger function that keeps the fti tsvector column up to date.';


CREATE FUNCTION ftq(text) RETURNS pg_catalog.tsquery
    LANGUAGE plpythonu IMMUTABLE STRICT
    AS $_$
        import re

        # I think this method would be more robust if we used a real
        # tokenizer and parser to generate the query string, but we need
        # something suitable for use as a stored procedure which currently
        # means no external dependancies.

        # Convert to Unicode
        query = args[0].decode('utf8')
        ## plpy.debug('1 query is %s' % repr(query))

        # Normalize whitespace
        query = re.sub("(?u)\s+"," ", query)

        # Convert AND, OR, NOT and - to tsearch2 punctuation
        query = re.sub(r"(?u)(?:^|\s)-([\w\(])", r" !\1", query)
        query = re.sub(r"(?u)\bAND\b", "&", query)
        query = re.sub(r"(?u)\bOR\b", "|", query)
        query = re.sub(r"(?u)\bNOT\b", " !", query)
        ## plpy.debug('2 query is %s' % repr(query))

        # Deal with unwanted punctuation. We convert strings of punctuation
        # inside words to a '-' character for the hypenation handling below
        # to deal with further. Outside of words we replace with whitespace.
        # We don't mess with -&|!()' as they are handled later.
        #punctuation = re.escape(r'`~@#$%^*+=[]{}:;"<>,.?\/')
        punctuation = r"[^\w\s\-\&\|\!\(\)']"
        query = re.sub(r"(?u)(\w)%s+(\w)" % (punctuation,), r"\1-\2", query)
        query = re.sub(r"(?u)%s+" % (punctuation,), " ", query)
        ## plpy.debug('3 query is %s' % repr(query))

        # Strip ! characters inside and at the end of a word
        query = re.sub(r"(?u)(?<=\w)[\!]+", " ", query)

        # Now that we have handle case sensitive booleans, convert to lowercase
        query = query.lower()

        # Convert foo-bar to ((foo&bar)|foobar) and foo-bar-baz to
        # ((foo&bar&baz)|foobarbaz)
        def hyphen_repl(match):
            bits = match.group(0).split("-")
            return "((%s)|%s)" % ("&".join(bits), "".join(bits))
        query = re.sub(r"(?u)\b\w+-[\w\-]+\b", hyphen_repl, query)
        ## plpy.debug('4 query is %s' % repr(query))

        # Any remaining - characters are spurious
        query = query.replace('-','')

        # Remove unpartnered bracket on the left and right
        query = re.sub(r"(?ux) ^ ( [^(]* ) \)", r"(\1)", query)
        query = re.sub(r"(?ux) \( ( [^)]* ) $", r"(\1)", query)

        # Remove spurious brackets
        query = re.sub(r"(?u)\(([^\&\|]*?)\)", r" \1 ", query)
        ## plpy.debug('5 query is %s' % repr(query))

        # Insert & between tokens without an existing boolean operator
        # ( not proceeded by (|&!
        query = re.sub(r"(?u)(?<![\(\|\&\!])\s*\(", "&(", query)
        ## plpy.debug('6 query is %s' % repr(query))
        # ) not followed by )|&
        query = re.sub(r"(?u)\)(?!\s*(\)|\||\&|\s*$))", ")&", query)
        ## plpy.debug('6.1 query is %s' % repr(query))
        # Whitespace not proceded by (|&! not followed by &|
        query = re.sub(r"(?u)(?<![\(\|\&\!\s])\s+(?![\&\|\s])", "&", query)
        ## plpy.debug('7 query is %s' % repr(query))

        # Detect and repair syntax errors - we are lenient because
        # this input is generally from users.

        # Fix unbalanced brackets
        openings = query.count("(")
        closings = query.count(")")
        if openings > closings:
            query = query + " ) "*(openings-closings)
        elif closings > openings:
            query = " ( "*(closings-openings) + query
        ## plpy.debug('8 query is %s' % repr(query))

        # Strip ' character that do not have letters on both sides
        query = re.sub(r"(?u)((?<!\w)'|'(?!\w))", "", query)

        # Brackets containing nothing but whitespace and booleans, recursive
        last = ""
        while last != query:
            last = query
            query = re.sub(r"(?u)\([\s\&\|\!]*\)", "", query)
        ## plpy.debug('9 query is %s' % repr(query))

        # An & or | following a (
        query = re.sub(r"(?u)(?<=\()[\&\|\s]+", "", query)
        ## plpy.debug('10 query is %s' % repr(query))

        # An &, | or ! immediatly before a )
        query = re.sub(r"(?u)[\&\|\!\s]*[\&\|\!]+\s*(?=\))", "", query)
        ## plpy.debug('11 query is %s' % repr(query))

        # An &,| or ! followed by another boolean.
        query = re.sub(r"(?ux) \s* ( [\&\|\!] ) [\s\&\|]+", r"\1", query)
        ## plpy.debug('12 query is %s' % repr(query))

        # Leading & or |
        query = re.sub(r"(?u)^[\s\&\|]+", "", query)
        ## plpy.debug('13 query is %s' % repr(query))

        # Trailing &, | or !
        query = re.sub(r"(?u)[\&\|\!\s]+$", "", query)
        ## plpy.debug('14 query is %s' % repr(query))

        # If we have nothing but whitespace and tsearch2 operators,
        # return NULL.
        if re.search(r"(?u)^[\&\|\!\s\(\)]*$", query) is not None:
            return None

        # Convert back to UTF-8
        query = query.encode('utf8')
        ## plpy.debug('15 query is %s' % repr(query))
        
        p = plpy.prepare("SELECT to_tsquery('default', $1) AS x", ["text"])
        query = plpy.execute(p, [query], 1)[0]["x"]
        return query or None
        $_$;


COMMENT ON FUNCTION ftq(text) IS 'Convert a string to an unparsed tsearch2 query';


CREATE FUNCTION get_covers(pg_catalog.tsvector, pg_catalog.tsquery) RETURNS text
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_get_covers';


CREATE FUNCTION headline(oid, text, pg_catalog.tsquery, text) RETURNS text
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_headline_byid_opt$$;


CREATE FUNCTION headline(oid, text, pg_catalog.tsquery) RETURNS text
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_headline_byid$$;


CREATE FUNCTION headline(text, text, pg_catalog.tsquery, text) RETURNS text
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/tsearch2', 'tsa_headline_byname';


CREATE FUNCTION headline(text, text, pg_catalog.tsquery) RETURNS text
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/tsearch2', 'tsa_headline_byname';


CREATE FUNCTION headline(text, pg_catalog.tsquery, text) RETURNS text
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_headline_opt$$;


CREATE FUNCTION headline(text, pg_catalog.tsquery) RETURNS text
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_headline$$;


CREATE FUNCTION length(pg_catalog.tsvector) RETURNS integer
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsvector_length$$;


CREATE FUNCTION lexize(oid, text) RETURNS text[]
    LANGUAGE internal STRICT
    AS $$ts_lexize$$;


CREATE FUNCTION lexize(text, text) RETURNS text[]
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_lexize_byname';


CREATE FUNCTION lexize(text) RETURNS text[]
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_lexize_bycurrent';


CREATE FUNCTION numnode(pg_catalog.tsquery) RETURNS integer
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsquery_numnode$$;


CREATE FUNCTION parse(oid, text) RETURNS SETOF tokenout
    LANGUAGE internal STRICT
    AS $$ts_parse_byid$$;


CREATE FUNCTION parse(text, text) RETURNS SETOF tokenout
    LANGUAGE internal STRICT
    AS $$ts_parse_byname$$;


CREATE FUNCTION parse(text) RETURNS SETOF tokenout
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_parse_current';


CREATE FUNCTION plainto_tsquery(oid, text) RETURNS pg_catalog.tsquery
    LANGUAGE internal IMMUTABLE STRICT
    AS $$plainto_tsquery_byid$$;


CREATE FUNCTION plainto_tsquery(text, text) RETURNS pg_catalog.tsquery
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/tsearch2', 'tsa_plainto_tsquery_name';


CREATE FUNCTION plainto_tsquery(text) RETURNS pg_catalog.tsquery
    LANGUAGE internal IMMUTABLE STRICT
    AS $$plainto_tsquery$$;


CREATE FUNCTION prsd_end(internal) RETURNS void
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_prsd_end';


CREATE FUNCTION prsd_getlexeme(internal, internal, internal) RETURNS integer
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_prsd_getlexeme';


CREATE FUNCTION prsd_headline(internal, internal, internal) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_prsd_headline';


CREATE FUNCTION prsd_lextype(internal) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_prsd_lextype';


CREATE FUNCTION prsd_start(internal, integer) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_prsd_start';


CREATE FUNCTION querytree(pg_catalog.tsquery) RETURNS text
    LANGUAGE internal STRICT
    AS $$tsquerytree$$;


CREATE FUNCTION rank(real[], pg_catalog.tsvector, pg_catalog.tsquery) RETURNS real
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_rank_wtt$$;


CREATE FUNCTION rank(real[], pg_catalog.tsvector, pg_catalog.tsquery, integer) RETURNS real
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_rank_wttf$$;


CREATE FUNCTION rank(pg_catalog.tsvector, pg_catalog.tsquery) RETURNS real
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_rank_tt$$;


CREATE FUNCTION rank(pg_catalog.tsvector, pg_catalog.tsquery, integer) RETURNS real
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_rank_ttf$$;


CREATE FUNCTION rank_cd(real[], pg_catalog.tsvector, pg_catalog.tsquery) RETURNS real
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_rankcd_wtt$$;


CREATE FUNCTION rank_cd(real[], pg_catalog.tsvector, pg_catalog.tsquery, integer) RETURNS real
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_rankcd_wttf$$;


CREATE FUNCTION rank_cd(pg_catalog.tsvector, pg_catalog.tsquery) RETURNS real
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_rankcd_tt$$;


CREATE FUNCTION rank_cd(pg_catalog.tsvector, pg_catalog.tsquery, integer) RETURNS real
    LANGUAGE internal IMMUTABLE STRICT
    AS $$ts_rankcd_ttf$$;


CREATE FUNCTION reset_tsearch() RETURNS void
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_reset_tsearch';


CREATE FUNCTION rewrite(pg_catalog.tsquery, text) RETURNS pg_catalog.tsquery
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsquery_rewrite_query$$;


CREATE FUNCTION rewrite(pg_catalog.tsquery, pg_catalog.tsquery, pg_catalog.tsquery) RETURNS pg_catalog.tsquery
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsquery_rewrite$$;


CREATE FUNCTION rewrite_accum(pg_catalog.tsquery, pg_catalog.tsquery[]) RETURNS pg_catalog.tsquery
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_rewrite_accum';


CREATE FUNCTION rewrite_finish(pg_catalog.tsquery) RETURNS pg_catalog.tsquery
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_rewrite_finish';


CREATE FUNCTION set_curcfg(integer) RETURNS void
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_set_curcfg';


CREATE FUNCTION set_curcfg(text) RETURNS void
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_set_curcfg_byname';


CREATE FUNCTION set_curdict(integer) RETURNS void
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_set_curdict';


CREATE FUNCTION set_curdict(text) RETURNS void
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_set_curdict_byname';


CREATE FUNCTION set_curprs(integer) RETURNS void
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_set_curprs';


CREATE FUNCTION set_curprs(text) RETURNS void
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_set_curprs_byname';


CREATE FUNCTION setweight(pg_catalog.tsvector, "char") RETURNS pg_catalog.tsvector
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsvector_setweight$$;


CREATE FUNCTION show_curcfg() RETURNS oid
    LANGUAGE internal STABLE STRICT
    AS $$get_current_ts_config$$;


CREATE FUNCTION snb_en_init(internal) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_snb_en_init';


CREATE FUNCTION snb_lexize(internal, internal, integer) RETURNS internal
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_snb_lexize';


CREATE FUNCTION snb_ru_init(internal) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_snb_ru_init';


CREATE FUNCTION snb_ru_init_koi8(internal) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_snb_ru_init_koi8';


CREATE FUNCTION snb_ru_init_utf8(internal) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_snb_ru_init_utf8';


CREATE FUNCTION spell_init(internal) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_spell_init';


CREATE FUNCTION spell_lexize(internal, internal, integer) RETURNS internal
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_spell_lexize';


CREATE FUNCTION stat(text) RETURNS SETOF statinfo
    LANGUAGE internal STRICT
    AS $$ts_stat1$$;


CREATE FUNCTION stat(text, text) RETURNS SETOF statinfo
    LANGUAGE internal STRICT
    AS $$ts_stat2$$;


CREATE FUNCTION strip(pg_catalog.tsvector) RETURNS pg_catalog.tsvector
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsvector_strip$$;


CREATE FUNCTION syn_init(internal) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_syn_init';


CREATE FUNCTION syn_lexize(internal, internal, integer) RETURNS internal
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_syn_lexize';


CREATE FUNCTION thesaurus_init(internal) RETURNS internal
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_thesaurus_init';


CREATE FUNCTION thesaurus_lexize(internal, internal, integer, internal) RETURNS internal
    LANGUAGE c STRICT
    AS '$libdir/tsearch2', 'tsa_thesaurus_lexize';


CREATE FUNCTION to_tsquery(oid, text) RETURNS pg_catalog.tsquery
    LANGUAGE internal IMMUTABLE STRICT
    AS $$to_tsquery_byid$$;


CREATE FUNCTION to_tsquery(text, text) RETURNS pg_catalog.tsquery
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/tsearch2', 'tsa_to_tsquery_name';


CREATE FUNCTION to_tsquery(text) RETURNS pg_catalog.tsquery
    LANGUAGE internal IMMUTABLE STRICT
    AS $$to_tsquery$$;


CREATE FUNCTION to_tsvector(oid, text) RETURNS pg_catalog.tsvector
    LANGUAGE internal IMMUTABLE STRICT
    AS $$to_tsvector_byid$$;


CREATE FUNCTION to_tsvector(text, text) RETURNS pg_catalog.tsvector
    LANGUAGE c IMMUTABLE STRICT
    AS '$libdir/tsearch2', 'tsa_to_tsvector_name';


CREATE FUNCTION to_tsvector(text) RETURNS pg_catalog.tsvector
    LANGUAGE internal IMMUTABLE STRICT
    AS $$to_tsvector$$;


CREATE FUNCTION token_type(integer) RETURNS SETOF tokentype
    LANGUAGE internal STRICT ROWS 16
    AS $$ts_token_type_byid$$;


CREATE FUNCTION token_type(text) RETURNS SETOF tokentype
    LANGUAGE internal STRICT ROWS 16
    AS $$ts_token_type_byname$$;


CREATE FUNCTION token_type() RETURNS SETOF tokentype
    LANGUAGE c STRICT ROWS 16
    AS '$libdir/tsearch2', 'tsa_token_type_current';


CREATE FUNCTION ts_debug(text) RETURNS SETOF tsdebug
    LANGUAGE sql STRICT
    AS $_$
select
        (select c.cfgname::text from pg_catalog.pg_ts_config as c
         where c.oid = show_curcfg()),
        t.alias as tok_type,
        t.descr as description,
        p.token,
        ARRAY ( SELECT m.mapdict::pg_catalog.regdictionary::pg_catalog.text
                FROM pg_catalog.pg_ts_config_map AS m
                WHERE m.mapcfg = show_curcfg() AND m.maptokentype = p.tokid
                ORDER BY m.mapseqno )
        AS dict_name,
        strip(to_tsvector(p.token)) as tsvector
from
        parse( _get_parser_from_curcfg(), $1 ) as p,
        token_type() as t
where
        t.tokid = p.tokid
$_$;


CREATE FUNCTION tsearch2() RETURNS trigger
    LANGUAGE c
    AS '$libdir/tsearch2', 'tsa_tsearch2';


CREATE FUNCTION tsq_mcontained(pg_catalog.tsquery, pg_catalog.tsquery) RETURNS boolean
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsq_mcontained$$;


CREATE FUNCTION tsq_mcontains(pg_catalog.tsquery, pg_catalog.tsquery) RETURNS boolean
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsq_mcontains$$;


CREATE FUNCTION tsquery_and(pg_catalog.tsquery, pg_catalog.tsquery) RETURNS pg_catalog.tsquery
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsquery_and$$;


CREATE FUNCTION tsquery_not(pg_catalog.tsquery) RETURNS pg_catalog.tsquery
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsquery_not$$;


CREATE FUNCTION tsquery_or(pg_catalog.tsquery, pg_catalog.tsquery) RETURNS pg_catalog.tsquery
    LANGUAGE internal IMMUTABLE STRICT
    AS $$tsquery_or$$;


SET search_path = public, pg_catalog;

CREATE OPERATOR > (
    PROCEDURE = debversion_gt,
    LEFTARG = debversion,
    RIGHTARG = debversion,
    COMMUTATOR = <,
    NEGATOR = >=
);


COMMENT ON OPERATOR > (debversion, debversion) IS 'debversion greater-than';


CREATE AGGREGATE max(debversion) (
    SFUNC = debversion_larger,
    STYPE = debversion,
    SORTOP = >
);


CREATE OPERATOR < (
    PROCEDURE = debversion_lt,
    LEFTARG = debversion,
    RIGHTARG = debversion,
    COMMUTATOR = >,
    NEGATOR = >=
);


COMMENT ON OPERATOR < (debversion, debversion) IS 'debversion less-than';


CREATE AGGREGATE min(debversion) (
    SFUNC = debversion_smaller,
    STYPE = debversion,
    SORTOP = <
);


SET search_path = ts2, pg_catalog;

CREATE AGGREGATE rewrite(pg_catalog.tsquery[]) (
    SFUNC = rewrite_accum,
    STYPE = pg_catalog.tsquery,
    FINALFUNC = rewrite_finish
);


SET search_path = public, pg_catalog;

CREATE OPERATOR <= (
    PROCEDURE = debversion_le,
    LEFTARG = debversion,
    RIGHTARG = debversion,
    COMMUTATOR = >=,
    NEGATOR = >
);


COMMENT ON OPERATOR <= (debversion, debversion) IS 'debversion less-than-or-equal';


CREATE OPERATOR <> (
    PROCEDURE = debversion_ne,
    LEFTARG = debversion,
    RIGHTARG = debversion,
    COMMUTATOR = <>,
    NEGATOR = =
);


COMMENT ON OPERATOR <> (debversion, debversion) IS 'debversion not equal';


CREATE OPERATOR = (
    PROCEDURE = debversion_eq,
    LEFTARG = debversion,
    RIGHTARG = debversion,
    COMMUTATOR = =,
    NEGATOR = <>
);


COMMENT ON OPERATOR = (debversion, debversion) IS 'debversion equal';


CREATE OPERATOR >= (
    PROCEDURE = debversion_ge,
    LEFTARG = debversion,
    RIGHTARG = debversion,
    COMMUTATOR = <=,
    NEGATOR = <
);


COMMENT ON OPERATOR >= (debversion, debversion) IS 'debversion greater-than-or-equal';


CREATE OPERATOR FAMILY debversion_ops USING btree;


CREATE OPERATOR CLASS debversion_ops
    DEFAULT FOR TYPE debversion USING btree AS
    OPERATOR 1 <(debversion,debversion) ,
    OPERATOR 2 <=(debversion,debversion) ,
    OPERATOR 3 =(debversion,debversion) ,
    OPERATOR 4 >=(debversion,debversion) ,
    OPERATOR 5 >(debversion,debversion) ,
    FUNCTION 1 debversion_cmp(debversion,debversion);


CREATE OPERATOR FAMILY debversion_ops USING hash;


CREATE OPERATOR CLASS debversion_ops
    DEFAULT FOR TYPE debversion USING hash AS
    OPERATOR 1 =(debversion,debversion) ,
    FUNCTION 1 debversion_hash(debversion);


SET search_path = ts2, pg_catalog;

CREATE OPERATOR FAMILY tsquery_ops USING btree;


CREATE OPERATOR CLASS tsquery_ops
    FOR TYPE pg_catalog.tsquery USING btree AS
    OPERATOR 1 <(pg_catalog.tsquery,pg_catalog.tsquery) ,
    OPERATOR 2 <=(pg_catalog.tsquery,pg_catalog.tsquery) ,
    OPERATOR 3 =(pg_catalog.tsquery,pg_catalog.tsquery) ,
    OPERATOR 4 >=(pg_catalog.tsquery,pg_catalog.tsquery) ,
    OPERATOR 5 >(pg_catalog.tsquery,pg_catalog.tsquery) ,
    FUNCTION 1 tsquery_cmp(pg_catalog.tsquery,pg_catalog.tsquery);


CREATE OPERATOR FAMILY tsvector_ops USING btree;


CREATE OPERATOR CLASS tsvector_ops
    FOR TYPE pg_catalog.tsvector USING btree AS
    OPERATOR 1 <(pg_catalog.tsvector,pg_catalog.tsvector) ,
    OPERATOR 2 <=(pg_catalog.tsvector,pg_catalog.tsvector) ,
    OPERATOR 3 =(pg_catalog.tsvector,pg_catalog.tsvector) ,
    OPERATOR 4 >=(pg_catalog.tsvector,pg_catalog.tsvector) ,
    OPERATOR 5 >(pg_catalog.tsvector,pg_catalog.tsvector) ,
    FUNCTION 1 tsvector_cmp(pg_catalog.tsvector,pg_catalog.tsvector);


SET search_path = pg_catalog;

CREATE CAST (character AS public.debversion) WITH FUNCTION public.debversion(character);


CREATE CAST (public.debversion AS character) WITHOUT FUNCTION AS ASSIGNMENT;


CREATE CAST (public.debversion AS text) WITHOUT FUNCTION AS IMPLICIT;


CREATE CAST (public.debversion AS character varying) WITHOUT FUNCTION AS IMPLICIT;


CREATE CAST (text AS public.debversion) WITHOUT FUNCTION AS ASSIGNMENT;


CREATE CAST (character varying AS public.debversion) WITHOUT FUNCTION AS ASSIGNMENT;


SET search_path = ts2, pg_catalog;

CREATE TEXT SEARCH CONFIGURATION "default" (
    PARSER = pg_catalog."default" );

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR asciiword WITH english_stem;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR word WITH english_stem;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR numword WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR email WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR url WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR host WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR sfloat WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR version WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR hword_numpart WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR hword_part WITH english_stem;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR hword_asciipart WITH english_stem;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR numhword WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR asciihword WITH english_stem;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR hword WITH english_stem;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR url_path WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR file WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR "float" WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR "int" WITH simple;

ALTER TEXT SEARCH CONFIGURATION "default"
    ADD MAPPING FOR uint WITH simple;


SET search_path = public, pg_catalog;

CREATE TABLE accesspolicy (
    id integer NOT NULL,
    product integer,
    distribution integer,
    type integer NOT NULL,
    CONSTRAINT has_target CHECK (((product IS NULL) <> (distribution IS NULL)))
);


CREATE SEQUENCE accesspolicy_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE accesspolicy_id_seq OWNED BY accesspolicy.id;


CREATE TABLE accesspolicyartifact (
    id integer NOT NULL,
    bug integer,
    branch integer,
    policy integer,
    CONSTRAINT has_artifact CHECK (((bug IS NULL) <> (branch IS NULL)))
);


CREATE SEQUENCE accesspolicyartifact_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE accesspolicyartifact_id_seq OWNED BY accesspolicyartifact.id;


CREATE TABLE accesspolicygrant (
    id integer NOT NULL,
    grantee integer NOT NULL,
    grantor integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    policy integer,
    artifact integer,
    CONSTRAINT has_target CHECK (((policy IS NULL) <> (artifact IS NULL)))
);


CREATE SEQUENCE accesspolicygrant_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE accesspolicygrant_id_seq OWNED BY accesspolicygrant.id;


CREATE TABLE account (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    creation_rationale integer NOT NULL,
    status integer NOT NULL,
    date_status_set timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    displayname text NOT NULL,
    status_comment text
);


COMMENT ON TABLE account IS 'An account that may be used for authenticating to Canonical or other systems.';


COMMENT ON COLUMN account.status IS 'The status of the account.';


COMMENT ON COLUMN account.date_status_set IS 'When the status was last changed.';


COMMENT ON COLUMN account.displayname IS 'Name to display when rendering information about this account.';


COMMENT ON COLUMN account.status_comment IS 'The comment on the status of the account.';


CREATE SEQUENCE account_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE account_id_seq OWNED BY account.id;


CREATE TABLE accountpassword (
    id integer NOT NULL,
    account integer NOT NULL,
    password text NOT NULL
);


COMMENT ON TABLE accountpassword IS 'A password used to authenticate an Account.';


COMMENT ON COLUMN accountpassword.password IS 'SSHA digest encrypted password.';


CREATE SEQUENCE accountpassword_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE accountpassword_id_seq OWNED BY accountpassword.id;


CREATE VIEW alllocks AS
    SELECT a.procpid, a.usename, (now() - a.query_start) AS age, c.relname, l.mode, l.granted, a.current_query FROM ((pg_locks l JOIN pg_class c ON ((l.relation = c.oid))) LEFT JOIN pg_stat_activity a ON ((a.procpid = l.pid)));


CREATE TABLE announcement (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_announced timestamp without time zone,
    registrant integer NOT NULL,
    product integer,
    distribution integer,
    project integer,
    title text NOT NULL,
    summary text,
    url text,
    active boolean DEFAULT true NOT NULL,
    date_updated timestamp without time zone,
    CONSTRAINT has_target CHECK ((((product IS NOT NULL) OR (project IS NOT NULL)) OR (distribution IS NOT NULL))),
    CONSTRAINT valid_url CHECK (valid_absolute_url(url))
);


COMMENT ON TABLE announcement IS 'A project announcement. This is a single item of news or information that the project is communicating. Announcements can be attached to a Project, a Product or a Distribution.';


COMMENT ON COLUMN announcement.date_announced IS 'The date at which an announcement will become public, if it is active. If this is not set then the announcement will not become public until someone consciously publishes it (which sets this date).';


COMMENT ON COLUMN announcement.url IS 'A web location for the announcement itself.';


COMMENT ON COLUMN announcement.active IS 'Whether or not the announcement is public. This is TRUE by default, but can be set to FALSE if the project "retracts" the announcement.';


CREATE SEQUENCE announcement_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE announcement_id_seq OWNED BY announcement.id;


CREATE TABLE answercontact (
    id integer NOT NULL,
    product integer,
    distribution integer,
    sourcepackagename integer,
    person integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    CONSTRAINT valid_target CHECK ((((product IS NULL) <> (distribution IS NULL)) AND ((product IS NULL) OR (sourcepackagename IS NULL))))
);


COMMENT ON TABLE answercontact IS 'Defines the answer contact for a given question target. The answer contact will be automatically notified about changes to any questions filed on the question target.';


COMMENT ON COLUMN answercontact.product IS 'The product that the answer contact supports.';


COMMENT ON COLUMN answercontact.distribution IS 'The distribution that the answer contact supports.';


COMMENT ON COLUMN answercontact.sourcepackagename IS 'The sourcepackagename that the answer contact supports.';


COMMENT ON COLUMN answercontact.person IS 'The person or team associated with the question target.';


COMMENT ON COLUMN answercontact.date_created IS 'The date the answer contact was submitted.';


CREATE SEQUENCE answercontact_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE answercontact_id_seq OWNED BY answercontact.id;


CREATE TABLE apportjob (
    id integer NOT NULL,
    job integer NOT NULL,
    blob integer NOT NULL,
    job_type integer NOT NULL,
    json_data text
);


COMMENT ON TABLE apportjob IS 'Contains references to jobs to be run against Apport BLOBs.';


COMMENT ON COLUMN apportjob.blob IS 'The TemporaryBlobStorage entry on which the job is to be run.';


COMMENT ON COLUMN apportjob.job_type IS 'The type of job (enumeration value). Allows us to query the database for a given subset of ApportJobs.';


COMMENT ON COLUMN apportjob.json_data IS 'A JSON struct containing data for the job.';


CREATE SEQUENCE apportjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE apportjob_id_seq OWNED BY apportjob.id;


CREATE TABLE archive (
    id integer NOT NULL,
    owner integer NOT NULL,
    description text,
    enabled boolean DEFAULT true NOT NULL,
    authorized_size integer,
    distribution integer NOT NULL,
    purpose integer NOT NULL,
    private boolean DEFAULT false NOT NULL,
    sources_cached integer,
    binaries_cached integer,
    package_description_cache text,
    fti ts2.tsvector,
    buildd_secret text,
    require_virtualized boolean DEFAULT true NOT NULL,
    name text DEFAULT 'default'::text NOT NULL,
    publish boolean DEFAULT true NOT NULL,
    date_updated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    total_count integer DEFAULT 0 NOT NULL,
    pending_count integer DEFAULT 0 NOT NULL,
    succeeded_count integer DEFAULT 0 NOT NULL,
    failed_count integer DEFAULT 0 NOT NULL,
    building_count integer DEFAULT 0 NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    signing_key integer,
    removed_binary_retention_days integer,
    num_old_versions_published integer,
    displayname text NOT NULL,
    relative_build_score integer DEFAULT 0 NOT NULL,
    external_dependencies text,
    status integer DEFAULT 0 NOT NULL,
    commercial boolean DEFAULT false NOT NULL,
    build_debug_symbols boolean DEFAULT false NOT NULL,
    CONSTRAINT valid_buildd_secret CHECK ((((private = true) AND (buildd_secret IS NOT NULL)) OR (private = false))),
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE archive IS 'A package archive. Commonly either a distribution''s main_archive or a ppa''s archive.';


COMMENT ON COLUMN archive.owner IS 'Identifies the PPA owner when it has one.';


COMMENT ON COLUMN archive.description IS 'Allow users to describe their PPAs content.';


COMMENT ON COLUMN archive.enabled IS 'Whether or not the PPA is enabled for accepting uploads.';


COMMENT ON COLUMN archive.authorized_size IS 'Size, in MiB, allowed for this PPA.';


COMMENT ON COLUMN archive.distribution IS 'The distribution that uses this archive.';


COMMENT ON COLUMN archive.purpose IS 'The purpose of this archive, e.g. COMMERCIAL.  See the ArchivePurpose DBSchema item.';


COMMENT ON COLUMN archive.private IS 'Whether or not the archive is private. This affects the global visibility of the archive.';


COMMENT ON COLUMN archive.sources_cached IS 'Number of sources already cached for this archive.';


COMMENT ON COLUMN archive.binaries_cached IS 'Number of binaries already cached for this archive.';


COMMENT ON COLUMN archive.package_description_cache IS 'Text blob containing all source and binary names and descriptions concatenated. Used to to build the tsearch indexes on this table.';


COMMENT ON COLUMN archive.require_virtualized IS 'Whether this archive has binaries that should be built on a virtual machine, e.g. PPAs';


COMMENT ON COLUMN archive.name IS 'The name of the archive.';


COMMENT ON COLUMN archive.publish IS 'Whether this archive should be published.';


COMMENT ON COLUMN archive.date_updated IS 'When were the rebuild statistics last updated?';


COMMENT ON COLUMN archive.total_count IS 'How many source packages are in the rebuild archive altogether?';


COMMENT ON COLUMN archive.pending_count IS 'How many packages still need building?';


COMMENT ON COLUMN archive.succeeded_count IS 'How many source packages were built sucessfully?';


COMMENT ON COLUMN archive.failed_count IS 'How many packages failed to build?';


COMMENT ON COLUMN archive.building_count IS 'How many packages are building at present?';


COMMENT ON COLUMN archive.signing_key IS 'The GpgKey used for signing this archive.';


COMMENT ON COLUMN archive.removed_binary_retention_days IS 'The number of days before superseded or deleted binary files are expired in the librarian, or zero for never.';


COMMENT ON COLUMN archive.num_old_versions_published IS 'The number of versions of a package to keep published before older versions are superseded.';


COMMENT ON COLUMN archive.displayname IS 'User defined displayname for this archive.';


COMMENT ON COLUMN archive.relative_build_score IS 'A delta to the build score that is applied to all builds in this archive.';


COMMENT ON COLUMN archive.external_dependencies IS 'Newline-separated list of repositories to be used to retrieve any external build dependencies when building packages in this archive, in the format: deb http[s]://[user:pass@]<host>[/path] %(series)s[-pocket] [components]  The series variable is replaced with the series name of the context build.  This column is specifically and only intended for OEM migration to Launchpad and should be re-examined in October 2010 to see if it is still relevant.';


COMMENT ON COLUMN archive.status IS 'The status of this archive, e.g. ACTIVE.  See the ArchiveState DBSchema item.';


COMMENT ON COLUMN archive.commercial IS 'Whether this archive is a commercial Archive and should appear in the Software Center.';


COMMENT ON COLUMN archive.build_debug_symbols IS 'Whether builds for this archive should create debug symbol packages.';


CREATE SEQUENCE archive_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE archive_id_seq OWNED BY archive.id;


CREATE TABLE archivearch (
    id integer NOT NULL,
    archive integer NOT NULL,
    processorfamily integer NOT NULL
);


COMMENT ON TABLE archivearch IS 'ArchiveArch: A table that allows a user to specify which architectures an archive requires or supports.';


COMMENT ON COLUMN archivearch.archive IS 'The archive for which an architecture is specified.';


COMMENT ON COLUMN archivearch.processorfamily IS 'The architecture specified for the archive on hand.';


CREATE SEQUENCE archivearch_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE archivearch_id_seq OWNED BY archivearch.id;


CREATE TABLE archiveauthtoken (
    id integer NOT NULL,
    archive integer NOT NULL,
    person integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_deactivated timestamp without time zone,
    token text NOT NULL
);


COMMENT ON TABLE archiveauthtoken IS 'Authorisation tokens to use in .htaccess for published archives.';


COMMENT ON COLUMN archiveauthtoken.archive IS 'The archive to which this token refers.';


COMMENT ON COLUMN archiveauthtoken.person IS 'The person to which this token applies.';


COMMENT ON COLUMN archiveauthtoken.date_created IS 'The date and time this token was created.';


COMMENT ON COLUMN archiveauthtoken.date_deactivated IS 'The date and time this token was deactivated.';


COMMENT ON COLUMN archiveauthtoken.token IS 'The token text for this authorisation.';


CREATE SEQUENCE archiveauthtoken_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE archiveauthtoken_id_seq OWNED BY archiveauthtoken.id;


CREATE TABLE archivedependency (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    archive integer NOT NULL,
    dependency integer NOT NULL,
    pocket integer NOT NULL,
    component integer,
    CONSTRAINT distinct_archives CHECK ((archive <> dependency))
);


COMMENT ON TABLE archivedependency IS 'This table maps a given archive to all other archives it should depend on.';


COMMENT ON COLUMN archivedependency.date_created IS 'Instant when the dependency was created.';


COMMENT ON COLUMN archivedependency.archive IS 'The archive where the dependency should be applied.';


COMMENT ON COLUMN archivedependency.dependency IS 'The archive to depend on.';


CREATE SEQUENCE archivedependency_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE archivedependency_id_seq OWNED BY archivedependency.id;


CREATE TABLE archivejob (
    id integer NOT NULL,
    job integer NOT NULL,
    archive integer NOT NULL,
    job_type integer NOT NULL,
    json_data text
);


COMMENT ON TABLE archivejob IS 'Contains references to jobs to be run against Archives.';


COMMENT ON COLUMN archivejob.archive IS 'The archive on which the job is to be run.';


COMMENT ON COLUMN archivejob.job_type IS 'The type of job (enumeration value). Allows us to query the database for a given subset of ArchiveJobs.';


COMMENT ON COLUMN archivejob.json_data IS 'A JSON struct containing data for the job.';


CREATE SEQUENCE archivejob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE archivejob_id_seq OWNED BY archivejob.id;


CREATE TABLE archivepermission (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    person integer NOT NULL,
    permission integer NOT NULL,
    archive integer NOT NULL,
    component integer,
    sourcepackagename integer,
    packageset integer,
    explicit boolean DEFAULT false NOT NULL,
    CONSTRAINT one_target CHECK ((null_count(ARRAY[packageset, component, sourcepackagename]) = 2))
);


COMMENT ON TABLE archivepermission IS 'ArchivePermission: A record of who has permission to upload and approve uploads to an archive (and hence a distribution)';


COMMENT ON COLUMN archivepermission.date_created IS 'The date that this permission was created.';


COMMENT ON COLUMN archivepermission.person IS 'The person or team to whom the permission is being granted.';


COMMENT ON COLUMN archivepermission.permission IS 'The permission type being granted.';


COMMENT ON COLUMN archivepermission.archive IS 'The archive to which this permission applies.';


COMMENT ON COLUMN archivepermission.component IS 'The component to which this upload permission applies.';


COMMENT ON COLUMN archivepermission.sourcepackagename IS 'The source package name to which this permission applies.  This can be used to provide package-level permissions to single users.';


COMMENT ON COLUMN archivepermission.packageset IS 'The package set to which this permission applies.';


COMMENT ON COLUMN archivepermission.explicit IS 'This flag is set for package sets containing high-profile packages that must not break and/or require specialist skills for proper handling e.g. the kernel.';


CREATE SEQUENCE archivepermission_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE archivepermission_id_seq OWNED BY archivepermission.id;


CREATE TABLE archivesubscriber (
    id integer NOT NULL,
    archive integer NOT NULL,
    registrant integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    subscriber integer NOT NULL,
    date_expires timestamp without time zone,
    status integer NOT NULL,
    description text,
    date_cancelled timestamp without time zone,
    cancelled_by integer
);


COMMENT ON TABLE archivesubscriber IS 'An authorised person or team subscription to an archive.';


COMMENT ON COLUMN archivesubscriber.archive IS 'The archive that the subscriber is authorised to see.';


COMMENT ON COLUMN archivesubscriber.registrant IS 'The person who authorised this subscriber.';


COMMENT ON COLUMN archivesubscriber.date_created IS 'The date and time this subscription was created.';


COMMENT ON COLUMN archivesubscriber.subscriber IS 'The person or team that this subscription refers to.';


COMMENT ON COLUMN archivesubscriber.date_expires IS 'The date and time this subscription will expire. If NULL, it does not expire.';


COMMENT ON COLUMN archivesubscriber.status IS 'The status of the subscription, e.g. PENDING, ACTIVE, CANCELLING, CANCELLED.';


COMMENT ON COLUMN archivesubscriber.description IS 'An optional note for the archive owner to describe the subscription.';


COMMENT ON COLUMN archivesubscriber.date_cancelled IS 'The date and time this subscription was revoked.';


COMMENT ON COLUMN archivesubscriber.cancelled_by IS 'The person who revoked this subscription.';


CREATE SEQUENCE archivesubscriber_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE archivesubscriber_id_seq OWNED BY archivesubscriber.id;


CREATE TABLE binarypackagename (
    id integer NOT NULL,
    name text NOT NULL,
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE binarypackagename IS 'BinaryPackageName: A soyuz binary package name.';


COMMENT ON COLUMN binarypackagename.name IS 'A lowercase name identifying one or more binarypackages';


CREATE TABLE sourcepackagename (
    id integer NOT NULL,
    name text NOT NULL,
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE sourcepackagename IS 'SourcePackageName: A soyuz source package name.';


COMMENT ON COLUMN sourcepackagename.name IS 'A lowercase name identifying one or more sourcepackages';


CREATE VIEW binaryandsourcepackagenameview AS
    SELECT binarypackagename.name FROM binarypackagename UNION SELECT sourcepackagename.name FROM sourcepackagename;


CREATE TABLE binarypackagebuild (
    id integer NOT NULL,
    package_build integer NOT NULL,
    distro_arch_series integer NOT NULL,
    source_package_release integer NOT NULL
);


COMMENT ON TABLE binarypackagebuild IS 'BinaryPackageBuild: This table links a package build with a distroarchseries and sourcepackagerelease.';


COMMENT ON COLUMN binarypackagebuild.package_build IS 'Points to the related package build with the base information.';


COMMENT ON COLUMN binarypackagebuild.distro_arch_series IS 'Points the target DistroArchSeries for this build.';


COMMENT ON COLUMN binarypackagebuild.source_package_release IS 'SourcePackageRelease which originated this build.';


CREATE SEQUENCE binarypackagebuild_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE binarypackagebuild_id_seq OWNED BY binarypackagebuild.id;


CREATE TABLE binarypackagefile (
    binarypackagerelease integer NOT NULL,
    libraryfile integer NOT NULL,
    filetype integer NOT NULL,
    id integer DEFAULT nextval(('binarypackagefile_id_seq'::text)::regclass) NOT NULL
);


COMMENT ON TABLE binarypackagefile IS 'BinaryPackageFile: A soyuz <-> librarian link table. This table represents the ownership in the librarian of a file which represents a binary package';


COMMENT ON COLUMN binarypackagefile.binarypackagerelease IS 'The binary package which is represented by the file';


COMMENT ON COLUMN binarypackagefile.libraryfile IS 'The file in the librarian which represents the package';


COMMENT ON COLUMN binarypackagefile.filetype IS 'The "type" of the file. E.g. DEB, RPM';


CREATE SEQUENCE binarypackagefile_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE binarypackagefile_id_seq OWNED BY binarypackagefile.id;


CREATE TABLE binarypackagepublishinghistory (
    id integer NOT NULL,
    binarypackagerelease integer NOT NULL,
    distroarchseries integer NOT NULL,
    status integer NOT NULL,
    component integer NOT NULL,
    section integer NOT NULL,
    priority integer NOT NULL,
    datecreated timestamp without time zone NOT NULL,
    datepublished timestamp without time zone,
    datesuperseded timestamp without time zone,
    supersededby integer,
    datemadepending timestamp without time zone,
    scheduleddeletiondate timestamp without time zone,
    dateremoved timestamp without time zone,
    pocket integer DEFAULT 0 NOT NULL,
    archive integer NOT NULL,
    removed_by integer,
    removal_comment text,
    binarypackagename integer
);


COMMENT ON TABLE binarypackagepublishinghistory IS 'PackagePublishingHistory: The history of a BinaryPackagePublishing record. This table represents the lifetime of a publishing record from inception to deletion. Records are never removed from here and in time the publishing table may become a view onto this table. A column being NULL indicates there''s no data for that state transition. E.g. a package which is removed without being superseded won''t have datesuperseded or supersededby filled in.';


COMMENT ON COLUMN binarypackagepublishinghistory.binarypackagerelease IS 'The binarypackage being published.';


COMMENT ON COLUMN binarypackagepublishinghistory.distroarchseries IS 'The distroarchseries into which the binarypackage is being published.';


COMMENT ON COLUMN binarypackagepublishinghistory.status IS 'The current status of the publishing.';


COMMENT ON COLUMN binarypackagepublishinghistory.component IS 'The component into which the publishing takes place.';


COMMENT ON COLUMN binarypackagepublishinghistory.section IS 'The section into which the publishing takes place.';


COMMENT ON COLUMN binarypackagepublishinghistory.priority IS 'The priority at which the publishing takes place.';


COMMENT ON COLUMN binarypackagepublishinghistory.datecreated IS 'The date/time on which the publishing record was created.';


COMMENT ON COLUMN binarypackagepublishinghistory.datepublished IS 'The date/time on which the source was actually published into an archive.';


COMMENT ON COLUMN binarypackagepublishinghistory.datesuperseded IS 'The date/time on which the source was superseded by a new source.';


COMMENT ON COLUMN binarypackagepublishinghistory.supersededby IS 'The build which superseded this package. This seems odd but it is important because a new build may not actually build a given binarypackage and we need to supersede it appropriately';


COMMENT ON COLUMN binarypackagepublishinghistory.datemadepending IS 'The date/time on which this publishing record was made to be pending removal from the archive.';


COMMENT ON COLUMN binarypackagepublishinghistory.scheduleddeletiondate IS 'The date/time at which the package is/was scheduled to be deleted.';


COMMENT ON COLUMN binarypackagepublishinghistory.dateremoved IS 'The date/time at which the package was actually deleted.';


COMMENT ON COLUMN binarypackagepublishinghistory.pocket IS 'The pocket into which this record is published. The RELEASE pocket (zero) provides behaviour as normal. Other pockets may append things to the distroseries name such as the UPDATES pocket (-updates) or the SECURITY pocket (-security).';


COMMENT ON COLUMN binarypackagepublishinghistory.archive IS 'Target archive for this publishing record.';


COMMENT ON COLUMN binarypackagepublishinghistory.removed_by IS 'Person responsible for the removal.';


COMMENT ON COLUMN binarypackagepublishinghistory.removal_comment IS 'Reason why the publication was removed.';


CREATE TABLE binarypackagerelease (
    id integer NOT NULL,
    binarypackagename integer NOT NULL,
    version debversion NOT NULL,
    summary text NOT NULL,
    description text NOT NULL,
    build integer NOT NULL,
    binpackageformat integer NOT NULL,
    component integer NOT NULL,
    section integer NOT NULL,
    priority integer NOT NULL,
    shlibdeps text,
    depends text,
    recommends text,
    suggests text,
    conflicts text,
    replaces text,
    provides text,
    essential boolean NOT NULL,
    installedsize integer,
    architecturespecific boolean NOT NULL,
    fti ts2.tsvector,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    pre_depends text,
    enhances text,
    breaks text,
    debug_package integer,
    user_defined_fields text,
    homepage text,
    CONSTRAINT valid_version CHECK (valid_debian_version((version)::text))
);


COMMENT ON TABLE binarypackagerelease IS 'BinaryPackageRelease: A soyuz binary package representation. This table stores the records for each binary package uploaded into the system. Each sourcepackagerelease may build various binarypackages on various architectures.';


COMMENT ON COLUMN binarypackagerelease.binarypackagename IS 'A reference to the name of the binary package';


COMMENT ON COLUMN binarypackagerelease.version IS 'The version of the binary package. E.g. "1.0-2"';


COMMENT ON COLUMN binarypackagerelease.summary IS 'A summary of the binary package. Commonly used on listings of binary packages';


COMMENT ON COLUMN binarypackagerelease.description IS 'A longer more detailed description of the binary package';


COMMENT ON COLUMN binarypackagerelease.build IS 'The build in which this binarypackage was produced';


COMMENT ON COLUMN binarypackagerelease.binpackageformat IS 'The binarypackage format. E.g. RPM, DEB etc';


COMMENT ON COLUMN binarypackagerelease.component IS 'The archive component that this binarypackage is in. E.g. main, universe etc';


COMMENT ON COLUMN binarypackagerelease.section IS 'The archive section that this binarypackage is in. E.g. devel, libdevel, editors';


COMMENT ON COLUMN binarypackagerelease.priority IS 'The priority that this package has. E.g. Base, Standard, Extra, Optional';


COMMENT ON COLUMN binarypackagerelease.shlibdeps IS 'The shared library dependencies of this binary package';


COMMENT ON COLUMN binarypackagerelease.depends IS 'The list of packages this binarypackage depends on';


COMMENT ON COLUMN binarypackagerelease.recommends IS 'The list of packages this binarypackage recommends. Recommended packages often enhance the behaviour of a package.';


COMMENT ON COLUMN binarypackagerelease.suggests IS 'The list of packages this binarypackage suggests.';


COMMENT ON COLUMN binarypackagerelease.conflicts IS 'The list of packages this binarypackage conflicts with.';


COMMENT ON COLUMN binarypackagerelease.replaces IS 'The list of packages this binarypackage replaces files in. Often this is used to provide an upgrade path between two binarypackages of different names';


COMMENT ON COLUMN binarypackagerelease.provides IS 'The list of virtual packages (or real packages under some circumstances) which this binarypackage provides.';


COMMENT ON COLUMN binarypackagerelease.essential IS 'Whether or not this binarypackage is essential to the smooth operation of a base system';


COMMENT ON COLUMN binarypackagerelease.installedsize IS 'What the installed size of the binarypackage is. This is represented as a number of kilobytes of storage.';


COMMENT ON COLUMN binarypackagerelease.architecturespecific IS 'This field indicates whether or not a binarypackage is architecture-specific. If it is not specific to any given architecture then it can automatically be included in all the distroarchseries which pertain.';


COMMENT ON COLUMN binarypackagerelease.pre_depends IS 'The list of packages this binary requires to be installed beforehand in apt/dpkg format, as it is in control file "Pre-Depends:" field.';


COMMENT ON COLUMN binarypackagerelease.enhances IS 'The list of packages pointed as "enhanced" after the installation of this package, as it is in control file "Enhances:" field.';


COMMENT ON COLUMN binarypackagerelease.breaks IS 'The list of packages which will be broken by the installtion of this package, as it is in the control file "Breaks:" field.';


COMMENT ON COLUMN binarypackagerelease.debug_package IS 'The corresponding binary package release containing debug symbols for this binary, if any.';


COMMENT ON COLUMN binarypackagerelease.user_defined_fields IS 'A JSON struct containing a sequence of key-value pairs with user defined fields in the control file.';


COMMENT ON COLUMN binarypackagerelease.homepage IS 'Upstream project homepage URL, not checked for validity.';


CREATE TABLE component (
    id integer NOT NULL,
    name text NOT NULL,
    description text,
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE component IS 'Known components in Launchpad';


COMMENT ON COLUMN component.name IS 'Component name text';


COMMENT ON COLUMN component.description IS 'Description of this component.';


CREATE TABLE distroarchseries (
    id integer NOT NULL,
    distroseries integer NOT NULL,
    processorfamily integer NOT NULL,
    architecturetag text NOT NULL,
    owner integer NOT NULL,
    official boolean NOT NULL,
    package_count integer DEFAULT 0 NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    supports_virtualized boolean DEFAULT false NOT NULL,
    enabled boolean DEFAULT true NOT NULL,
    CONSTRAINT valid_architecturetag CHECK (valid_name(architecturetag))
);


COMMENT ON TABLE distroarchseries IS 'DistroArchSeries: A soyuz distribution release for a given architecture. A distroseries runs on various architectures. The distroarchseries groups that architecture-specific stuff.';


COMMENT ON COLUMN distroarchseries.distroseries IS 'The distribution which this distroarchseries is part of.';


COMMENT ON COLUMN distroarchseries.processorfamily IS 'A link to the ProcessorFamily table, giving the architecture of this DistroArchSeries.';


COMMENT ON COLUMN distroarchseries.architecturetag IS 'The name of this architecture in the context of this specific distro release. For example, some distributions might label amd64 as amd64, others might call is x86_64. This information is used, for example, in determining the names of the actual package files... such as the "amd64" part of "apache2_2.0.56-1_amd64.deb"';


COMMENT ON COLUMN distroarchseries.official IS 'Whether or not this architecture or "port" is an official release. If it is not official then you may not be able to install it or get all the packages for it.';


COMMENT ON COLUMN distroarchseries.package_count IS 'A cache of the number of binary packages published in this distro arch release. The count only includes packages published in the release pocket.';


COMMENT ON COLUMN distroarchseries.supports_virtualized IS 'Whether or not
virtualized build support should be provided by this specific distroarchseries';


COMMENT ON COLUMN distroarchseries.enabled IS 'Whether to allow build creation and publishing for this DistroArchSeries.';


CREATE TABLE distroseries (
    id integer NOT NULL,
    distribution integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    description text NOT NULL,
    version text NOT NULL,
    releasestatus integer NOT NULL,
    datereleased timestamp without time zone,
    parent_series integer,
    registrant integer NOT NULL,
    summary text NOT NULL,
    displayname text NOT NULL,
    datelastlangpack timestamp without time zone,
    messagecount integer DEFAULT 0 NOT NULL,
    nominatedarchindep integer,
    changeslist text,
    binarycount integer DEFAULT 0 NOT NULL,
    sourcecount integer DEFAULT 0 NOT NULL,
    driver integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    hide_all_translations boolean DEFAULT true NOT NULL,
    defer_translation_imports boolean DEFAULT true NOT NULL,
    language_pack_base integer,
    language_pack_delta integer,
    language_pack_proposed integer,
    language_pack_full_export_requested boolean DEFAULT false NOT NULL,
    backports_not_automatic boolean DEFAULT false NOT NULL,
    include_long_descriptions boolean DEFAULT true NOT NULL,
    CONSTRAINT valid_language_pack_delta CHECK (((language_pack_base IS NOT NULL) OR (language_pack_delta IS NULL))),
    CONSTRAINT valid_name CHECK (valid_name(name)),
    CONSTRAINT valid_version CHECK (sane_version(version))
);


COMMENT ON TABLE distroseries IS 'DistroSeries: A soyuz distribution release. A DistroSeries is a given version of a distribution. E.g. "Warty" "Hoary" "Sarge" etc.';


COMMENT ON COLUMN distroseries.distribution IS 'The distribution which contains this distroseries.';


COMMENT ON COLUMN distroseries.name IS 'The unique name of the distroseries. This is a short name in lower case and would be used in sources.list configuration and in generated URLs. E.g. "warty" "sarge" "sid"';


COMMENT ON COLUMN distroseries.title IS 'The display-name title of the distroseries E.g. "Warty Warthog"';


COMMENT ON COLUMN distroseries.description IS 'The long detailed description of the release. This may describe the focus of the release or other related information.';


COMMENT ON COLUMN distroseries.version IS 'The version of the release. E.g. warty would be "4.10" and hoary would be "5.4"';


COMMENT ON COLUMN distroseries.releasestatus IS 'The current release status of this distroseries. E.g. "pre-release freeze" or "released"';


COMMENT ON COLUMN distroseries.datereleased IS 'The date on which this distroseries was released. (obviously only valid for released distributions)';


COMMENT ON COLUMN distroseries.parent_series IS 'The parent distroseries on which this distribution is based. This is related to the inheritance stuff.';


COMMENT ON COLUMN distroseries.registrant IS 'The ultimate owner of this distroseries.';


COMMENT ON COLUMN distroseries.summary IS 'A brief summary of the distro release. This will be displayed in bold at the top of the distroseries page, above the distroseries description. It should include any high points that are particularly important to draw to the attention of users.';


COMMENT ON COLUMN distroseries.datelastlangpack IS 'The date we last generated a base language pack for this release. Language update packs for this release will only include translations added after that date.';


COMMENT ON COLUMN distroseries.messagecount IS 'This is a cached value and may be a few hours out of sync with reality. It should, however, be in sync with the values in DistroSeriesLanguage, and should never be updated separately. The total number of translation messages in this distro release, as per IRosettaStats.';


COMMENT ON COLUMN distroseries.nominatedarchindep IS 'This is the DistroArchSeries nominated to build architecture independent packages within this DistroRelase, it is mandatory for buildable distroseries, i.e., Auto Build System will avoid to create build jobs for a DistroSeries with no nominatedarchindep, but the database model allow us to do it (for non-buildable DistroSeries). See further info in NominatedArchIndep specification.';


COMMENT ON COLUMN distroseries.changeslist IS 'The email address (name name) of the changes announcement list for this distroseries. If NULL, no announcement mail will be sent.';


COMMENT ON COLUMN distroseries.binarycount IS 'A cache of the number of distinct binary package names published in this distro release.';


COMMENT ON COLUMN distroseries.sourcecount IS 'A cache of the number of distinct source package names published in this distro release.';


COMMENT ON COLUMN distroseries.driver IS 'This is a person or team who can act as a driver for this specific release - note that the distribution drivers can also set goals for any release.';


COMMENT ON COLUMN distroseries.hide_all_translations IS 'Whether we should hid
e all available translations for this distro release to non admin users.';


COMMENT ON COLUMN distroseries.defer_translation_imports IS 'Don''t accept PO imports for this release just now.';


COMMENT ON COLUMN distroseries.language_pack_base IS 'Current full export language pack for this distribution release.';


COMMENT ON COLUMN distroseries.language_pack_delta IS 'Current language pack update based on language_pack_base information.';


COMMENT ON COLUMN distroseries.language_pack_proposed IS 'Either a full or update language pack being tested to be used in language_pack_base or language_pack_delta.';


COMMENT ON COLUMN distroseries.language_pack_full_export_requested IS 'Whether next language pack export should be a full export or an update.';


CREATE TABLE libraryfilealias (
    id integer NOT NULL,
    content integer,
    filename text NOT NULL,
    mimetype text NOT NULL,
    expires timestamp without time zone,
    last_accessed timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    restricted boolean DEFAULT false NOT NULL,
    hits integer DEFAULT 0 NOT NULL,
    CONSTRAINT valid_filename CHECK ((filename !~~ '%/%'::text))
);


COMMENT ON TABLE libraryfilealias IS 'LibraryFileAlias: A librarian file''s alias. The librarian stores, along with the file contents, a record stating the file name and mimetype. This table represents it.';


COMMENT ON COLUMN libraryfilealias.content IS 'The libraryfilecontent which is the data in this file.';


COMMENT ON COLUMN libraryfilealias.filename IS 'The name of the file. E.g. "foo_1.0-1_i386.deb"';


COMMENT ON COLUMN libraryfilealias.mimetype IS 'The mime type of the file. E.g. "application/x-debian-package"';


COMMENT ON COLUMN libraryfilealias.expires IS 'The expiry date of this file. If NULL, this item may be removed as soon as it is no longer referenced. If set, the item will not be removed until this date. Once the date is passed, the file may be removed from disk even if this item is still being referenced (in which case content.deleted will be true)';


COMMENT ON COLUMN libraryfilealias.last_accessed IS 'Roughly when this file was last retrieved from the Librarian. Initially set to this item''s creation date.';


COMMENT ON COLUMN libraryfilealias.date_created IS 'The timestamp when this alias was created.';


COMMENT ON COLUMN libraryfilealias.restricted IS 'Is this file available only from the restricted librarian?';


COMMENT ON COLUMN libraryfilealias.hits IS 'The number of times this file has been downloaded.';


CREATE TABLE sourcepackagerelease (
    id integer NOT NULL,
    creator integer NOT NULL,
    version debversion NOT NULL,
    dateuploaded timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    urgency integer NOT NULL,
    dscsigningkey integer,
    component integer NOT NULL,
    changelog_entry text,
    builddepends text,
    builddependsindep text,
    architecturehintlist text NOT NULL,
    dsc text,
    section integer NOT NULL,
    maintainer integer NOT NULL,
    sourcepackagename integer NOT NULL,
    upload_distroseries integer NOT NULL,
    format integer NOT NULL,
    dsc_maintainer_rfc822 text,
    dsc_standards_version text,
    dsc_format text NOT NULL,
    dsc_binaries text,
    upload_archive integer,
    copyright text,
    build_conflicts text,
    build_conflicts_indep text,
    sourcepackage_recipe_build integer,
    changelog integer,
    user_defined_fields text,
    homepage text,
    CONSTRAINT valid_version CHECK (valid_debian_version((version)::text))
);


COMMENT ON TABLE sourcepackagerelease IS 'SourcePackageRelease: A source
package release. This table represents a specific release of a source
package. Source package releases may be published into a distroseries, or
even multiple distroseries.';


COMMENT ON COLUMN sourcepackagerelease.creator IS 'The creator of this
sourcepackagerelease. This is the person referred to in the top entry in the
package changelog in debian terms. Note that a source package maintainer in
Ubuntu might be person A, but a particular release of that source package
might in fact have been created by a different person B. The maintainer
would be recorded in the Maintainership table, while the creator of THIS
release would be recorded in the SourcePackageRelease.creator field.';


COMMENT ON COLUMN sourcepackagerelease.version IS 'The version string for
this source package release. E.g. "1.0-2" or "1.4-5ubuntu9.1". Note that, in
ubuntu-style and redhat-style distributions, the version+sourcepackagename
is unique, even across distroseries. In other words, you cannot have a
foo-1.2-1 package in Hoary that is different from foo-1.2-1 in Warty.';


COMMENT ON COLUMN sourcepackagerelease.dateuploaded IS 'The date/time that
this sourcepackagerelease was first uploaded to the Launchpad.';


COMMENT ON COLUMN sourcepackagerelease.urgency IS 'The urgency of the
upload. This is generally used to prioritise buildd activity but may also be
used for "testing" systems or security work in the future. The "urgency" is
set by the uploader, in the DSC file.';


COMMENT ON COLUMN sourcepackagerelease.dscsigningkey IS 'The GPG key used to
sign the DSC. This is not necessarily the maintainer''s key, or the
creator''s key. For example, it''s possible to produce a package, then ask a
sponsor to upload it.';


COMMENT ON COLUMN sourcepackagerelease.component IS 'The component in which
this sourcepackagerelease is intended (by the uploader) to reside. E.g.
main, universe, restricted. Note that the distribution managers will often
override this data and publish the package in an entirely different
component.';


COMMENT ON COLUMN sourcepackagerelease.changelog_entry IS 'Changelog text section extracted from the changesfile.';


COMMENT ON COLUMN sourcepackagerelease.builddepends IS 'The build
dependencies for this source package release.';


COMMENT ON COLUMN sourcepackagerelease.builddependsindep IS 'The
architecture-independant build dependancies for this source package release.';


COMMENT ON COLUMN sourcepackagerelease.architecturehintlist IS 'The
architectures which this source package release believes it should be built.
This is used as a hint to the build management system when deciding what
builds are still needed.';


COMMENT ON COLUMN sourcepackagerelease.dsc IS 'The "Debian Source Control"
file for the sourcepackagerelease, from its upload into Ubuntu for the
first time.';


COMMENT ON COLUMN sourcepackagerelease.section IS 'This integer field references the Section which the source package claims to be in';


COMMENT ON COLUMN sourcepackagerelease.maintainer IS 'Reference to the person noted as source package maintainer in the DSC.';


COMMENT ON COLUMN sourcepackagerelease.sourcepackagename IS 'Reference to a SourcePackageName.';


COMMENT ON COLUMN sourcepackagerelease.upload_distroseries IS 'The
distroseries into which this source package release was uploaded into
Launchpad / Ubuntu for the first time. In general, this will be the
development Ubuntu release into which this package was uploaded. For a
package which was unchanged between warty and hoary, this would show Warty.
For a package which was uploaded into Hoary, this would show Hoary.';


COMMENT ON COLUMN sourcepackagerelease.format IS 'The format of this
sourcepackage release, e.g. DPKG, RPM, EBUILD, etc. This is an enum, and the
values are listed in dbschema.SourcePackageFormat';


COMMENT ON COLUMN sourcepackagerelease.dsc_maintainer_rfc822 IS 'The original maintainer line in RFC-822 format, to be used in archive indexes.';


COMMENT ON COLUMN sourcepackagerelease.dsc_standards_version IS 'DSC standards version (such as "3.6.2", "3.5.9", etc) used to build this source.';


COMMENT ON COLUMN sourcepackagerelease.dsc_format IS 'DSC format version (such as "1.0").';


COMMENT ON COLUMN sourcepackagerelease.dsc_binaries IS 'DSC binary line, claimed binary-names produce by this source.';


COMMENT ON COLUMN sourcepackagerelease.upload_archive IS 'The archive into which this sourcepackagerelese was originally uploaded.';


COMMENT ON COLUMN sourcepackagerelease.copyright IS 'The copyright associated with this sourcepackage. Often in the case of debian packages and will be found after the installation in /usr/share/doc/<binarypackagename>/copyright';


COMMENT ON COLUMN sourcepackagerelease.build_conflicts IS 'The list of packages that will conflict with this source while building, as mentioned in the control file "Build-Conflicts:" field.';


COMMENT ON COLUMN sourcepackagerelease.build_conflicts_indep IS 'The list of packages that will conflict with this source while building in architecture independent environment, as mentioned in the control file "Build-Conflicts-Indep:" field.';


COMMENT ON COLUMN sourcepackagerelease.changelog IS 'The LibraryFileAlias ID of changelog associated with this sourcepackage.  Often in the case of debian packages and will be found after the installation in /usr/share/doc/<binarypackagename>/changelog.Debian.gz';


COMMENT ON COLUMN sourcepackagerelease.user_defined_fields IS 'A JSON struct containing a sequence of key-value pairs with user defined fields in the control file.';


COMMENT ON COLUMN sourcepackagerelease.homepage IS 'Upstream project homepage URL, not checked for validity.';


CREATE VIEW binarypackagefilepublishing AS
    SELECT (((libraryfilealias.id)::text || '.'::text) || (securebinarypackagepublishinghistory.id)::text) AS id, distroseries.distribution, securebinarypackagepublishinghistory.id AS binarypackagepublishing, component.name AS componentname, libraryfilealias.filename AS libraryfilealiasfilename, sourcepackagename.name AS sourcepackagename, binarypackagefile.libraryfile AS libraryfilealias, distroseries.name AS distroseriesname, distroarchseries.architecturetag, securebinarypackagepublishinghistory.status AS publishingstatus, securebinarypackagepublishinghistory.pocket, securebinarypackagepublishinghistory.archive FROM (((((((((binarypackagepublishinghistory securebinarypackagepublishinghistory JOIN binarypackagerelease ON ((securebinarypackagepublishinghistory.binarypackagerelease = binarypackagerelease.id))) JOIN binarypackagebuild ON ((binarypackagerelease.build = binarypackagebuild.id))) JOIN sourcepackagerelease ON ((binarypackagebuild.source_package_release = sourcepackagerelease.id))) JOIN sourcepackagename ON ((sourcepackagerelease.sourcepackagename = sourcepackagename.id))) JOIN binarypackagefile ON ((binarypackagefile.binarypackagerelease = binarypackagerelease.id))) JOIN libraryfilealias ON ((binarypackagefile.libraryfile = libraryfilealias.id))) JOIN distroarchseries ON ((securebinarypackagepublishinghistory.distroarchseries = distroarchseries.id))) JOIN distroseries ON ((distroarchseries.distroseries = distroseries.id))) JOIN component ON ((securebinarypackagepublishinghistory.component = component.id))) WHERE (securebinarypackagepublishinghistory.dateremoved IS NULL);


COMMENT ON VIEW binarypackagefilepublishing IS 'This view is used mostly by Lucille while performing publishing and unpublishing operations. It lists all the files associated with a binarypackage and collates all the textual representations needed for publishing components etc to allow rapid queries from SQLObject.';


CREATE SEQUENCE binarypackagename_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE binarypackagename_id_seq OWNED BY binarypackagename.id;


CREATE TABLE binarypackagepath (
    id integer NOT NULL,
    path bytea NOT NULL
);


CREATE SEQUENCE binarypackagepath_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE binarypackagepath_id_seq OWNED BY binarypackagepath.id;


CREATE SEQUENCE binarypackagepublishinghistory_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE binarypackagepublishinghistory_id_seq OWNED BY binarypackagepublishinghistory.id;


CREATE SEQUENCE binarypackagerelease_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE binarypackagerelease_id_seq OWNED BY binarypackagerelease.id;


CREATE TABLE binarypackagereleasecontents (
    binarypackagerelease integer NOT NULL,
    binarypackagepath integer NOT NULL
);


CREATE TABLE binarypackagereleasedownloadcount (
    id integer NOT NULL,
    archive integer NOT NULL,
    binary_package_release integer NOT NULL,
    day date NOT NULL,
    country integer,
    count integer NOT NULL
);


CREATE SEQUENCE binarypackagereleasedownloadcount_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE binarypackagereleasedownloadcount_id_seq OWNED BY binarypackagereleasedownloadcount.id;


CREATE TABLE branch (
    id integer NOT NULL,
    title text,
    summary text,
    owner integer NOT NULL,
    product integer,
    author integer,
    name text NOT NULL,
    home_page text,
    url text,
    whiteboard text,
    lifecycle_status integer DEFAULT 1 NOT NULL,
    last_mirrored timestamp without time zone,
    last_mirror_attempt timestamp without time zone,
    mirror_failures integer DEFAULT 0 NOT NULL,
    mirror_status_message text,
    last_scanned timestamp without time zone,
    last_scanned_id text,
    last_mirrored_id text,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    revision_count integer DEFAULT 0 NOT NULL,
    next_mirror_time timestamp without time zone,
    private boolean DEFAULT false NOT NULL,
    branch_type integer NOT NULL,
    reviewer integer,
    date_last_modified timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    registrant integer NOT NULL,
    branch_format integer,
    repository_format integer,
    metadir_format integer,
    stacked_on integer,
    distroseries integer,
    sourcepackagename integer,
    owner_name text NOT NULL,
    target_suffix text,
    unique_name text,
    size_on_disk bigint,
    merge_queue integer,
    merge_queue_config text,
    transitively_private boolean DEFAULT true NOT NULL,
    access_policy integer,
    CONSTRAINT branch_type_url_consistent CHECK (((((branch_type = 2) AND (url IS NOT NULL)) OR ((branch_type = ANY (ARRAY[1, 3])) AND (url IS NULL))) OR (branch_type = 4))),
    CONSTRAINT branch_url_no_trailing_slash CHECK ((url !~~ '%/'::text)),
    CONSTRAINT branch_url_not_supermirror CHECK ((url !~~ 'http://bazaar.launchpad.net/%'::text)),
    CONSTRAINT one_container CHECK ((((distroseries IS NULL) = (sourcepackagename IS NULL)) AND ((distroseries IS NULL) OR (product IS NULL)))),
    CONSTRAINT valid_home_page CHECK (valid_absolute_url(home_page)),
    CONSTRAINT valid_name CHECK (valid_branch_name(name)),
    CONSTRAINT valid_url CHECK (valid_absolute_url(url))
);


COMMENT ON TABLE branch IS 'Bzr branch';


COMMENT ON COLUMN branch.summary IS 'A single paragraph description of the branch';


COMMENT ON COLUMN branch.home_page IS 'This column is deprecated and to be removed soon.';


COMMENT ON COLUMN branch.whiteboard IS 'Notes on the current status of the branch';


COMMENT ON COLUMN branch.lifecycle_status IS 'Authors assesment of the branchs maturity';


COMMENT ON COLUMN branch.last_mirrored IS 'The time when the branch was last mirrored.';


COMMENT ON COLUMN branch.mirror_status_message IS 'The last message we got when mirroring this branch.';


COMMENT ON COLUMN branch.last_scanned IS 'The time when the branch was last scanned.';


COMMENT ON COLUMN branch.last_scanned_id IS 'The revision ID of the branch when it was last scanned.';


COMMENT ON COLUMN branch.last_mirrored_id IS 'The revision ID of the branch when it was last mirrored.';


COMMENT ON COLUMN branch.revision_count IS 'The number of revisions in the associated bazaar branch revision_history.';


COMMENT ON COLUMN branch.next_mirror_time IS 'The time when we will next mirror this branch (NULL means never). This will be set automatically by pushing to a hosted branch, which, once mirrored, will be set back to NULL.';


COMMENT ON COLUMN branch.private IS 'If the branch is private, then only the owner and subscribers of the branch can see it.';


COMMENT ON COLUMN branch.branch_type IS 'Branches are currently one of HOSTED (1), MIRRORED (2), or IMPORTED (3).';


COMMENT ON COLUMN branch.reviewer IS 'The reviewer (person or) team are able to transition merge proposals targetted at the branch throught the CODE_APPROVED state.';


COMMENT ON COLUMN branch.date_last_modified IS 'A branch is modified any time a user updates something using a view, a new revision for the branch is scanned, or the branch is linked to a bug, blueprint or merge proposal.';


COMMENT ON COLUMN branch.registrant IS 'The user that registered the branch.';


COMMENT ON COLUMN branch.branch_format IS 'The bzr branch format';


COMMENT ON COLUMN branch.repository_format IS 'The bzr repository format';


COMMENT ON COLUMN branch.metadir_format IS 'The bzr metadir format';


COMMENT ON COLUMN branch.stacked_on IS 'The Launchpad branch that this branch is stacked on (if any).';


COMMENT ON COLUMN branch.distroseries IS 'The distribution series that the branch belongs to.';


COMMENT ON COLUMN branch.sourcepackagename IS 'The source package this is a branch of.';


COMMENT ON COLUMN branch.size_on_disk IS 'The size in bytes of this branch in the mirrored area.';


COMMENT ON COLUMN branch.merge_queue IS 'A reference to the BranchMergeQueue record that manages merges.';


COMMENT ON COLUMN branch.merge_queue_config IS 'A JSON string of configuration values that can be read by a merge queue script.';


CREATE SEQUENCE branch_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE branch_id_seq OWNED BY branch.id;


CREATE TABLE branchjob (
    id integer NOT NULL,
    job integer NOT NULL,
    branch integer,
    job_type integer NOT NULL,
    json_data text
);


COMMENT ON TABLE branchjob IS 'Contains references to jobs that are executed for a branch.';


COMMENT ON COLUMN branchjob.job IS 'A reference to a row in the Job table that has all the common job details.';


COMMENT ON COLUMN branchjob.branch IS 'The branch that this job is for.';


COMMENT ON COLUMN branchjob.job_type IS 'The type of job, like new revisions, or attribute change.';


COMMENT ON COLUMN branchjob.json_data IS 'Data that is specific to the type of job, whether this be the revisions to send email out for, or the changes that were recorded for the branch.';


CREATE SEQUENCE branchjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE branchjob_id_seq OWNED BY branchjob.id;


CREATE TABLE branchmergeproposal (
    id integer NOT NULL,
    registrant integer NOT NULL,
    source_branch integer NOT NULL,
    target_branch integer NOT NULL,
    dependent_branch integer,
    whiteboard text,
    date_merged timestamp without time zone,
    merged_revno integer,
    merge_reporter integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    commit_message text,
    queue_position integer,
    queue_status integer DEFAULT 1 NOT NULL,
    date_review_requested timestamp without time zone,
    reviewer integer,
    date_reviewed timestamp without time zone,
    reviewed_revision_id text,
    queuer integer,
    date_queued timestamp without time zone,
    queued_revision_id text,
    merger integer,
    merged_revision_id text,
    date_merge_started timestamp without time zone,
    date_merge_finished timestamp without time zone,
    merge_log_file integer,
    superseded_by integer,
    root_message_id text,
    merge_diff integer,
    description text,
    CONSTRAINT different_branches CHECK ((((source_branch <> target_branch) AND (dependent_branch <> source_branch)) AND (dependent_branch <> target_branch))),
    CONSTRAINT positive_revno CHECK (((merged_revno IS NULL) OR (merged_revno > 0)))
);


COMMENT ON TABLE branchmergeproposal IS 'Branch merge proposals record the intent of landing (or merging) one branch on another.';


COMMENT ON COLUMN branchmergeproposal.registrant IS 'The person that created the merge proposal.';


COMMENT ON COLUMN branchmergeproposal.source_branch IS 'The branch where the work is being written.  This branch contains the changes that the registrant wants to land.';


COMMENT ON COLUMN branchmergeproposal.target_branch IS 'The branch where the user wants the changes from the source branch to be merged into.';


COMMENT ON COLUMN branchmergeproposal.dependent_branch IS 'If the source branch was not branched off the target branch, then this is considered the dependent_branch.';


COMMENT ON COLUMN branchmergeproposal.whiteboard IS 'Used to write other information about the branch, like test URLs.';


COMMENT ON COLUMN branchmergeproposal.date_merged IS 'This is the date that merge occurred.';


COMMENT ON COLUMN branchmergeproposal.merged_revno IS 'This is the revision number of the revision on the target branch that includes the merge from the source branch.';


COMMENT ON COLUMN branchmergeproposal.merge_reporter IS 'This is the user that marked the proposal as merged.';


COMMENT ON COLUMN branchmergeproposal.date_created IS 'When the registrant created the merge proposal.';


COMMENT ON COLUMN branchmergeproposal.commit_message IS 'This is the commit message that is to be used when the branch is landed by a robot.';


COMMENT ON COLUMN branchmergeproposal.queue_position IS 'The position on the merge proposal in the overall landing queue.  If the branch has a merge_robot set and the merge robot controls multiple branches then the queue position is unique over all the queued merge proposals for the landing robot.';


COMMENT ON COLUMN branchmergeproposal.queue_status IS 'This is the current state of the merge proposal.';


COMMENT ON COLUMN branchmergeproposal.date_review_requested IS 'The date that the merge proposal enters the REVIEW_REQUESTED state. This is stored so that we can determine how long a branch has been waiting for code approval.';


COMMENT ON COLUMN branchmergeproposal.reviewer IS 'The individual who said that the code in this branch is OK to land.';


COMMENT ON COLUMN branchmergeproposal.date_reviewed IS 'When the reviewer said the code is OK to land.';


COMMENT ON COLUMN branchmergeproposal.reviewed_revision_id IS 'The Bazaar revision ID that was approved to land.';


COMMENT ON COLUMN branchmergeproposal.queuer IS 'The individual who submitted the branch to the merge queue. This is usually the merge proposal registrant.';


COMMENT ON COLUMN branchmergeproposal.date_queued IS 'When the queuer submitted the branch to the merge queue.';


COMMENT ON COLUMN branchmergeproposal.queued_revision_id IS 'The Bazaar revision ID that is queued to land.';


COMMENT ON COLUMN branchmergeproposal.merger IS 'The merger is the person who merged the branch.';


COMMENT ON COLUMN branchmergeproposal.merged_revision_id IS 'The Bazaar revision ID that was actually merged.  If the owner of the source branch is a trusted person, this may be different than the revision_id that was actually queued or reviewed.';


COMMENT ON COLUMN branchmergeproposal.date_merge_started IS 'If the merge is performed by a bot the time the merge was started is recorded otherwise it is NULL.';


COMMENT ON COLUMN branchmergeproposal.date_merge_finished IS 'If the merge is performed by a bot the time the merge was finished is recorded otherwise it is NULL.';


COMMENT ON COLUMN branchmergeproposal.merge_log_file IS 'If the merge is performed by a bot the log file is accessible from the librarian.';


COMMENT ON COLUMN branchmergeproposal.superseded_by IS 'The proposal to merge has been superceded by this one.';


COMMENT ON COLUMN branchmergeproposal.root_message_id IS 'The root message of this BranchMergeProposal''s mail thread.';


COMMENT ON COLUMN branchmergeproposal.merge_diff IS 'The diff showing the predicted result of a merge.';


CREATE SEQUENCE branchmergeproposal_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE branchmergeproposal_id_seq OWNED BY branchmergeproposal.id;


CREATE TABLE branchmergeproposaljob (
    id integer NOT NULL,
    job integer NOT NULL,
    branch_merge_proposal integer NOT NULL,
    job_type integer NOT NULL,
    json_data text
);


COMMENT ON TABLE branchmergeproposaljob IS 'Contains references to jobs that are executed for a branch merge proposal.';


COMMENT ON COLUMN branchmergeproposaljob.job IS 'A reference to a row in the Job table that has all the common job details.';


COMMENT ON COLUMN branchmergeproposaljob.branch_merge_proposal IS 'The branch merge proposal that this job is for.';


COMMENT ON COLUMN branchmergeproposaljob.job_type IS 'The type of job, like new proposal, review comment, or new review requested.';


COMMENT ON COLUMN branchmergeproposaljob.json_data IS 'Data that is specific to the type of job, normally references to code review messages and or votes.';


CREATE SEQUENCE branchmergeproposaljob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE branchmergeproposaljob_id_seq OWNED BY branchmergeproposaljob.id;


CREATE TABLE branchmergequeue (
    id integer NOT NULL,
    registrant integer NOT NULL,
    owner integer NOT NULL,
    name text NOT NULL,
    description text,
    configuration text,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE branchmergequeue IS 'Queue for managing the merge workflow for branches.';


COMMENT ON COLUMN branchmergequeue.id IS 'The id of the merge queue.';


COMMENT ON COLUMN branchmergequeue.registrant IS 'A reference to the person who created the merge queue.';


COMMENT ON COLUMN branchmergequeue.owner IS 'A reference to the person who owns the merge queue.';


COMMENT ON COLUMN branchmergequeue.name IS 'The name of the queue.';


COMMENT ON COLUMN branchmergequeue.description IS 'A description of the queue.';


COMMENT ON COLUMN branchmergequeue.configuration IS 'A JSON string of configuration data to be read by the merging script.';


COMMENT ON COLUMN branchmergequeue.date_created IS 'The date the queue was created.';


CREATE SEQUENCE branchmergequeue_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE branchmergequeue_id_seq OWNED BY branchmergequeue.id;


CREATE TABLE branchrevision (
    sequence integer,
    branch integer NOT NULL,
    revision integer NOT NULL
)
WITH (fillfactor=100);
ALTER TABLE ONLY branchrevision ALTER COLUMN branch SET STATISTICS 500;
ALTER TABLE ONLY branchrevision ALTER COLUMN revision SET STATISTICS 500;


CREATE TABLE branchsubscription (
    id integer NOT NULL,
    person integer NOT NULL,
    branch integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    notification_level integer DEFAULT 1 NOT NULL,
    max_diff_lines integer,
    review_level integer DEFAULT 0 NOT NULL,
    subscribed_by integer NOT NULL
);


COMMENT ON TABLE branchsubscription IS 'An association between a person or team and a bazaar branch.';


COMMENT ON COLUMN branchsubscription.person IS 'The person or team associated with the branch.';


COMMENT ON COLUMN branchsubscription.branch IS 'The branch associated with the person or team.';


COMMENT ON COLUMN branchsubscription.notification_level IS 'The level of email the person wants to receive from branch updates.';


COMMENT ON COLUMN branchsubscription.max_diff_lines IS 'If the generated diff for a revision is larger than this number, then the diff is not sent in the notification email.';


COMMENT ON COLUMN branchsubscription.review_level IS 'The level of email the person wants to receive from review activity';


CREATE SEQUENCE branchsubscription_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE branchsubscription_id_seq OWNED BY branchsubscription.id;


CREATE TABLE branchvisibilitypolicy (
    id integer NOT NULL,
    project integer,
    product integer,
    team integer,
    policy integer DEFAULT 1 NOT NULL,
    CONSTRAINT only_one_target CHECK (((project IS NULL) <> (product IS NULL)))
);


COMMENT ON TABLE branchvisibilitypolicy IS 'Defines the policy for the initial visibility of branches.';


COMMENT ON COLUMN branchvisibilitypolicy.project IS 'Even though projects don''t directly have branches themselves, if a product of the project does not specify its own branch visibility policies, those of the project are used.';


COMMENT ON COLUMN branchvisibilitypolicy.product IS 'The product that the visibility policies apply to.';


COMMENT ON COLUMN branchvisibilitypolicy.team IS 'Refers to the team that the policy applies to.  NULL is used to indicate ALL people, as there is no team defined for *everybody*.';


COMMENT ON COLUMN branchvisibilitypolicy.policy IS 'An enumerated type, one of PUBLIC or PRIVATE.  PUBLIC is the default value.';


CREATE SEQUENCE branchvisibilitypolicy_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE branchvisibilitypolicy_id_seq OWNED BY branchvisibilitypolicy.id;


CREATE SEQUENCE bug_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bug_id_seq OWNED BY bug.id;


CREATE TABLE bugactivity (
    id integer NOT NULL,
    bug integer NOT NULL,
    datechanged timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    person integer NOT NULL,
    whatchanged text NOT NULL,
    oldvalue text,
    newvalue text,
    message text
)
WITH (fillfactor=100);


CREATE SEQUENCE bugactivity_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugactivity_id_seq OWNED BY bugactivity.id;


CREATE TABLE bugaffectsperson (
    id integer NOT NULL,
    bug integer NOT NULL,
    person integer NOT NULL,
    affected boolean DEFAULT true NOT NULL
);


COMMENT ON TABLE bugaffectsperson IS 'This table maintains a mapping between bugs and users indicating that they are affected by that bug. The value is calculated and cached in the Bug.users_affected_count column.';


COMMENT ON COLUMN bugaffectsperson.bug IS 'The bug affecting this person.';


COMMENT ON COLUMN bugaffectsperson.person IS 'The person affected by this bug.';


CREATE SEQUENCE bugaffectsperson_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugaffectsperson_id_seq OWNED BY bugaffectsperson.id;


CREATE TABLE bugattachment (
    id integer NOT NULL,
    message integer NOT NULL,
    name text,
    title text,
    libraryfile integer NOT NULL,
    bug integer NOT NULL,
    type integer NOT NULL,
    CONSTRAINT valid_name CHECK (valid_name(name))
);


CREATE SEQUENCE bugattachment_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugattachment_id_seq OWNED BY bugattachment.id;


CREATE TABLE bugbranch (
    id integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    bug integer NOT NULL,
    branch integer NOT NULL,
    revision_hint integer,
    whiteboard text,
    registrant integer NOT NULL
);


COMMENT ON TABLE bugbranch IS 'A branch related to a bug, most likely a branch for fixing the bug.';


COMMENT ON COLUMN bugbranch.bug IS 'The bug associated with this branch.';


COMMENT ON COLUMN bugbranch.branch IS 'The branch associated to the bug.';


COMMENT ON COLUMN bugbranch.revision_hint IS 'An optional revision at which this branch became interesting to this bug, and/or may contain a fix for the bug.';


COMMENT ON COLUMN bugbranch.whiteboard IS 'Additional information about the status of the bugfix in this branch.';


COMMENT ON COLUMN bugbranch.registrant IS 'The person who linked the bug to the branch.';


CREATE SEQUENCE bugbranch_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugbranch_id_seq OWNED BY bugbranch.id;


CREATE TABLE bugcve (
    id integer NOT NULL,
    bug integer NOT NULL,
    cve integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE bugcve IS 'A table that records the link between a given malone bug number, and a CVE entry.';


CREATE SEQUENCE bugcve_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugcve_id_seq OWNED BY bugcve.id;


CREATE TABLE bugjob (
    id integer NOT NULL,
    job integer NOT NULL,
    bug integer NOT NULL,
    job_type integer NOT NULL,
    json_data text
);


COMMENT ON TABLE bugjob IS 'Contains references to jobs to be run against Bugs.';


COMMENT ON COLUMN bugjob.bug IS 'The bug on which the job is to be run.';


COMMENT ON COLUMN bugjob.job_type IS 'The type of job (enumeration value). Allows us to query the database for a given subset of BugJobs.';


COMMENT ON COLUMN bugjob.json_data IS 'A JSON struct containing data for the job.';


CREATE SEQUENCE bugjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugjob_id_seq OWNED BY bugjob.id;


CREATE TABLE bugmessage (
    id integer NOT NULL,
    bug integer NOT NULL,
    message integer NOT NULL,
    bugwatch integer,
    remote_comment_id text,
    index integer NOT NULL,
    owner integer NOT NULL,
    CONSTRAINT imported_comment CHECK (((remote_comment_id IS NULL) OR (bugwatch IS NOT NULL)))
);


COMMENT ON TABLE bugmessage IS 'This table maps a message to a bug. In other words, it shows that a particular message is associated with a particular bug.';


COMMENT ON COLUMN bugmessage.bugwatch IS 'The external bug this bug comment was imported from.';


COMMENT ON COLUMN bugmessage.remote_comment_id IS 'The id this bug comment has in the external bug tracker, if it is an imported comment. If it is NULL while having a bugwatch set, this comment was added in Launchpad and needs to be pushed to the external bug tracker.';


COMMENT ON COLUMN bugmessage.index IS 'The index (used in urls) of the message in a particular bug.';


CREATE SEQUENCE bugmessage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugmessage_id_seq OWNED BY bugmessage.id;


CREATE TABLE bugmute (
    person integer NOT NULL,
    bug integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


CREATE TABLE bugnomination (
    id integer NOT NULL,
    bug integer NOT NULL,
    distroseries integer,
    productseries integer,
    status integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()),
    date_decided timestamp without time zone,
    owner integer NOT NULL,
    decider integer,
    CONSTRAINT distroseries_or_productseries CHECK (((distroseries IS NULL) <> (productseries IS NULL)))
);


COMMENT ON TABLE bugnomination IS 'A bug nominated for fixing in a distroseries or productseries';


COMMENT ON COLUMN bugnomination.bug IS 'The bug being nominated.';


COMMENT ON COLUMN bugnomination.distroseries IS 'The distroseries for which the bug is nominated.';


COMMENT ON COLUMN bugnomination.productseries IS 'The productseries for which the bug is nominated.';


COMMENT ON COLUMN bugnomination.status IS 'The status of the nomination.';


COMMENT ON COLUMN bugnomination.date_created IS 'The date the nomination was submitted.';


COMMENT ON COLUMN bugnomination.date_decided IS 'The date the nomination was approved or declined.';


COMMENT ON COLUMN bugnomination.owner IS 'The person that submitted the nomination';


COMMENT ON COLUMN bugnomination.decider IS 'The person who approved or declined the nomination';


CREATE SEQUENCE bugnomination_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugnomination_id_seq OWNED BY bugnomination.id;


CREATE TABLE bugnotification (
    id integer NOT NULL,
    bug integer NOT NULL,
    message integer NOT NULL,
    is_comment boolean NOT NULL,
    date_emailed timestamp without time zone,
    status integer DEFAULT 10 NOT NULL,
    activity integer
);


COMMENT ON TABLE bugnotification IS 'The text representation of changes to a bug, which are used to send email notifications to bug changes.';


COMMENT ON COLUMN bugnotification.bug IS 'The bug that was changed.';


COMMENT ON COLUMN bugnotification.message IS 'The message the contains the textual representation of the change.';


COMMENT ON COLUMN bugnotification.is_comment IS 'Is the change a comment addition.';


COMMENT ON COLUMN bugnotification.date_emailed IS 'When this notification was emailed to the bug subscribers.';


CREATE SEQUENCE bugnotification_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugnotification_id_seq OWNED BY bugnotification.id;


CREATE TABLE bugnotificationarchive (
    id integer NOT NULL,
    bug integer,
    message integer,
    is_comment boolean,
    date_emailed timestamp without time zone
);


CREATE TABLE bugnotificationattachment (
    id integer NOT NULL,
    message integer NOT NULL,
    bug_notification integer NOT NULL
);


COMMENT ON TABLE bugnotificationattachment IS 'Attachments to be attached to a bug notification.';


COMMENT ON COLUMN bugnotificationattachment.message IS 'A message to be attached to the sent bug notification. It will be attached as a mime/multipart part, with a content type of message/rfc822.';


COMMENT ON COLUMN bugnotificationattachment.bug_notification IS 'The bug notification, to which things should be attached to.';


CREATE SEQUENCE bugnotificationattachment_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugnotificationattachment_id_seq OWNED BY bugnotificationattachment.id;


CREATE TABLE bugnotificationfilter (
    bug_notification integer NOT NULL,
    bug_subscription_filter integer NOT NULL
);


CREATE TABLE bugnotificationrecipient (
    id integer NOT NULL,
    bug_notification integer NOT NULL,
    person integer NOT NULL,
    reason_header text NOT NULL,
    reason_body text NOT NULL
);


COMMENT ON TABLE bugnotificationrecipient IS 'The recipient for a bug notification.';


COMMENT ON COLUMN bugnotificationrecipient.bug_notification IS 'The notification this recipient should get.';


COMMENT ON COLUMN bugnotificationrecipient.person IS 'The person who should receive this notification.';


COMMENT ON COLUMN bugnotificationrecipient.reason_header IS 'The reason this person is receiving this notification (the value for the X-Launchpad-Message-Rationale header).';


COMMENT ON COLUMN bugnotificationrecipient.reason_body IS 'A line of text describing the reason this person is receiving this notification (to be included in the email message).';


CREATE SEQUENCE bugnotificationrecipient_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugnotificationrecipient_id_seq OWNED BY bugnotificationrecipient.id;


CREATE TABLE bugnotificationrecipientarchive (
    id integer NOT NULL,
    bug_notification integer,
    person integer,
    reason_header text,
    reason_body text
);


CREATE SEQUENCE bugsubscription_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugsubscription_id_seq OWNED BY bugsubscription.id;


CREATE TABLE bugsubscriptionfilter (
    id integer NOT NULL,
    structuralsubscription integer,
    find_all_tags boolean NOT NULL,
    include_any_tags boolean NOT NULL,
    exclude_any_tags boolean NOT NULL,
    other_parameters text,
    description text,
    bug_notification_level integer DEFAULT 40 NOT NULL
);


COMMENT ON TABLE bugsubscriptionfilter IS 'A filter with search criteria. Emails are sent only if the affected bug matches the specified parameters. The parameters are the same as those used for bugtask searches.';


COMMENT ON COLUMN bugsubscriptionfilter.structuralsubscription IS 'The structural subscription to be filtered.';


COMMENT ON COLUMN bugsubscriptionfilter.find_all_tags IS 'If set, search for bugs having all tags specified in BugSubscriptionFilterTag, else search for bugs having any of the tags specified in BugSubscriptionFilterTag.';


COMMENT ON COLUMN bugsubscriptionfilter.include_any_tags IS 'If True, include messages for bugs having any tag set.';


COMMENT ON COLUMN bugsubscriptionfilter.exclude_any_tags IS 'If True, exclude bugs having any tag set.';


COMMENT ON COLUMN bugsubscriptionfilter.other_parameters IS 'Other filter paremeters. Actual filtering is implemented on Python level.';


COMMENT ON COLUMN bugsubscriptionfilter.description IS 'A description of the filter, allowing subscribers to note the intent of the filter.';


CREATE SEQUENCE bugsubscriptionfilter_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugsubscriptionfilter_id_seq OWNED BY bugsubscriptionfilter.id;


CREATE TABLE bugsubscriptionfilterimportance (
    id integer NOT NULL,
    filter integer NOT NULL,
    importance integer NOT NULL
);


COMMENT ON TABLE bugsubscriptionfilterimportance IS 'Filter a bugsubscription by bug task status.';


COMMENT ON COLUMN bugsubscriptionfilterimportance.filter IS 'The subscription filter of this record.';


COMMENT ON COLUMN bugsubscriptionfilterimportance.importance IS 'The bug task importance.';


CREATE SEQUENCE bugsubscriptionfilterimportance_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugsubscriptionfilterimportance_id_seq OWNED BY bugsubscriptionfilterimportance.id;


CREATE TABLE bugsubscriptionfiltermute (
    person integer NOT NULL,
    filter integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


CREATE TABLE bugsubscriptionfilterstatus (
    id integer NOT NULL,
    filter integer NOT NULL,
    status integer NOT NULL
);


COMMENT ON TABLE bugsubscriptionfilterstatus IS 'Filter a bugsubscription by bug task status.';


COMMENT ON COLUMN bugsubscriptionfilterstatus.filter IS 'The subscription filter of this record.';


COMMENT ON COLUMN bugsubscriptionfilterstatus.status IS 'The bug task status.';


CREATE SEQUENCE bugsubscriptionfilterstatus_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugsubscriptionfilterstatus_id_seq OWNED BY bugsubscriptionfilterstatus.id;


CREATE TABLE bugsubscriptionfiltertag (
    id integer NOT NULL,
    filter integer NOT NULL,
    tag text NOT NULL,
    include boolean NOT NULL
);


COMMENT ON TABLE bugsubscriptionfiltertag IS 'Filter by bug tag.';


COMMENT ON COLUMN bugsubscriptionfiltertag.filter IS 'The subscription filter of this record.';


COMMENT ON COLUMN bugsubscriptionfiltertag.tag IS 'A bug tag.';


COMMENT ON COLUMN bugsubscriptionfiltertag.include IS 'If True, send only messages for bugs having this tag, else send only messages for bugs which do not have this tag.';


CREATE SEQUENCE bugsubscriptionfiltertag_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugsubscriptionfiltertag_id_seq OWNED BY bugsubscriptionfiltertag.id;


CREATE SEQUENCE bugsummary_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugsummary_id_seq OWNED BY bugsummary.id;


CREATE TABLE bugsummaryjournal (
    id integer NOT NULL,
    count integer DEFAULT 0 NOT NULL,
    product integer,
    productseries integer,
    distribution integer,
    distroseries integer,
    sourcepackagename integer,
    viewed_by integer,
    tag text,
    status integer NOT NULL,
    milestone integer,
    importance integer NOT NULL,
    has_patch boolean NOT NULL,
    fixed_upstream boolean NOT NULL
);


CREATE SEQUENCE bugsummaryjournal_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugsummaryjournal_id_seq OWNED BY bugsummaryjournal.id;


CREATE SEQUENCE bugtag_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugtag_id_seq OWNED BY bugtag.id;


CREATE SEQUENCE bugtask_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugtask_id_seq OWNED BY bugtask.id;


CREATE TABLE bugtracker (
    id integer NOT NULL,
    bugtrackertype integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    summary text,
    baseurl text NOT NULL,
    owner integer NOT NULL,
    contactdetails text,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    version text,
    block_comment_pushing boolean DEFAULT false NOT NULL,
    has_lp_plugin boolean,
    active boolean DEFAULT true NOT NULL,
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE bugtracker IS 'A bug tracker in some other project. Malone allows us to link Malone bugs with bugs recorded in other bug tracking systems, and to keep the status of the relevant bug task in sync with the status in that upstream bug tracker. So, for example, you might note that Malone bug #43224 is the same as a bug in the Apache bugzilla, number 534536. Then when the upstream guys mark that bug fixed in their bugzilla, Malone know that the bug is fixed upstream.';


COMMENT ON COLUMN bugtracker.bugtrackertype IS 'The type of bug tracker, a pointer to the table of bug tracker types. Currently we know about debbugs and bugzilla bugtrackers, and plan to support roundup and sourceforge as well.';


COMMENT ON COLUMN bugtracker.name IS 'The unique name of this bugtracker, allowing us to refer to it directly.';


COMMENT ON COLUMN bugtracker.title IS 'A title for the bug tracker, used in listings of all the bug trackers and also displayed at the top of the descriptive page for the bug tracker.';


COMMENT ON COLUMN bugtracker.summary IS 'A brief summary of this bug tracker, which might for example list any interesting policies regarding the use of the bug tracker. The summary is displayed in bold at the top of the bug tracker page.';


COMMENT ON COLUMN bugtracker.baseurl IS 'The base URL for this bug tracker. Using our knowledge of the bugtrackertype, and the details in the BugWatch table we are then able to calculate relative URLs for relevant pages in the bug tracker based on this baseurl.';


COMMENT ON COLUMN bugtracker.owner IS 'The person who created this bugtracker entry and who thus has permission to modify it. Ideally we would like this to be the person who coordinates the running of the actual bug tracker upstream.';


COMMENT ON COLUMN bugtracker.contactdetails IS 'The contact details of the people responsible for that bug tracker. This allows us to coordinate the syncing of bugs to and from that bug tracker with the responsible people on the other side.';


COMMENT ON COLUMN bugtracker.version IS 'The version of the bug tracker software being used.';


COMMENT ON COLUMN bugtracker.block_comment_pushing IS 'Whether to block pushing comments to the bug tracker. Having a value of false means that we will push the comments if the bug tracker supports it.';


COMMENT ON COLUMN bugtracker.has_lp_plugin IS 'Whether we have confirmed that the Launchpad plugin was installed on the bug tracker, the last time checkwatches was run.';


CREATE SEQUENCE bugtracker_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugtracker_id_seq OWNED BY bugtracker.id;


CREATE TABLE bugtrackeralias (
    id integer NOT NULL,
    bugtracker integer NOT NULL,
    base_url text NOT NULL
);


COMMENT ON TABLE bugtrackeralias IS 'A bugtracker alias is a URL that also refers to the same bugtracker as the master bugtracker. For example, a bugtracker might be accessible as both http://www.bugsrus.com/ and http://bugsrus.com/. A bugtracker can have many aliases, and all of them are checked to prevents users registering duplicate bugtrackers inadvertently.';


COMMENT ON COLUMN bugtrackeralias.bugtracker IS 'The master bugtracker that this alias refers to.';


COMMENT ON COLUMN bugtrackeralias.base_url IS 'Another base URL for this bug tracker. See BugTracker.baseurl.';


CREATE SEQUENCE bugtrackeralias_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugtrackeralias_id_seq OWNED BY bugtrackeralias.id;


CREATE TABLE bugtrackercomponent (
    id integer NOT NULL,
    name text NOT NULL,
    is_visible boolean DEFAULT true NOT NULL,
    is_custom boolean DEFAULT true NOT NULL,
    component_group integer NOT NULL,
    distribution integer,
    source_package_name integer,
    CONSTRAINT valid_target CHECK (((distribution IS NULL) = (source_package_name IS NULL)))
);


COMMENT ON TABLE bugtrackercomponent IS 'A software component in a remote bug tracker, which can be linked to the corresponding source package in a distribution using this table.';


COMMENT ON COLUMN bugtrackercomponent.name IS 'The name of the component as registered in the remote bug tracker.';


COMMENT ON COLUMN bugtrackercomponent.is_visible IS 'Whether to display or hide the item in the Launchpad user interface.';


COMMENT ON COLUMN bugtrackercomponent.is_custom IS 'Whether the item was added by a user in Launchpad or is kept in sync with the remote bug tracker.';


COMMENT ON COLUMN bugtrackercomponent.component_group IS 'The product or other higher level category used by the remote bug tracker to group projects, if any.';


COMMENT ON COLUMN bugtrackercomponent.distribution IS 'Link to the distribution for the associated source package.  This can be NULL if no ling has been established.';


COMMENT ON COLUMN bugtrackercomponent.source_package_name IS 'The text name of the source package in a distribution that corresponds to this component.  This can be NULL if no link has been established yet.';


CREATE SEQUENCE bugtrackercomponent_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugtrackercomponent_id_seq OWNED BY bugtrackercomponent.id;


CREATE TABLE bugtrackercomponentgroup (
    id integer NOT NULL,
    name text NOT NULL,
    bug_tracker integer NOT NULL
);


COMMENT ON TABLE bugtrackercomponentgroup IS 'A collection of components as modeled in a remote bug tracker, often referred to as a product.  Some bug trackers do not categorize software components this way, so they will have a single default component group that all components belong to.';


COMMENT ON COLUMN bugtrackercomponentgroup.name IS 'The product or category name used in the remote bug tracker for grouping components.';


COMMENT ON COLUMN bugtrackercomponentgroup.bug_tracker IS 'The external bug tracker this component group belongs to.';


CREATE SEQUENCE bugtrackercomponentgroup_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugtrackercomponentgroup_id_seq OWNED BY bugtrackercomponentgroup.id;


CREATE TABLE bugtrackerperson (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    bugtracker integer NOT NULL,
    person integer NOT NULL,
    name text NOT NULL
);


COMMENT ON TABLE bugtrackerperson IS 'A mapping from a user in an external bug tracker to a Person record in Launchpad. This is used when we can''t get an e-mail address from the bug tracker.';


COMMENT ON COLUMN bugtrackerperson.date_created IS 'When was this mapping added.';


COMMENT ON COLUMN bugtrackerperson.bugtracker IS 'The external bug tracker in which this user has an account.';


COMMENT ON COLUMN bugtrackerperson.person IS 'The Person record in Launchpad this user corresponds to.';


COMMENT ON COLUMN bugtrackerperson.name IS 'The (within the bug tracker) unique username in the external bug tracker.';


CREATE SEQUENCE bugtrackerperson_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugtrackerperson_id_seq OWNED BY bugtrackerperson.id;


CREATE TABLE bugwatch (
    id integer NOT NULL,
    bug integer NOT NULL,
    bugtracker integer NOT NULL,
    remotebug text NOT NULL,
    remotestatus text,
    lastchanged timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone),
    lastchecked timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone),
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    owner integer NOT NULL,
    last_error_type integer,
    remote_importance text,
    remote_lp_bug_id integer,
    next_check timestamp without time zone
);


COMMENT ON COLUMN bugwatch.last_error_type IS 'The type of error which last prevented this entry from being updated. Legal values are defined by the BugWatchErrorType enumeration.';


COMMENT ON COLUMN bugwatch.remote_importance IS 'The importance of the bug as returned by the remote server. This will be converted into a Launchpad BugTaskImportance value.';


COMMENT ON COLUMN bugwatch.remote_lp_bug_id IS 'The bug in Launchpad that the remote bug is pointing at. This can be different than the BugWatch.bug column, since the same remote bug can be linked from multiple bugs in Launchpad, but the remote bug can only link to a single bug in Launchpad. The main use case for this column is to avoid having to query the remote bug tracker for this information, in order to decide whether we need to give this information to the remote bug tracker.';


COMMENT ON COLUMN bugwatch.next_check IS 'The time after which the watch should next be checked. Note that this does not denote an exact schedule for the next check since checkwatches only runs periodically.';


CREATE SEQUENCE bugwatch_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugwatch_id_seq OWNED BY bugwatch.id;


CREATE TABLE bugwatchactivity (
    id integer NOT NULL,
    bug_watch integer NOT NULL,
    activity_date timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    result integer NOT NULL,
    message text,
    oops_id text
)
WITH (fillfactor=100);


COMMENT ON TABLE bugwatchactivity IS 'This table contains a record of each update for a given bug watch. This allows us to track whether a given update was successful or not and, if not, the details of the error which caused the update to fail.';


COMMENT ON COLUMN bugwatchactivity.bug_watch IS 'The bug_watch to which this activity entry relates.';


COMMENT ON COLUMN bugwatchactivity.activity_date IS 'The datetime at which the activity occurred.';


COMMENT ON COLUMN bugwatchactivity.result IS 'The result of the update. Legal values are defined in the BugWatchErrorType enumeration. An update is considered successful if its error_type is NULL.';


COMMENT ON COLUMN bugwatchactivity.message IS 'The message (if any) associated with the update.';


COMMENT ON COLUMN bugwatchactivity.oops_id IS 'The OOPS id, if any, associated with the error that caused the update to fail.';


CREATE SEQUENCE bugwatchactivity_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE bugwatchactivity_id_seq OWNED BY bugwatchactivity.id;


CREATE TABLE builder (
    id integer NOT NULL,
    processor integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    description text NOT NULL,
    owner integer NOT NULL,
    speedindex integer,
    builderok boolean NOT NULL,
    failnotes text,
    virtualized boolean DEFAULT true NOT NULL,
    url text NOT NULL,
    manual boolean DEFAULT false,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    vm_host text,
    active boolean DEFAULT true NOT NULL,
    failure_count integer DEFAULT 0 NOT NULL,
    CONSTRAINT valid_absolute_url CHECK (valid_absolute_url(url))
);


COMMENT ON TABLE builder IS 'Builder: This table stores the build-slave registry and status information as: name, url, trusted, builderok, builderaction, failnotes.';


COMMENT ON COLUMN builder.speedindex IS 'A relative measure of the speed of this builder. If NULL, we do not yet have a speedindex for the builder else it is the number of seconds needed to perform a reference build';


COMMENT ON COLUMN builder.builderok IS 'Should a builder fail for any reason, from out-of-disk-space to not responding to the buildd master, the builderok flag is set to false and the failnotes column is filled with a reason.';


COMMENT ON COLUMN builder.failnotes IS 'This column gets filled out with a textual description of how/why a builder has failed. If the builderok column is true then the value in this column is irrelevant and should be treated as NULL or empty.';


COMMENT ON COLUMN builder.virtualized IS 'Whether or not the builder is a virtual Xen builder. Packages coming via ubuntu workflow are trusted to build on non-Xen and do not need facist behaviour to be built. Other packages like ppa/grumpy incoming packages can contain malicious code, so are unstrusted and build in a Xen virtual machine.';


COMMENT ON COLUMN builder.url IS 'The url to the build slave. There may be more than one build slave on a given host so this url includes the port number to use. The default port number for a build slave is 8221';


COMMENT ON COLUMN builder.manual IS 'Whether or not builder was manual mode, i.e., collect any result from the it, but do not dispach anything to it automatically.';


COMMENT ON COLUMN builder.vm_host IS 'The virtual machine host associated to this builder. It should be empty for "native" builders (old fashion or architectures not yet supported by XEN).';


COMMENT ON COLUMN builder.active IS 'Whether to present or not the builder in the public list of builders avaialble. It is used to hide transient or defunct builders while they get fixed.';


COMMENT ON COLUMN builder.failure_count IS 'The number of consecutive failures on this builder.  Is reset to zero after a sucessful dispatch.';


CREATE SEQUENCE builder_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE builder_id_seq OWNED BY builder.id;


CREATE TABLE buildfarmjob (
    id integer NOT NULL,
    processor integer,
    virtualized boolean,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_started timestamp without time zone,
    date_finished timestamp without time zone,
    date_first_dispatched timestamp without time zone,
    builder integer,
    status integer NOT NULL,
    log integer,
    job_type integer NOT NULL,
    failure_count integer DEFAULT 0 NOT NULL,
    CONSTRAINT started_if_finished CHECK (((date_finished IS NULL) OR (date_started IS NOT NULL)))
);


COMMENT ON TABLE buildfarmjob IS 'BuildFarmJob: This table stores the information common to all jobs on the Launchpad build farm.';


COMMENT ON COLUMN buildfarmjob.processor IS 'Points to the required processor target for this job, or null.';


COMMENT ON COLUMN buildfarmjob.virtualized IS 'The virtualization setting required by this build farm job, or null.';


COMMENT ON COLUMN buildfarmjob.date_created IS 'When the build farm job record was created.';


COMMENT ON COLUMN buildfarmjob.date_started IS 'When the build farm job started being processed.';


COMMENT ON COLUMN buildfarmjob.date_finished IS 'When the build farm job finished being processed.';


COMMENT ON COLUMN buildfarmjob.date_first_dispatched IS 'The instant the build was dispatched the first time. This value will not get overridden if the build is retried.';


COMMENT ON COLUMN buildfarmjob.builder IS 'Points to the builder which processed this build farm job.';


COMMENT ON COLUMN buildfarmjob.status IS 'Stores the current build status.';


COMMENT ON COLUMN buildfarmjob.log IS 'Points to the log for this build farm job file stored in librarian.';


COMMENT ON COLUMN buildfarmjob.job_type IS 'The type of build farm job to which this record corresponds.';


COMMENT ON COLUMN buildfarmjob.failure_count IS 'The number of consecutive failures on this job.  If excessive, the job may be terminated.';


CREATE SEQUENCE buildfarmjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE buildfarmjob_id_seq OWNED BY buildfarmjob.id;


CREATE TABLE buildpackagejob (
    id integer NOT NULL,
    job integer NOT NULL,
    build integer NOT NULL
);


CREATE SEQUENCE buildpackagejob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE buildpackagejob_id_seq OWNED BY buildpackagejob.id;


CREATE TABLE buildqueue (
    id integer NOT NULL,
    builder integer,
    logtail text,
    lastscore integer,
    manual boolean DEFAULT false NOT NULL,
    job integer NOT NULL,
    job_type integer DEFAULT 1 NOT NULL,
    estimated_duration interval DEFAULT '00:00:00'::interval NOT NULL,
    processor integer,
    virtualized boolean
);


COMMENT ON TABLE buildqueue IS 'BuildQueue: The queue of jobs in progress/scheduled to run on the Soyuz build farm.';


COMMENT ON COLUMN buildqueue.builder IS 'The builder assigned to this build. Some builds will have a builder assigned to queue them up; some will be building on the specified builder already; others will not have a builder yet (NULL) and will be waiting to be assigned into a builder''s queue';


COMMENT ON COLUMN buildqueue.logtail IS 'The tail end of the log of the current build. This is updated regularly as the buildd master polls the buildd slaves. Once the build is complete; the full log will be lodged with the librarian and linked into the build table.';


COMMENT ON COLUMN buildqueue.lastscore IS 'The last score ascribed to this build record. This can be used in the UI among other places.';


COMMENT ON COLUMN buildqueue.manual IS 'Indicates if the current record was or not rescored manually, if so it get skipped from the auto-score procedure.';


COMMENT ON COLUMN buildqueue.job IS 'Foreign key to the `Job` table row with the generic job data.';


COMMENT ON COLUMN buildqueue.job_type IS 'Type of job (enumeration value), enables us to find/query the correct table with the data specific to this type of job.';


COMMENT ON COLUMN buildqueue.estimated_duration IS 'Estimated job duration, based on previous running times of comparable jobs.';


COMMENT ON COLUMN buildqueue.processor IS 'The processor required by the associated build farm job.';


COMMENT ON COLUMN buildqueue.virtualized IS 'The virtualization setting required by the associated build farm job.';


CREATE SEQUENCE buildqueue_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE buildqueue_id_seq OWNED BY buildqueue.id;


CREATE TABLE codeimport (
    id integer NOT NULL,
    branch integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    registrant integer NOT NULL,
    rcs_type integer NOT NULL,
    cvs_root text,
    cvs_module text,
    review_status integer DEFAULT 1 NOT NULL,
    date_last_successful timestamp without time zone,
    owner integer NOT NULL,
    assignee integer,
    update_interval interval,
    url text,
    CONSTRAINT valid_vcs_details CHECK (CASE WHEN (rcs_type = 1) THEN (((((cvs_root IS NOT NULL) AND (cvs_root <> ''::text)) AND (cvs_module IS NOT NULL)) AND (cvs_module <> ''::text)) AND (url IS NULL)) WHEN (rcs_type = ANY (ARRAY[2, 3])) THEN ((((cvs_root IS NULL) AND (cvs_module IS NULL)) AND (url IS NOT NULL)) AND valid_absolute_url(url)) WHEN (rcs_type = ANY (ARRAY[4, 5, 6])) THEN (((cvs_root IS NULL) AND (cvs_module IS NULL)) AND (url IS NOT NULL)) ELSE false END)
);


COMMENT ON TABLE codeimport IS 'The persistent record of an import from a foreign version control system to Bazaar, from the initial request to the regularly updated import branch.';


COMMENT ON COLUMN codeimport.branch IS 'The Bazaar branch produced by the import system.  Always non-NULL: a placeholder branch is created when the import is created.  The import is associated to a Product and Series though the branch.';


COMMENT ON COLUMN codeimport.registrant IS 'The person who originally requested this import.';


COMMENT ON COLUMN codeimport.rcs_type IS 'The revision control system used by the import source. The value is defined in dbschema.RevisionControlSystems.';


COMMENT ON COLUMN codeimport.cvs_root IS 'The $CVSROOT details, probably of the form :pserver:user@host:/path.';


COMMENT ON COLUMN codeimport.cvs_module IS 'The module in cvs_root to import, often the name of the project.';


COMMENT ON COLUMN codeimport.review_status IS 'Whether this code import request has been reviewed, and whether it was accepted.';


COMMENT ON COLUMN codeimport.date_last_successful IS 'When this code import last succeeded. NULL if this import has never succeeded.';


COMMENT ON COLUMN codeimport.owner IS 'The person who is currently responsible for keeping the import details up to date, initially set to the registrant. This person can edit some of the details of the code import branch.';


COMMENT ON COLUMN codeimport.assignee IS 'The person in charge of delivering this code import and interacting with the owner.';


COMMENT ON COLUMN codeimport.update_interval IS 'How often should this import be updated. If NULL, defaults to a system-wide value set by the Launchpad administrators.';


COMMENT ON COLUMN codeimport.url IS 'The URL of the foreign VCS branch for this import.';


CREATE SEQUENCE codeimport_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE codeimport_id_seq OWNED BY codeimport.id;


CREATE TABLE codeimportevent (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    entry_type integer NOT NULL,
    code_import integer,
    person integer,
    machine integer
);


COMMENT ON TABLE codeimportevent IS 'A record of events in the code import system.  Rows in this table are created by triggers on other code import tables.';


COMMENT ON COLUMN codeimportevent.entry_type IS 'The type of event that is recorded by this entry. Legal values are defined by the CodeImportEventType enumeration.';


COMMENT ON COLUMN codeimportevent.code_import IS 'The code import that was associated to this event, if any and if it has not been deleted.';


COMMENT ON COLUMN codeimportevent.person IS 'The user who caused the event, if the event is not automatically generated.';


COMMENT ON COLUMN codeimportevent.machine IS 'The code import machine that was concerned by this event, if any.';


CREATE SEQUENCE codeimportevent_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE codeimportevent_id_seq OWNED BY codeimportevent.id;


CREATE TABLE codeimporteventdata (
    id integer NOT NULL,
    event integer,
    data_type integer NOT NULL,
    data_value text
);


COMMENT ON TABLE codeimporteventdata IS 'Additional data associated to a particular code import event.';


COMMENT ON COLUMN codeimporteventdata.event IS 'The event the data is associated to.';


COMMENT ON COLUMN codeimporteventdata.data_type IS 'The type of additional data, from the CodeImportEventDataType enumeration.';


COMMENT ON COLUMN codeimporteventdata.data_value IS 'The value of the additional data.  A string.';


CREATE SEQUENCE codeimporteventdata_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE codeimporteventdata_id_seq OWNED BY codeimporteventdata.id;


CREATE TABLE codeimportjob (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    code_import integer NOT NULL,
    machine integer,
    date_due timestamp without time zone NOT NULL,
    state integer NOT NULL,
    requesting_user integer,
    ordering integer,
    heartbeat timestamp without time zone,
    logtail text,
    date_started timestamp without time zone,
    CONSTRAINT valid_state CHECK (CASE WHEN (state = 10) THEN (((((machine IS NULL) AND (ordering IS NULL)) AND (heartbeat IS NULL)) AND (date_started IS NULL)) AND (logtail IS NULL)) WHEN (state = 20) THEN (((((machine IS NOT NULL) AND (ordering IS NOT NULL)) AND (heartbeat IS NULL)) AND (date_started IS NULL)) AND (logtail IS NULL)) WHEN (state = 30) THEN (((((machine IS NOT NULL) AND (ordering IS NULL)) AND (heartbeat IS NOT NULL)) AND (date_started IS NOT NULL)) AND (logtail IS NOT NULL)) ELSE false END)
);


COMMENT ON TABLE codeimportjob IS 'A pending or active code import job.  There is always such a row for any active import, but it will not run until date_due is in the past.';


COMMENT ON COLUMN codeimportjob.code_import IS 'The code import that is being worked upon.';


COMMENT ON COLUMN codeimportjob.machine IS 'The machine job is currently scheduled to run on, or where the job is currently running.';


COMMENT ON COLUMN codeimportjob.date_due IS 'When the import should happen.';


COMMENT ON COLUMN codeimportjob.state IS 'One of PENDING (waiting until its due or a machine is online), SCHEDULED (assigned to a machine, but not yet running) or RUNNING (actually in the process of being imported now).';


COMMENT ON COLUMN codeimportjob.requesting_user IS 'The user who requested the import, if any. Set if and only if reason = REQUEST.';


COMMENT ON COLUMN codeimportjob.ordering IS 'A measure of how urgent the job is -- queue entries with lower "ordering" should be processed first, or in other works "ORDER BY ordering" returns the most import jobs first.';


COMMENT ON COLUMN codeimportjob.heartbeat IS 'While the job is running, this field should be updated frequently to indicate that the import job hasn''t crashed.';


COMMENT ON COLUMN codeimportjob.logtail IS 'The last few lines of output produced by the running job. It should be updated at the same time as the heartbeat.';


COMMENT ON COLUMN codeimportjob.date_started IS 'When the import began to be processed.';


CREATE SEQUENCE codeimportjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE codeimportjob_id_seq OWNED BY codeimportjob.id;


CREATE TABLE codeimportmachine (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    hostname text NOT NULL,
    state integer DEFAULT 10 NOT NULL,
    heartbeat timestamp without time zone
);


COMMENT ON TABLE codeimportmachine IS 'The record of a machine capable of performing jobs for the code import system.';


COMMENT ON COLUMN codeimportmachine.hostname IS 'The (unique) hostname of the machine.';


COMMENT ON COLUMN codeimportmachine.state IS 'Whether the controller daemon on this machine is offline, online, or quiescing (running but not accepting new jobs).';


COMMENT ON COLUMN codeimportmachine.heartbeat IS 'When the code-import-controller daemon was last known to be running on this machine. If it is not updated for a long time the machine state will change to offline.';


CREATE SEQUENCE codeimportmachine_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE codeimportmachine_id_seq OWNED BY codeimportmachine.id;


CREATE TABLE codeimportresult (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    code_import integer,
    machine integer,
    requesting_user integer,
    log_excerpt text,
    log_file integer,
    status integer NOT NULL,
    date_job_started timestamp without time zone
);


COMMENT ON TABLE codeimportresult IS 'A completed code import job.';


COMMENT ON COLUMN codeimportresult.code_import IS 'The code import for which the job was run.';


COMMENT ON COLUMN codeimportresult.machine IS 'The machine the job ran on.';


COMMENT ON COLUMN codeimportresult.log_excerpt IS 'The last few lines of the partial log, in case it is set.';


COMMENT ON COLUMN codeimportresult.log_file IS 'A partial log of the job for users to see. It is normally only recorded if the job failed in a step that interacts with the remote repository. If a job was successful, or failed in a houskeeping step, the log file would not contain information useful to the user.';


COMMENT ON COLUMN codeimportresult.status IS 'How the job ended. Success, some kind of failure, or some kind of interruption before completion.';


COMMENT ON COLUMN codeimportresult.date_job_started IS 'When the job started to run (date_created is when it finished).';


CREATE SEQUENCE codeimportresult_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE codeimportresult_id_seq OWNED BY codeimportresult.id;


CREATE TABLE codereviewmessage (
    id integer NOT NULL,
    branch_merge_proposal integer NOT NULL,
    message integer NOT NULL,
    vote integer,
    vote_tag text
);


COMMENT ON TABLE codereviewmessage IS 'A message that is part of a code review discussion.';


COMMENT ON COLUMN codereviewmessage.branch_merge_proposal IS 'The merge proposal that is being discussed.';


COMMENT ON COLUMN codereviewmessage.message IS 'The actual message.';


COMMENT ON COLUMN codereviewmessage.vote IS 'The reviewer''s vote for this message.';


COMMENT ON COLUMN codereviewmessage.vote_tag IS 'A short description of the vote';


CREATE SEQUENCE codereviewmessage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE codereviewmessage_id_seq OWNED BY codereviewmessage.id;


CREATE TABLE codereviewvote (
    id integer NOT NULL,
    branch_merge_proposal integer NOT NULL,
    reviewer integer NOT NULL,
    review_type text,
    registrant integer NOT NULL,
    vote_message integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE codereviewvote IS 'Reference to a person''s last vote in a code review discussion.';


COMMENT ON COLUMN codereviewvote.branch_merge_proposal IS 'The BranchMergeProposal for the code review.';


COMMENT ON COLUMN codereviewvote.reviewer IS 'The person performing the review.';


COMMENT ON COLUMN codereviewvote.review_type IS 'The aspect of the code being reviewed.';


COMMENT ON COLUMN codereviewvote.registrant IS 'The person who registered this vote';


COMMENT ON COLUMN codereviewvote.vote_message IS 'The message associated with the vote';


COMMENT ON COLUMN codereviewvote.date_created IS 'The date this vote reference was created';


CREATE SEQUENCE codereviewvote_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE codereviewvote_id_seq OWNED BY codereviewvote.id;


CREATE VIEW combinedbugsummary AS
    SELECT bugsummary.id, bugsummary.count, bugsummary.product, bugsummary.productseries, bugsummary.distribution, bugsummary.distroseries, bugsummary.sourcepackagename, bugsummary.viewed_by, bugsummary.tag, bugsummary.status, bugsummary.milestone, bugsummary.importance, bugsummary.has_patch, bugsummary.fixed_upstream FROM bugsummary UNION ALL SELECT (- bugsummaryjournal.id) AS id, bugsummaryjournal.count, bugsummaryjournal.product, bugsummaryjournal.productseries, bugsummaryjournal.distribution, bugsummaryjournal.distroseries, bugsummaryjournal.sourcepackagename, bugsummaryjournal.viewed_by, bugsummaryjournal.tag, bugsummaryjournal.status, bugsummaryjournal.milestone, bugsummaryjournal.importance, bugsummaryjournal.has_patch, bugsummaryjournal.fixed_upstream FROM bugsummaryjournal;


CREATE TABLE commercialsubscription (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_last_modified timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_starts timestamp without time zone NOT NULL,
    date_expires timestamp without time zone NOT NULL,
    status integer DEFAULT 10 NOT NULL,
    product integer NOT NULL,
    registrant integer NOT NULL,
    purchaser integer NOT NULL,
    whiteboard text,
    sales_system_id text
);


COMMENT ON TABLE commercialsubscription IS 'A Commercial Subscription entry for a project.  Projects with licenses of Other/Proprietary must purchase a subscription in order to use Launchpad.';


COMMENT ON COLUMN commercialsubscription.date_created IS 'The date this subscription was created in Launchpad.';


COMMENT ON COLUMN commercialsubscription.date_last_modified IS 'The date this subscription was last modified.';


COMMENT ON COLUMN commercialsubscription.date_starts IS 'The beginning date for this subscription.  It is invalid until that date.';


COMMENT ON COLUMN commercialsubscription.date_expires IS 'The expiration date for this subscription.  It is invalid after that date.';


COMMENT ON COLUMN commercialsubscription.status IS 'The current status.  One of: SUBSCRIBED, LAPSED, SUSPENDED.';


COMMENT ON COLUMN commercialsubscription.product IS 'The product this subscription enables.';


COMMENT ON COLUMN commercialsubscription.registrant IS 'The person who created this subscription.';


COMMENT ON COLUMN commercialsubscription.purchaser IS 'The person who purchased this subscription.';


COMMENT ON COLUMN commercialsubscription.whiteboard IS 'A place for administrators to store comments related to this subscription.';


COMMENT ON COLUMN commercialsubscription.sales_system_id IS 'A reference in the external sales system (e.g. Salesforce) that can be used to identify this subscription.';


CREATE SEQUENCE commercialsubscription_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE commercialsubscription_id_seq OWNED BY commercialsubscription.id;


CREATE SEQUENCE component_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE component_id_seq OWNED BY component.id;


CREATE TABLE componentselection (
    id integer NOT NULL,
    distroseries integer NOT NULL,
    component integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE componentselection IS 'Allowed components in a given distroseries.';


COMMENT ON COLUMN componentselection.distroseries IS 'Refers to the distroseries in question.';


COMMENT ON COLUMN componentselection.component IS 'Refers to the component in qestion.';


CREATE SEQUENCE componentselection_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE componentselection_id_seq OWNED BY componentselection.id;


CREATE TABLE continent (
    id integer NOT NULL,
    code text NOT NULL,
    name text NOT NULL
)
WITH (fillfactor=100);


COMMENT ON TABLE continent IS 'A continent in this huge world.';


COMMENT ON COLUMN continent.code IS 'A two-letter code for a continent.';


COMMENT ON COLUMN continent.name IS 'The name of the continent.';


CREATE SEQUENCE continent_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE continent_id_seq OWNED BY continent.id;


CREATE TABLE country (
    id integer NOT NULL,
    iso3166code2 character(2) NOT NULL,
    iso3166code3 character(3) NOT NULL,
    name text NOT NULL,
    title text,
    description text,
    continent integer NOT NULL
)
WITH (fillfactor=100);


CREATE SEQUENCE country_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE country_id_seq OWNED BY country.id;


CREATE TABLE customlanguagecode (
    id integer NOT NULL,
    product integer,
    distribution integer,
    sourcepackagename integer,
    language_code text NOT NULL,
    language integer,
    CONSTRAINT distro_and_sourcepackage CHECK (((sourcepackagename IS NULL) = (distribution IS NULL))),
    CONSTRAINT product_or_distro CHECK (((product IS NULL) <> (distribution IS NULL)))
);


COMMENT ON TABLE customlanguagecode IS 'Overrides translation importer''s interpretation of language codes where needed.';


COMMENT ON COLUMN customlanguagecode.product IS 'Product for which this custom language code applies (alternative to distribution + source package name).';


COMMENT ON COLUMN customlanguagecode.distribution IS 'Distribution in which this custom language code applies (if not a product).';


COMMENT ON COLUMN customlanguagecode.sourcepackagename IS 'Source package name to which this custom language code applies; goes with distribution.';


COMMENT ON COLUMN customlanguagecode.language_code IS 'Custom language code; need not be for a real language, and typically not for a "useful" language.';


COMMENT ON COLUMN customlanguagecode.language IS 'Language to which code really refers in this context, or NULL if files with this code are to be rejected.';


CREATE SEQUENCE customlanguagecode_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE customlanguagecode_id_seq OWNED BY customlanguagecode.id;


CREATE TABLE cve (
    id integer NOT NULL,
    sequence text NOT NULL,
    status integer NOT NULL,
    description text NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    datemodified timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    fti ts2.tsvector,
    CONSTRAINT valid_cve_ref CHECK (valid_cve(sequence))
);


COMMENT ON TABLE cve IS 'A CVE Entry. The formal database of CVE entries is available at http://cve.mitre.org/ and we sync that database into Launchpad on a regular basis.';


COMMENT ON COLUMN cve.sequence IS 'The official CVE entry number. It takes the form XXXX-XXXX where the first four digits are a year indicator, like 2004, and the latter four are the sequence number of the vulnerability in that year.';


COMMENT ON COLUMN cve.status IS 'The current status of the CVE. The values are documented in dbschema.CVEState, and are Entry, Candidate, and Deprecated.';


COMMENT ON COLUMN cve.datemodified IS 'The last time this CVE entry changed in some way - including addition or modification of references.';


CREATE SEQUENCE cve_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE cve_id_seq OWNED BY cve.id;


CREATE TABLE cvereference (
    id integer NOT NULL,
    cve integer NOT NULL,
    source text NOT NULL,
    content text NOT NULL,
    url text,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE cvereference IS 'A reference in the CVE system that shows what outside tracking numbers are associated with the CVE. These are tracked in the CVE database and extracted from the daily XML dump that we fetch.';


COMMENT ON COLUMN cvereference.source IS 'The SOURCE of the CVE reference. This is a text string, like XF or BUGTRAQ or MSKB. Each string indicates a different kind of reference. The list of known types is documented on the CVE web site. At some future date we might turn this into an enum rather than a text, but for the moment we prefer to keep it fluid and just suck in what CVE gives us. This means that CVE can add new source types without us having to update our code.';


COMMENT ON COLUMN cvereference.content IS 'The content of the ref in the CVE database. This is sometimes a comment, sometimes a description, sometimes a bug number... it is not predictable.';


COMMENT ON COLUMN cvereference.url IS 'The URL to this reference out there on the web, if it was present in the CVE database.';


CREATE SEQUENCE cvereference_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE cvereference_id_seq OWNED BY cvereference.id;


CREATE TABLE databasecpustats (
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    username text NOT NULL,
    cpu integer NOT NULL
)
WITH (fillfactor=100);


COMMENT ON TABLE databasecpustats IS 'Snapshots of CPU utilization per database username.';


COMMENT ON COLUMN databasecpustats.cpu IS '% CPU utilization * 100, as reported by ps -o cp';


CREATE TABLE databasediskutilization (
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    namespace text NOT NULL,
    name text NOT NULL,
    sub_namespace text,
    sub_name text,
    kind character(1) NOT NULL,
    sort text NOT NULL,
    table_len bigint NOT NULL,
    tuple_count bigint NOT NULL,
    tuple_len bigint NOT NULL,
    tuple_percent double precision NOT NULL,
    dead_tuple_count bigint NOT NULL,
    dead_tuple_len bigint NOT NULL,
    dead_tuple_percent double precision NOT NULL,
    free_space bigint NOT NULL,
    free_percent double precision NOT NULL
)
WITH (fillfactor=100);


CREATE TABLE databasereplicationlag (
    node integer NOT NULL,
    lag interval NOT NULL,
    updated timestamp without time zone DEFAULT timezone('UTC'::text, now())
);


COMMENT ON TABLE databasereplicationlag IS 'A cached snapshot of database replication lag between our master Slony node and its slaves.';


COMMENT ON COLUMN databasereplicationlag.node IS 'The Slony node number identifying the slave database.';


COMMENT ON COLUMN databasereplicationlag.lag IS 'lag time.';


COMMENT ON COLUMN databasereplicationlag.updated IS 'When this value was updated.';


CREATE TABLE databasetablestats (
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    schemaname name NOT NULL,
    relname name NOT NULL,
    seq_scan bigint NOT NULL,
    seq_tup_read bigint NOT NULL,
    idx_scan bigint NOT NULL,
    idx_tup_fetch bigint NOT NULL,
    n_tup_ins bigint NOT NULL,
    n_tup_upd bigint NOT NULL,
    n_tup_del bigint NOT NULL,
    n_tup_hot_upd bigint NOT NULL,
    n_live_tup bigint NOT NULL,
    n_dead_tup bigint NOT NULL,
    last_vacuum timestamp with time zone,
    last_autovacuum timestamp with time zone,
    last_analyze timestamp with time zone,
    last_autoanalyze timestamp with time zone
)
WITH (fillfactor=100);


COMMENT ON TABLE databasetablestats IS 'Snapshots of pg_stat_user_tables to let us calculate arbitrary deltas';


CREATE TABLE diff (
    id integer NOT NULL,
    diff_text integer,
    diff_lines_count integer,
    diffstat text,
    added_lines_count integer,
    removed_lines_count integer
);


COMMENT ON TABLE diff IS 'Information common to static or preview diffs';


COMMENT ON COLUMN diff.diff_text IS 'The library copy of the fulltext of the diff';


COMMENT ON COLUMN diff.diff_lines_count IS 'The number of lines in the diff';


COMMENT ON COLUMN diff.diffstat IS 'Statistics about the diff';


COMMENT ON COLUMN diff.added_lines_count IS 'The number of lines added in the diff.';


COMMENT ON COLUMN diff.removed_lines_count IS 'The number of lines removed in the diff';


CREATE SEQUENCE diff_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE diff_id_seq OWNED BY diff.id;


CREATE TABLE distribution (
    id integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    description text NOT NULL,
    domainname text NOT NULL,
    owner integer NOT NULL,
    displayname text NOT NULL,
    summary text NOT NULL,
    members integer NOT NULL,
    translationgroup integer,
    translationpermission integer DEFAULT 1 NOT NULL,
    bug_supervisor integer,
    official_malone boolean DEFAULT false NOT NULL,
    official_rosetta boolean DEFAULT false NOT NULL,
    security_contact integer,
    driver integer,
    translation_focus integer,
    mirror_admin integer NOT NULL,
    upload_admin integer,
    upload_sender text,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    homepage_content text,
    icon integer,
    mugshot integer,
    logo integer,
    fti ts2.tsvector,
    official_answers boolean DEFAULT false NOT NULL,
    language_pack_admin integer,
    official_blueprints boolean DEFAULT false NOT NULL,
    enable_bug_expiration boolean DEFAULT false NOT NULL,
    bug_reporting_guidelines text,
    reviewer_whiteboard text,
    max_bug_heat integer,
    bug_reported_acknowledgement text,
    answers_usage integer DEFAULT 10 NOT NULL,
    blueprints_usage integer DEFAULT 10 NOT NULL,
    translations_usage integer DEFAULT 10 NOT NULL,
    registrant integer NOT NULL,
    package_derivatives_email text,
    CONSTRAINT only_launchpad_has_expiration CHECK (((enable_bug_expiration IS FALSE) OR (official_malone IS TRUE))),
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE distribution IS 'Distribution: A soyuz distribution. A distribution is a collection of DistroSeries. Distributions often group together policy and may be referred to by a name such as "Ubuntu" or "Debian"';


COMMENT ON COLUMN distribution.name IS 'The unique name of the distribution as a short lowercase name suitable for use in a URL.';


COMMENT ON COLUMN distribution.title IS 'The title of the distribution. More a "display name" as it were. E.g. "Ubuntu" or "Debian GNU/Linux"';


COMMENT ON COLUMN distribution.description IS 'A description of the distribution. More detailed than the title, this column may also contain information about the project this distribution is run by.';


COMMENT ON COLUMN distribution.domainname IS 'The domain name of the distribution. This may be used both for linking to the distribution and for context-related stuff.';


COMMENT ON COLUMN distribution.owner IS 'The person in launchpad who is in ultimate-charge of this distribution within launchpad.';


COMMENT ON COLUMN distribution.displayname IS 'A short, well-capitalised
name for this distribution that is not required to be unique but in almost
all cases would be so.';


COMMENT ON COLUMN distribution.summary IS 'A single paragraph that
summarises the highlights of this distribution. It should be no longer than
240 characters, although this is not enforced in the database.';


COMMENT ON COLUMN distribution.members IS 'Person or team with upload and commit priviledges relating to this distribution. Other rights may be assigned to this role in the future.';


COMMENT ON COLUMN distribution.translationgroup IS 'The translation group that is responsible for all translation work in this distribution.';


COMMENT ON COLUMN distribution.translationpermission IS 'The level of openness of this distribution''s translation process. The enum lists different approaches to translation, from the very open (anybody can edit any translation in any language) to the completely closed (only designated translators can make any changes at all).';


COMMENT ON COLUMN distribution.bug_supervisor IS 'Person who is responsible for managing bugs on this distribution.';


COMMENT ON COLUMN distribution.official_malone IS 'Whether or not this distribution uses Malone for an official bug tracker.';


COMMENT ON COLUMN distribution.official_rosetta IS 'Whether or not this distribution uses Rosetta for its official translation team and coordination.';


COMMENT ON COLUMN distribution.security_contact IS 'The person or team who handles security-related issues in the distribution.';


COMMENT ON COLUMN distribution.driver IS 'The team or person responsible for approving goals for each release in the distribution. This should usually be a very small team because the Distribution driver can approve items for backporting to past releases as well as the current release under development. Each distroseries has its own driver too, so you can have the small superset in the Distribution driver, and then specific teams per distroseries for backporting, for example, or for the current release management team on the current development focus release.';


COMMENT ON COLUMN distribution.translation_focus IS 'The DistroSeries that should get the translation effort focus.';


COMMENT ON COLUMN distribution.mirror_admin IS 'Person or team with privileges to mark a mirror as official.';


COMMENT ON COLUMN distribution.upload_admin IS 'Person foreign key which have access to modify the queue ui. If NULL, we fall back to launchpad admin members';


COMMENT ON COLUMN distribution.upload_sender IS 'The email address (and name) of the default sender used by the upload processor. If NULL, we fall back to the default sender in the launchpad config.';


COMMENT ON COLUMN distribution.homepage_content IS 'A home page for this distribution in the Launchpad.';


COMMENT ON COLUMN distribution.icon IS 'The library file alias to a small image to be used as an icon whenever we are referring to a distribution.';


COMMENT ON COLUMN distribution.mugshot IS 'The library file alias of a mugshot image to display as the branding of a distribution, on its home page.';


COMMENT ON COLUMN distribution.logo IS 'The library file alias of a smaller version of this distributions''s mugshot.';


COMMENT ON COLUMN distribution.official_answers IS 'Whether or not this product upstream uses Answers officialy.';


COMMENT ON COLUMN distribution.language_pack_admin IS 'The Person or Team that handle language packs for the distro release.';


COMMENT ON COLUMN distribution.enable_bug_expiration IS 'Indicates whether automatic bug expiration is enabled.';


COMMENT ON COLUMN distribution.bug_reporting_guidelines IS 'Guidelines to the end user for reporting bugs on this distribution.';


COMMENT ON COLUMN distribution.reviewer_whiteboard IS 'A whiteboard for Launchpad admins, registry experts and the project owners to capture the state of current issues with the project.';


COMMENT ON COLUMN distribution.max_bug_heat IS 'The highest heat value across bugs for this distribution.';


COMMENT ON COLUMN distribution.bug_reported_acknowledgement IS 'A message of acknowledgement to display to a bug reporter after they''ve reported a new bug.';


CREATE SEQUENCE distribution_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distribution_id_seq OWNED BY distribution.id;


CREATE TABLE distributionjob (
    id integer NOT NULL,
    job integer NOT NULL,
    distribution integer NOT NULL,
    distroseries integer,
    job_type integer NOT NULL,
    json_data text
);


COMMENT ON TABLE distributionjob IS 'Contains references to jobs to be run on distributions.';


COMMENT ON COLUMN distributionjob.distribution IS 'The distribution to be acted on.';


COMMENT ON COLUMN distributionjob.distroseries IS 'The distroseries to be acted on.';


COMMENT ON COLUMN distributionjob.job_type IS 'The type of job';


COMMENT ON COLUMN distributionjob.json_data IS 'A JSON struct containing data for the job.';


CREATE SEQUENCE distributionjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distributionjob_id_seq OWNED BY distributionjob.id;


CREATE TABLE distributionmirror (
    id integer NOT NULL,
    distribution integer NOT NULL,
    name text NOT NULL,
    http_base_url text,
    ftp_base_url text,
    rsync_base_url text,
    displayname text,
    description text,
    owner integer NOT NULL,
    speed integer NOT NULL,
    country integer NOT NULL,
    content integer NOT NULL,
    official_candidate boolean DEFAULT false NOT NULL,
    enabled boolean DEFAULT false NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    whiteboard text,
    status integer DEFAULT 10 NOT NULL,
    date_reviewed timestamp without time zone,
    reviewer integer,
    country_dns_mirror boolean DEFAULT false NOT NULL,
    CONSTRAINT one_or_more_urls CHECK ((((http_base_url IS NOT NULL) OR (ftp_base_url IS NOT NULL)) OR (rsync_base_url IS NOT NULL))),
    CONSTRAINT valid_ftp_base_url CHECK (valid_absolute_url(ftp_base_url)),
    CONSTRAINT valid_http_base_url CHECK (valid_absolute_url(http_base_url)),
    CONSTRAINT valid_name CHECK (valid_name(name)),
    CONSTRAINT valid_rsync_base_url CHECK (valid_absolute_url(rsync_base_url))
);


COMMENT ON TABLE distributionmirror IS 'A mirror of a given distribution.';


COMMENT ON COLUMN distributionmirror.distribution IS 'The distribution to which the mirror refers to.';


COMMENT ON COLUMN distributionmirror.name IS 'The unique name of the mirror.';


COMMENT ON COLUMN distributionmirror.http_base_url IS 'The HTTP URL used to access the mirror.';


COMMENT ON COLUMN distributionmirror.ftp_base_url IS 'The FTP URL used to access the mirror.';


COMMENT ON COLUMN distributionmirror.rsync_base_url IS 'The Rsync URL used to access the mirror.';


COMMENT ON COLUMN distributionmirror.displayname IS 'The displayname of the mirror.';


COMMENT ON COLUMN distributionmirror.description IS 'A description of the mirror.';


COMMENT ON COLUMN distributionmirror.owner IS 'The owner of the mirror.';


COMMENT ON COLUMN distributionmirror.speed IS 'The speed of the mirror''s Internet link.';


COMMENT ON COLUMN distributionmirror.country IS 'The country where the mirror is located.';


COMMENT ON COLUMN distributionmirror.content IS 'The content that is mirrored.';


COMMENT ON COLUMN distributionmirror.official_candidate IS 'Is the mirror a candidate for becoming an official mirror?';


COMMENT ON COLUMN distributionmirror.enabled IS 'Is this mirror enabled?';


COMMENT ON COLUMN distributionmirror.date_created IS 'The date and time the mirror was created.';


COMMENT ON COLUMN distributionmirror.whiteboard IS 'Notes on the current status of the mirror';


COMMENT ON COLUMN distributionmirror.status IS 'This mirror''s status.';


COMMENT ON COLUMN distributionmirror.date_reviewed IS 'The date and time the mirror was reviewed.';


COMMENT ON COLUMN distributionmirror.reviewer IS 'The person who reviewed the mirror.';


COMMENT ON COLUMN distributionmirror.country_dns_mirror IS 'Is the mirror a country DNS mirror?';


CREATE SEQUENCE distributionmirror_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distributionmirror_id_seq OWNED BY distributionmirror.id;


CREATE TABLE distributionsourcepackage (
    id integer NOT NULL,
    distribution integer NOT NULL,
    sourcepackagename integer NOT NULL,
    bug_reporting_guidelines text,
    max_bug_heat integer,
    bug_reported_acknowledgement text,
    total_bug_heat integer,
    bug_count integer,
    po_message_count integer,
    is_upstream_link_allowed boolean DEFAULT true NOT NULL,
    enable_bugfiling_duplicate_search boolean DEFAULT true NOT NULL
);


COMMENT ON TABLE distributionsourcepackage IS 'Representing a sourcepackage in a distribution across all distribution series.';


COMMENT ON COLUMN distributionsourcepackage.bug_reporting_guidelines IS 'Guidelines to the end user for reporting bugs on a particular a source package in a distribution.';


COMMENT ON COLUMN distributionsourcepackage.max_bug_heat IS 'The highest heat value across bugs for this source package. NULL means it has not yet been calculated.';


COMMENT ON COLUMN distributionsourcepackage.bug_reported_acknowledgement IS 'A message of acknowledgement to display to a bug reporter after they''ve reported a new bug.';


COMMENT ON COLUMN distributionsourcepackage.total_bug_heat IS 'Sum of bug heat matching the package distribution and sourcepackagename. NULL means it has not yet been calculated.';


COMMENT ON COLUMN distributionsourcepackage.bug_count IS 'Number of bugs matching the package distribution and sourcepackagename. NULL means it has not yet been calculated.';


COMMENT ON COLUMN distributionsourcepackage.po_message_count IS 'Number of translations matching the package distribution and sourcepackagename. NULL means it has not yet been calculated.';


COMMENT ON COLUMN distributionsourcepackage.is_upstream_link_allowed IS 'Whether an upstream link may be added if it does not already exist.';


COMMENT ON COLUMN distributionsourcepackage.enable_bugfiling_duplicate_search IS 'Enable/disable a search for posiible duplicates when a bug is filed.';


CREATE SEQUENCE distributionsourcepackage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distributionsourcepackage_id_seq OWNED BY distributionsourcepackage.id;


CREATE TABLE distributionsourcepackagecache (
    id integer NOT NULL,
    distribution integer NOT NULL,
    sourcepackagename integer NOT NULL,
    name text,
    binpkgnames text,
    binpkgsummaries text,
    binpkgdescriptions text,
    fti ts2.tsvector,
    changelog text,
    archive integer NOT NULL
);


COMMENT ON TABLE distributionsourcepackagecache IS 'A cache of the text associated with binary and source packages in the distribution. This table allows for fast queries to find a source packagename that matches a given text.';


COMMENT ON COLUMN distributionsourcepackagecache.distribution IS 'The distribution in which we are checking.';


COMMENT ON COLUMN distributionsourcepackagecache.sourcepackagename IS 'The source package name for which we are caching details.';


COMMENT ON COLUMN distributionsourcepackagecache.name IS 'The source package name itself. This is just a copy of the value of sourcepackagename.name. We have it here so it can be part of the full text index.';


COMMENT ON COLUMN distributionsourcepackagecache.binpkgnames IS 'The binary package names of binary packages generated from these source packages across all architectures.';


COMMENT ON COLUMN distributionsourcepackagecache.binpkgsummaries IS 'The aggregated summaries of all the binary packages generated from these source packages in this distribution.';


COMMENT ON COLUMN distributionsourcepackagecache.binpkgdescriptions IS 'The aggregated description of all the binary packages generated from these source packages in this distribution.';


COMMENT ON COLUMN distributionsourcepackagecache.changelog IS 'A concatenation of the source package release changelogs for this source package, where the status is not REMOVED.';


COMMENT ON COLUMN distributionsourcepackagecache.archive IS 'The archive where the source is published.';


CREATE SEQUENCE distributionsourcepackagecache_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distributionsourcepackagecache_id_seq OWNED BY distributionsourcepackagecache.id;


CREATE SEQUENCE distroarchseries_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distroarchseries_id_seq OWNED BY distroarchseries.id;


CREATE SEQUENCE distroseries_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distroseries_id_seq OWNED BY distroseries.id;


CREATE TABLE distroseriesdifference (
    id integer NOT NULL,
    derived_series integer NOT NULL,
    source_package_name integer NOT NULL,
    package_diff integer,
    status integer NOT NULL,
    difference_type integer NOT NULL,
    parent_package_diff integer,
    source_version debversion,
    parent_source_version debversion,
    base_version debversion,
    parent_series integer NOT NULL,
    CONSTRAINT valid_base_version CHECK (valid_debian_version((base_version)::text)),
    CONSTRAINT valid_parent_source_version CHECK (valid_debian_version((parent_source_version)::text)),
    CONSTRAINT valid_source_version CHECK (valid_debian_version((source_version)::text))
);


COMMENT ON TABLE distroseriesdifference IS 'A difference of versions for a package in a derived distroseries and its parent distroseries.';


COMMENT ON COLUMN distroseriesdifference.derived_series IS 'The derived distroseries with the difference from its parent.';


COMMENT ON COLUMN distroseriesdifference.source_package_name IS 'The name of the source package which is different in the two series.';


COMMENT ON COLUMN distroseriesdifference.package_diff IS 'The most recent package diff that was created for the base version to derived version.';


COMMENT ON COLUMN distroseriesdifference.status IS 'A distroseries difference can be needing attention, ignored or resolved.';


COMMENT ON COLUMN distroseriesdifference.difference_type IS 'The type of difference that this record represents - a package unique to the derived series, or missing, or in both.';


COMMENT ON COLUMN distroseriesdifference.parent_package_diff IS 'The most recent package diff that was created for the base version to the parent version.';


COMMENT ON COLUMN distroseriesdifference.source_version IS 'The version of the package in the derived series.';


COMMENT ON COLUMN distroseriesdifference.parent_source_version IS 'The version of the package in the parent series.';


COMMENT ON COLUMN distroseriesdifference.base_version IS 'The common base version of the package for the derived and parent series.';


CREATE SEQUENCE distroseriesdifference_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distroseriesdifference_id_seq OWNED BY distroseriesdifference.id;


CREATE TABLE distroseriesdifferencemessage (
    id integer NOT NULL,
    distro_series_difference integer NOT NULL,
    message integer NOT NULL
);


COMMENT ON TABLE distroseriesdifferencemessage IS 'A message/comment on a distro series difference.';


COMMENT ON COLUMN distroseriesdifferencemessage.distro_series_difference IS 'The distro series difference for this comment.';


COMMENT ON COLUMN distroseriesdifferencemessage.message IS 'The comment for the distro series difference.';


CREATE SEQUENCE distroseriesdifferencemessage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distroseriesdifferencemessage_id_seq OWNED BY distroseriesdifferencemessage.id;


CREATE TABLE distroserieslanguage (
    id integer NOT NULL,
    distroseries integer,
    language integer,
    currentcount integer NOT NULL,
    updatescount integer NOT NULL,
    rosettacount integer NOT NULL,
    contributorcount integer NOT NULL,
    dateupdated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    unreviewed_count integer DEFAULT 0 NOT NULL
);


COMMENT ON TABLE distroserieslanguage IS 'A cache of the current translation status of that language across an entire distroseries.';


COMMENT ON COLUMN distroserieslanguage.currentcount IS 'As per IRosettaStats.';


COMMENT ON COLUMN distroserieslanguage.updatescount IS 'As per IRosettaStats.';


COMMENT ON COLUMN distroserieslanguage.rosettacount IS 'As per IRosettaStats.';


COMMENT ON COLUMN distroserieslanguage.contributorcount IS 'The total number of contributors to the translation of this distroseries into this language.';


COMMENT ON COLUMN distroserieslanguage.dateupdated IS 'The date these statistucs were last updated.';


COMMENT ON COLUMN distroserieslanguage.unreviewed_count IS 'As per IRosettaStats.';


CREATE SEQUENCE distroserieslanguage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distroserieslanguage_id_seq OWNED BY distroserieslanguage.id;


CREATE TABLE distroseriespackagecache (
    id integer NOT NULL,
    distroseries integer NOT NULL,
    binarypackagename integer NOT NULL,
    name text,
    summary text,
    description text,
    summaries text,
    descriptions text,
    fti ts2.tsvector,
    archive integer NOT NULL
);


COMMENT ON TABLE distroseriespackagecache IS 'A cache of the text associated with binary packages in the distroseries. This table allows for fast queries to find a binary packagename that matches a given text.';


COMMENT ON COLUMN distroseriespackagecache.distroseries IS 'The distroseries in which we are checking.';


COMMENT ON COLUMN distroseriespackagecache.binarypackagename IS 'The binary package name for which we are caching details.';


COMMENT ON COLUMN distroseriespackagecache.name IS 'The binary package name itself. This is just a copy of the value of binarypackagename.name. We have it here so it can be part of the full text index.';


COMMENT ON COLUMN distroseriespackagecache.summary IS 'A single summary for one of the binary packages of this name in this distroseries. We could potentially have binary packages in different architectures with the same name and different summaries, so this is a way of collapsing to one arbitrarily-chosen one, for display purposes. The chances of actually having different summaries and descriptions is pretty small. It could happen, though, because of the way package superseding works when a package does not build on a specific architecture.';


COMMENT ON COLUMN distroseriespackagecache.summaries IS 'The aggregated summaries of all the binary packages with this name in this distroseries.';


COMMENT ON COLUMN distroseriespackagecache.descriptions IS 'The aggregated description of all the binary packages with this name in this distroseries.';


COMMENT ON COLUMN distroseriespackagecache.archive IS 'The archive where the binary is published.';


CREATE SEQUENCE distroseriespackagecache_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distroseriespackagecache_id_seq OWNED BY distroseriespackagecache.id;


CREATE TABLE distroseriesparent (
    id integer NOT NULL,
    derived_series integer NOT NULL,
    parent_series integer NOT NULL,
    initialized boolean NOT NULL,
    is_overlay boolean DEFAULT false NOT NULL,
    component integer,
    pocket integer,
    ordering integer DEFAULT 1 NOT NULL
);


CREATE SEQUENCE distroseriesparent_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE distroseriesparent_id_seq OWNED BY distroseriesparent.id;


CREATE TABLE emailaddress (
    id integer NOT NULL,
    email text NOT NULL,
    person integer,
    status integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    account integer,
    CONSTRAINT emailaddress__is_linked__chk CHECK (((person IS NOT NULL) OR (account IS NOT NULL)))
);


COMMENT ON COLUMN emailaddress.email IS 'An email address used by a Person. The email address is stored in a casesensitive way, but must be case insensitivly unique.';


CREATE SEQUENCE emailaddress_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE emailaddress_id_seq OWNED BY emailaddress.id;


CREATE TABLE entitlement (
    id integer NOT NULL,
    person integer,
    entitlement_type integer NOT NULL,
    quota integer NOT NULL,
    amount_used integer DEFAULT 0 NOT NULL,
    date_starts timestamp without time zone,
    date_expires timestamp without time zone,
    registrant integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    approved_by integer,
    date_approved timestamp without time zone,
    state integer DEFAULT 30 NOT NULL,
    whiteboard text,
    is_dirty boolean DEFAULT true NOT NULL,
    distribution integer,
    product integer,
    project integer,
    CONSTRAINT only_one_target CHECK ((null_count(ARRAY[person, product, project, distribution]) = 3))
);


COMMENT ON TABLE entitlement IS 'Entitlements and usage of privileged features.';


COMMENT ON COLUMN entitlement.person IS 'The person to which the entitlements apply.';


COMMENT ON COLUMN entitlement.entitlement_type IS 'The type of this entitlement (e.g. private bug).';


COMMENT ON COLUMN entitlement.quota IS 'Number of this entitlement allowed.';


COMMENT ON COLUMN entitlement.amount_used IS 'Quantity of this entitlement allocation that is used.';


COMMENT ON COLUMN entitlement.date_starts IS 'When this entitlement becomes active.';


COMMENT ON COLUMN entitlement.date_expires IS 'When this entitlement expires.';


COMMENT ON COLUMN entitlement.registrant IS 'The person (admin) who registered this entitlement.  It is NULL if imported directly from an external sales system.';


COMMENT ON COLUMN entitlement.date_created IS 'Creation date of entitlement.';


COMMENT ON COLUMN entitlement.approved_by IS 'The person who approved this entitlement.  It is NULL if imported directly from an external sales system.';


COMMENT ON COLUMN entitlement.date_approved IS 'Approval date of entitlement.  It is NULL if imported directly from an external sales system.';


COMMENT ON COLUMN entitlement.state IS 'The state (REQUESTED, ACTIVE, INACTIVE) of the entitlement.';


COMMENT ON COLUMN entitlement.whiteboard IS 'A place for administrator notes.';


COMMENT ON COLUMN entitlement.is_dirty IS 'This entitlement has been modified and the state needst to be updated on the external system.';


COMMENT ON COLUMN entitlement.distribution IS 'The distribution to which this entitlement applies.';


COMMENT ON COLUMN entitlement.product IS 'The product to which this entitlement applies.';


COMMENT ON COLUMN entitlement.project IS 'The project to which this entitlement applies.';


CREATE SEQUENCE entitlement_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE entitlement_id_seq OWNED BY entitlement.id;


CREATE VIEW exclusivelocks AS
    SELECT alllocks.procpid, alllocks.usename, alllocks.age, alllocks.relname, alllocks.mode, alllocks.granted, alllocks.current_query FROM alllocks WHERE (alllocks.mode !~~ '%Share%'::text);


CREATE TABLE faq (
    id integer NOT NULL,
    title text NOT NULL,
    tags text,
    content text NOT NULL,
    product integer,
    distribution integer,
    owner integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    last_updated_by integer,
    date_last_updated timestamp without time zone,
    fti ts2.tsvector,
    CONSTRAINT product_or_distro CHECK (((product IS NULL) <> (distribution IS NULL)))
);


COMMENT ON TABLE faq IS 'A technical document containing the answer to a common question.';


COMMENT ON COLUMN faq.id IS 'The FAQ document sequence number.';


COMMENT ON COLUMN faq.title IS 'The document title.';


COMMENT ON COLUMN faq.tags IS 'White-space separated list of tags.';


COMMENT ON COLUMN faq.content IS 'The content of FAQ. It can also contain a short summary and a link.';


COMMENT ON COLUMN faq.product IS 'The product to which this document is
related. Either "product" or "distribution" must be set.';


COMMENT ON COLUMN faq.distribution IS 'The distribution to which this document
is related. Either "product" or "distribution" must be set.';


COMMENT ON COLUMN faq.owner IS 'The person who created the document.';


COMMENT ON COLUMN faq.date_created IS 'The datetime when the document was created.';


COMMENT ON COLUMN faq.last_updated_by IS 'The person who last modified the document.';


COMMENT ON COLUMN faq.date_last_updated IS 'The datetime when the document was last modified.';


CREATE SEQUENCE faq_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE faq_id_seq OWNED BY faq.id;


CREATE TABLE featuredproject (
    id integer NOT NULL,
    pillar_name integer NOT NULL
);


COMMENT ON TABLE featuredproject IS 'A list of featured projects. This table is really just a list of pillarname IDs, if a project''s pillar name is in this list then it is a featured project and will be listed on the Launchpad home page.';


COMMENT ON COLUMN featuredproject.pillar_name IS 'A reference to PillarName.id';


CREATE SEQUENCE featuredproject_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE featuredproject_id_seq OWNED BY featuredproject.id;


CREATE TABLE featureflag (
    scope text NOT NULL,
    priority integer NOT NULL,
    flag text NOT NULL,
    value text NOT NULL,
    date_modified timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL
);


COMMENT ON TABLE featureflag IS 'Configuration that varies by the active scope and that 
can be changed without restarting Launchpad
<https://dev.launchpad.net/LEP/FeatureFlags>';


COMMENT ON COLUMN featureflag.scope IS 'Scope in which this setting is active';


COMMENT ON COLUMN featureflag.priority IS 'Higher priority flags override lower';


COMMENT ON COLUMN featureflag.flag IS 'Name of the flag being controlled';


CREATE TABLE featureflagchangelogentry (
    id integer NOT NULL,
    date_changed timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    diff text NOT NULL,
    comment text NOT NULL,
    person integer NOT NULL
);


CREATE SEQUENCE featureflagchangelogentry_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE featureflagchangelogentry_id_seq OWNED BY featureflagchangelogentry.id;


CREATE TABLE flatpackagesetinclusion (
    id integer NOT NULL,
    parent integer NOT NULL,
    child integer NOT NULL
);


COMMENT ON TABLE flatpackagesetinclusion IS 'In order to facilitate the querying of set-subset relationships an expanded or flattened representation of the set-subset hierarchy is provided by this table.';


COMMENT ON COLUMN flatpackagesetinclusion.parent IS 'The package set that is (directly or indirectly) including a subset.';


COMMENT ON COLUMN flatpackagesetinclusion.child IS 'The package set that is being included as a subset.';


CREATE SEQUENCE flatpackagesetinclusion_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE flatpackagesetinclusion_id_seq OWNED BY flatpackagesetinclusion.id;


CREATE TABLE fticache (
    id integer NOT NULL,
    tablename text NOT NULL,
    columns text NOT NULL
);


CREATE SEQUENCE fticache_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE fticache_id_seq OWNED BY fticache.id;


CREATE TABLE gpgkey (
    id integer NOT NULL,
    owner integer NOT NULL,
    keyid text NOT NULL,
    fingerprint text NOT NULL,
    active boolean NOT NULL,
    algorithm integer NOT NULL,
    keysize integer NOT NULL,
    can_encrypt boolean DEFAULT false NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    CONSTRAINT valid_fingerprint CHECK (valid_fingerprint(fingerprint)),
    CONSTRAINT valid_keyid CHECK (valid_keyid(keyid))
);


COMMENT ON TABLE gpgkey IS 'A GPG key belonging to a Person';


COMMENT ON COLUMN gpgkey.keyid IS 'The 8 character GPG key id, uppercase and no whitespace';


COMMENT ON COLUMN gpgkey.fingerprint IS 'The 40 character GPG fingerprint, uppercase and no whitespace';


COMMENT ON COLUMN gpgkey.active IS 'True if this key is active for use in Launchpad context, false could be deactivated by user or revoked in the global key ring.';


COMMENT ON COLUMN gpgkey.algorithm IS 'The algorithm used to generate this key. Valid values defined in dbschema.GPGKeyAlgorithms';


COMMENT ON COLUMN gpgkey.keysize IS 'Size of the key in bits, as reported by GPG. We may refuse to deal with keysizes < 768 bits in the future.';


COMMENT ON COLUMN gpgkey.can_encrypt IS 'Whether the key has been validated for use in encryption (as opposed to just signing)';


CREATE SEQUENCE gpgkey_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE gpgkey_id_seq OWNED BY gpgkey.id;


CREATE TABLE hwdevice (
    id integer NOT NULL,
    bus_vendor_id integer NOT NULL,
    bus_product_id text NOT NULL,
    variant text,
    name text NOT NULL,
    submissions integer NOT NULL
);


COMMENT ON TABLE hwdevice IS 'Basic information on devices.';


COMMENT ON COLUMN hwdevice.bus_vendor_id IS 'A reference to a HWVendorID record.';


COMMENT ON COLUMN hwdevice.bus_product_id IS 'The bus product ID of a device';


COMMENT ON COLUMN hwdevice.variant IS 'An optional additional description for a device that shares its vendor and product ID with another, technically different, device.';


COMMENT ON COLUMN hwdevice.name IS 'The human readable product name of the device.';


COMMENT ON COLUMN hwdevice.submissions IS 'The number of submissions that contain this device.';


CREATE SEQUENCE hwdevice_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwdevice_id_seq OWNED BY hwdevice.id;


CREATE TABLE hwdeviceclass (
    id integer NOT NULL,
    device integer NOT NULL,
    main_class integer NOT NULL,
    sub_class integer
);


COMMENT ON TABLE hwdeviceclass IS 'Capabilities of a device.';


COMMENT ON COLUMN hwdeviceclass.device IS 'A reference to a device.';


COMMENT ON COLUMN hwdeviceclass.main_class IS 'The main class of a device. Legal values are defined by the HWMainClass enumeration.';


COMMENT ON COLUMN hwdeviceclass.sub_class IS 'The sub-class of a device. Legal values are defined by the HWSubClass enumeration.';


CREATE SEQUENCE hwdeviceclass_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwdeviceclass_id_seq OWNED BY hwdeviceclass.id;


CREATE TABLE hwdevicedriverlink (
    id integer NOT NULL,
    device integer NOT NULL,
    driver integer
);


COMMENT ON TABLE hwdevicedriverlink IS 'Combinations of devices and drivers mentioned in submissions.';


COMMENT ON COLUMN hwdevicedriverlink.device IS 'The device controlled by the driver.';


COMMENT ON COLUMN hwdevicedriverlink.driver IS 'The driver controlling the device.';


CREATE SEQUENCE hwdevicedriverlink_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwdevicedriverlink_id_seq OWNED BY hwdevicedriverlink.id;


CREATE TABLE hwdevicenamevariant (
    id integer NOT NULL,
    vendor_name integer NOT NULL,
    product_name text NOT NULL,
    device integer NOT NULL,
    submissions integer NOT NULL
);


COMMENT ON TABLE hwdevicenamevariant IS 'Alternative vendor and product names of devices.';


COMMENT ON COLUMN hwdevicenamevariant.vendor_name IS 'The alternative vendor name.';


COMMENT ON COLUMN hwdevicenamevariant.product_name IS 'The alternative product name.';


COMMENT ON COLUMN hwdevicenamevariant.device IS 'The device named by this alternative vendor and product names.';


COMMENT ON COLUMN hwdevicenamevariant.submissions IS 'The number of submissions containing this alternative vendor and product name.';


CREATE SEQUENCE hwdevicenamevariant_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwdevicenamevariant_id_seq OWNED BY hwdevicenamevariant.id;


CREATE TABLE hwdmihandle (
    id integer NOT NULL,
    handle integer NOT NULL,
    type integer NOT NULL,
    submission integer
);


COMMENT ON TABLE hwdmihandle IS 'A DMI Handle appearing in the DMI data of a submission.';


COMMENT ON COLUMN hwdmihandle.handle IS 'The ID of the handle.';


COMMENT ON COLUMN hwdmihandle.type IS 'The type of the handle.';


CREATE SEQUENCE hwdmihandle_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwdmihandle_id_seq OWNED BY hwdmihandle.id;


CREATE TABLE hwdmivalue (
    id integer NOT NULL,
    key text,
    value text,
    handle integer NOT NULL
);


COMMENT ON TABLE hwdmivalue IS 'Key/value pairs of DMI data of a handle.';


COMMENT ON COLUMN hwdmivalue.key IS 'The key.';


COMMENT ON COLUMN hwdmivalue.value IS 'The value';


COMMENT ON COLUMN hwdmivalue.handle IS 'The handle to which this key/value pair belongs.';


CREATE SEQUENCE hwdmivalue_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwdmivalue_id_seq OWNED BY hwdmivalue.id;


CREATE TABLE hwdriver (
    id integer NOT NULL,
    package_name text,
    name text NOT NULL,
    license integer
);


COMMENT ON TABLE hwdriver IS 'Information about a driver for a device';


COMMENT ON COLUMN hwdriver.package_name IS 'The Debian package name a driver is a part of';


COMMENT ON COLUMN hwdriver.name IS 'The name of a driver.';


CREATE SEQUENCE hwdriver_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwdriver_id_seq OWNED BY hwdriver.id;


CREATE VIEW hwdrivernames AS
    SELECT DISTINCT ON (hwdriver.name) hwdriver.id, hwdriver.name FROM hwdriver ORDER BY hwdriver.name, hwdriver.id;


COMMENT ON VIEW hwdrivernames IS 'A view returning the distinct driver names stored in HWDriver.';


COMMENT ON COLUMN hwdrivernames.name IS 'The name of a driver.';


CREATE VIEW hwdriverpackagenames AS
    SELECT DISTINCT ON (hwdriver.package_name) hwdriver.id, hwdriver.package_name FROM hwdriver ORDER BY hwdriver.package_name, hwdriver.id;


COMMENT ON VIEW hwdriverpackagenames IS 'A view returning the distinct Debian package names stored in HWDriver.';


COMMENT ON COLUMN hwdriverpackagenames.package_name IS 'The Debian package name a driver is a part of.';


CREATE TABLE hwsubmission (
    id integer NOT NULL,
    date_created timestamp without time zone NOT NULL,
    date_submitted timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    format integer NOT NULL,
    status integer DEFAULT 1 NOT NULL,
    private boolean NOT NULL,
    contactable boolean NOT NULL,
    submission_key text NOT NULL,
    owner integer,
    distroarchseries integer,
    raw_submission integer NOT NULL,
    system_fingerprint integer NOT NULL,
    raw_emailaddress text
);


COMMENT ON TABLE hwsubmission IS 'Raw HWDB submission data';


COMMENT ON COLUMN hwsubmission.date_created IS 'Date and time of the submission (generated by the client).';


COMMENT ON COLUMN hwsubmission.date_submitted IS 'Date and time of the submission (generated by the server).';


COMMENT ON COLUMN hwsubmission.format IS 'The format version of the submitted data, as given by the HWDB client. See HWSubmissionFormat for valid values.';


COMMENT ON COLUMN hwsubmission.status IS 'The status of the submission. See HWSubmissionProcessingStatus for valid values.';


COMMENT ON COLUMN hwsubmission.private IS 'If false, the submitter allows public access to the data. If true, the data may be used only for statistical purposes.';


COMMENT ON COLUMN hwsubmission.contactable IS 'If True, the submitter agrees to be contacted by upstream developers and package maintainers for tests etc.';


COMMENT ON COLUMN hwsubmission.submission_key IS 'A unique submission ID.';


COMMENT ON COLUMN hwsubmission.owner IS 'A reference to the Person table: The owner/submitter of the data.';


COMMENT ON COLUMN hwsubmission.distroarchseries IS 'A reference to the distroarchseries of the submission. This value is null, if the submitted values for distribution, distroseries and architecture do not match an existing entry in the Distroarchseries table.';


COMMENT ON COLUMN hwsubmission.raw_submission IS 'A reference to a row of LibraryFileAlias. The library file contains the raw submission data.';


COMMENT ON COLUMN hwsubmission.system_fingerprint IS 'A reference to an entry of the HWDBSystemFingerPrint table. This table stores the system name as returned by HAL (system.vendor, system.product)';


COMMENT ON COLUMN hwsubmission.raw_emailaddress IS 'The email address of the submitter.';


CREATE SEQUENCE hwsubmission_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwsubmission_id_seq OWNED BY hwsubmission.id;


CREATE TABLE hwsubmissionbug (
    id integer NOT NULL,
    submission integer NOT NULL,
    bug integer NOT NULL
);


COMMENT ON TABLE hwsubmissionbug IS 'Link bugs to HWDB submissions';


CREATE SEQUENCE hwsubmissionbug_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwsubmissionbug_id_seq OWNED BY hwsubmissionbug.id;


CREATE TABLE hwsubmissiondevice (
    id integer NOT NULL,
    device_driver_link integer NOT NULL,
    submission integer NOT NULL,
    parent integer,
    hal_device_id integer NOT NULL
);


COMMENT ON TABLE hwsubmissiondevice IS 'Links between devices and submissions.';


COMMENT ON COLUMN hwsubmissiondevice.device_driver_link IS 'The combination (device, driver) mentioned in a submission.';


COMMENT ON COLUMN hwsubmissiondevice.submission IS 'The submission mentioning this (device, driver) combination.';


COMMENT ON COLUMN hwsubmissiondevice.parent IS 'The parent device of this device.';


COMMENT ON COLUMN hwsubmissiondevice.hal_device_id IS 'The ID of the HAL node of this device in the submitted data.';


CREATE SEQUENCE hwsubmissiondevice_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwsubmissiondevice_id_seq OWNED BY hwsubmissiondevice.id;


CREATE TABLE hwsystemfingerprint (
    id integer NOT NULL,
    fingerprint text NOT NULL
);


COMMENT ON TABLE hwsystemfingerprint IS 'A distinct list of "fingerprints" (HAL system.name, system.vendor) from raw submission data';


COMMENT ON COLUMN hwsystemfingerprint.fingerprint IS 'The fingerprint';


CREATE SEQUENCE hwsystemfingerprint_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwsystemfingerprint_id_seq OWNED BY hwsystemfingerprint.id;


CREATE TABLE hwtest (
    id integer NOT NULL,
    namespace text,
    name text NOT NULL,
    version text NOT NULL
);


COMMENT ON TABLE hwtest IS 'General information about a device test.';


COMMENT ON COLUMN hwtest.namespace IS 'The namespace of a test.';


COMMENT ON COLUMN hwtest.name IS 'The name of a test.';


CREATE SEQUENCE hwtest_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwtest_id_seq OWNED BY hwtest.id;


CREATE TABLE hwtestanswer (
    id integer NOT NULL,
    test integer NOT NULL,
    choice integer,
    intval integer,
    floatval double precision,
    unit text,
    comment text,
    language integer,
    submission integer NOT NULL,
    CONSTRAINT hwtestanswer_check CHECK (((((choice IS NULL) AND (unit IS NOT NULL)) AND ((intval IS NULL) <> (floatval IS NULL))) OR ((((choice IS NOT NULL) AND (unit IS NULL)) AND (intval IS NULL)) AND (floatval IS NULL))))
);


COMMENT ON TABLE hwtestanswer IS 'The answer for a test from a submission. This can be either a multiple choice selection or a numerical value. Exactly one of the columns choice, intval, floatval must be non-null.';


COMMENT ON COLUMN hwtestanswer.test IS 'The test answered by this answer.';


COMMENT ON COLUMN hwtestanswer.choice IS 'The selected value of a multiple choice test.';


COMMENT ON COLUMN hwtestanswer.intval IS 'The integer result of a test with a numerical result.';


COMMENT ON COLUMN hwtestanswer.floatval IS 'The double precision floating point number result of a test with a numerical result.';


COMMENT ON COLUMN hwtestanswer.unit IS 'The physical unit of a test with a numerical result.';


CREATE SEQUENCE hwtestanswer_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwtestanswer_id_seq OWNED BY hwtestanswer.id;


CREATE TABLE hwtestanswerchoice (
    id integer NOT NULL,
    choice text NOT NULL,
    test integer NOT NULL
);


COMMENT ON TABLE hwtestanswerchoice IS 'Choice values of multiple choice tests/questions.';


COMMENT ON COLUMN hwtestanswerchoice.choice IS 'The choice value.';


COMMENT ON COLUMN hwtestanswerchoice.test IS 'The test this choice belongs to.';


CREATE SEQUENCE hwtestanswerchoice_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwtestanswerchoice_id_seq OWNED BY hwtestanswerchoice.id;


CREATE TABLE hwtestanswercount (
    id integer NOT NULL,
    test integer NOT NULL,
    distroarchseries integer,
    choice integer,
    average double precision,
    sum_square double precision,
    unit text,
    num_answers integer NOT NULL,
    CONSTRAINT hwtestanswercount_check CHECK ((((((choice IS NULL) AND (average IS NOT NULL)) AND (sum_square IS NOT NULL)) AND (unit IS NOT NULL)) OR ((((choice IS NOT NULL) AND (average IS NULL)) AND (sum_square IS NULL)) AND (unit IS NULL))))
);


COMMENT ON TABLE hwtestanswercount IS 'Accumulated results of tests. Either the column choice or the columns average and sum_square must be non-null.';


COMMENT ON COLUMN hwtestanswercount.test IS 'The test.';


COMMENT ON COLUMN hwtestanswercount.distroarchseries IS 'The distroarchseries for which results are accumulated,';


COMMENT ON COLUMN hwtestanswercount.choice IS 'The choice value of a multiple choice test.';


COMMENT ON COLUMN hwtestanswercount.average IS 'The average value of the result of a numerical test.';


COMMENT ON COLUMN hwtestanswercount.sum_square IS 'The sum of the squares of the results of a numerical test.';


COMMENT ON COLUMN hwtestanswercount.unit IS 'The physical unit of a numerical test result.';


COMMENT ON COLUMN hwtestanswercount.num_answers IS 'The number of submissions from which the result is accumulated.';


CREATE SEQUENCE hwtestanswercount_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwtestanswercount_id_seq OWNED BY hwtestanswercount.id;


CREATE TABLE hwtestanswercountdevice (
    id integer NOT NULL,
    answer integer NOT NULL,
    device_driver integer NOT NULL
);


COMMENT ON TABLE hwtestanswercountdevice IS 'Association of accumulated test results and device/driver combinations.';


COMMENT ON COLUMN hwtestanswercountdevice.answer IS 'The test answer.';


COMMENT ON COLUMN hwtestanswercountdevice.device_driver IS 'The device/driver combination.';


CREATE SEQUENCE hwtestanswercountdevice_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwtestanswercountdevice_id_seq OWNED BY hwtestanswercountdevice.id;


CREATE TABLE hwtestanswerdevice (
    id integer NOT NULL,
    answer integer NOT NULL,
    device_driver integer NOT NULL
);


COMMENT ON TABLE hwtestanswerdevice IS 'Association of test results and device/driver combinations.';


COMMENT ON COLUMN hwtestanswerdevice.answer IS 'The test answer.';


COMMENT ON COLUMN hwtestanswerdevice.device_driver IS 'The device/driver combination.';


CREATE SEQUENCE hwtestanswerdevice_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwtestanswerdevice_id_seq OWNED BY hwtestanswerdevice.id;


CREATE TABLE hwvendorid (
    id integer NOT NULL,
    bus integer NOT NULL,
    vendor_id_for_bus text NOT NULL,
    vendor_name integer NOT NULL
);


COMMENT ON TABLE hwvendorid IS 'Associates tuples (bus, vendor ID for this bus) with vendor names.';


COMMENT ON COLUMN hwvendorid.bus IS 'The bus.';


COMMENT ON COLUMN hwvendorid.vendor_id_for_bus IS 'The ID of a vendor for the bus given by column `bus`';


CREATE SEQUENCE hwvendorid_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwvendorid_id_seq OWNED BY hwvendorid.id;


CREATE TABLE hwvendorname (
    id integer NOT NULL,
    name text NOT NULL
);


COMMENT ON TABLE hwvendorname IS 'A list of hardware vendor names.';


COMMENT ON COLUMN hwvendorname.name IS 'The name of a vendor.';


CREATE SEQUENCE hwvendorname_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE hwvendorname_id_seq OWNED BY hwvendorname.id;


CREATE TABLE incrementaldiff (
    id integer NOT NULL,
    diff integer NOT NULL,
    branch_merge_proposal integer NOT NULL,
    old_revision integer NOT NULL,
    new_revision integer NOT NULL
);


COMMENT ON TABLE incrementaldiff IS 'Incremental diffs for merge proposals.';


COMMENT ON COLUMN incrementaldiff.diff IS 'The contents of the diff.';


COMMENT ON COLUMN incrementaldiff.branch_merge_proposal IS 'The merge proposal the diff is for.';


COMMENT ON COLUMN incrementaldiff.old_revision IS 'The revision the diff is from.';


COMMENT ON COLUMN incrementaldiff.new_revision IS 'The revision the diff is to.';


CREATE SEQUENCE incrementaldiff_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE incrementaldiff_id_seq OWNED BY incrementaldiff.id;


CREATE TABLE ircid (
    id integer NOT NULL,
    person integer NOT NULL,
    network text NOT NULL,
    nickname text NOT NULL
);


CREATE SEQUENCE ircid_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE ircid_id_seq OWNED BY ircid.id;


CREATE TABLE jabberid (
    id integer NOT NULL,
    person integer NOT NULL,
    jabberid text NOT NULL
);


CREATE SEQUENCE jabberid_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE jabberid_id_seq OWNED BY jabberid.id;


CREATE TABLE job (
    id integer NOT NULL,
    requester integer,
    reason text,
    status integer NOT NULL,
    progress integer,
    last_report_seen timestamp without time zone,
    next_report_due timestamp without time zone,
    attempt_count integer DEFAULT 0 NOT NULL,
    max_retries integer DEFAULT 0 NOT NULL,
    log text,
    scheduled_start timestamp without time zone,
    lease_expires timestamp without time zone,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_started timestamp without time zone,
    date_finished timestamp without time zone
);


COMMENT ON TABLE job IS 'Common info about a job.';


COMMENT ON COLUMN job.requester IS 'Ther person who requested this job (if applicable).';


COMMENT ON COLUMN job.reason IS 'The reason that this job was created (if applicable)';


COMMENT ON COLUMN job.status IS 'An enum (JobStatus) indicating the job status, one of: new, in-progress, complete, failed, cancelling, cancelled.';


COMMENT ON COLUMN job.progress IS 'The percentage complete.  Can be NULL for some jobs that do not report progress.';


COMMENT ON COLUMN job.last_report_seen IS 'The last time the progress was reported.';


COMMENT ON COLUMN job.next_report_due IS 'The next time a progress report is expected.';


COMMENT ON COLUMN job.attempt_count IS 'The number of times this job has been attempted.';


COMMENT ON COLUMN job.max_retries IS 'The maximum number of retries valid for this job.';


COMMENT ON COLUMN job.log IS 'If provided, this is the tail of the log file being generated by the running job.';


COMMENT ON COLUMN job.scheduled_start IS 'The time when the job should start';


COMMENT ON COLUMN job.lease_expires IS 'The time when the lease expires.';


COMMENT ON COLUMN job.date_created IS 'The time when the job was created.';


COMMENT ON COLUMN job.date_started IS 'If the job has started, the time when the job started.';


COMMENT ON COLUMN job.date_finished IS 'If the job has finished, the time when the job finished.';


CREATE SEQUENCE job_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE job_id_seq OWNED BY job.id;


CREATE TABLE karma (
    id integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    person integer NOT NULL,
    action integer NOT NULL,
    product integer,
    distribution integer,
    sourcepackagename integer
)
WITH (fillfactor=100);


COMMENT ON TABLE karma IS 'Used to quantify all the ''operations'' a user performs inside the system, which maybe reporting and fixing bugs, uploading packages, end-user support, wiki editting, etc.';


COMMENT ON COLUMN karma.datecreated IS 'A timestamp for the assignment of this Karma.';


COMMENT ON COLUMN karma.person IS 'The Person for wich this Karma was assigned.';


COMMENT ON COLUMN karma.action IS 'A foreign key to the KarmaAction table.';


COMMENT ON COLUMN karma.product IS 'The Project to which this Product belongs.  An entry on this table with a non-NULL Project and a NULL Product represents the total karma of the person across all products of that project..';


COMMENT ON COLUMN karma.distribution IS 'The Distribution on which a person performed an action that resulted on this karma.';


COMMENT ON COLUMN karma.sourcepackagename IS 'The SourcePackageName on which a person performed an action that resulted on this karma.';


CREATE SEQUENCE karma_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE karma_id_seq OWNED BY karma.id;


CREATE TABLE karmaaction (
    id integer NOT NULL,
    category integer,
    points integer,
    name text NOT NULL,
    title text NOT NULL,
    summary text NOT NULL
);


COMMENT ON TABLE karmaaction IS 'Stores all the actions that would give karma to the user which performed it.';


COMMENT ON COLUMN karmaaction.category IS 'A dbschema value used to group actions together.';


COMMENT ON COLUMN karmaaction.points IS 'The number of points this action is worth of.';


COMMENT ON COLUMN karmaaction.name IS 'The unique name of this action.';


CREATE SEQUENCE karmaaction_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE karmaaction_id_seq OWNED BY karmaaction.id;


CREATE TABLE karmacache (
    id integer NOT NULL,
    person integer NOT NULL,
    category integer,
    karmavalue integer NOT NULL,
    product integer,
    distribution integer,
    sourcepackagename integer,
    project integer,
    CONSTRAINT just_distribution CHECK (((distribution IS NULL) OR ((product IS NULL) AND (project IS NULL)))),
    CONSTRAINT just_product CHECK (((product IS NULL) OR ((project IS NULL) AND (distribution IS NULL)))),
    CONSTRAINT just_project CHECK (((project IS NULL) OR ((product IS NULL) AND (distribution IS NULL)))),
    CONSTRAINT sourcepackagename_requires_distribution CHECK (((sourcepackagename IS NULL) OR (distribution IS NOT NULL)))
);


COMMENT ON TABLE karmacache IS 'Stores a cached value of a person''s karma points, grouped by the action category and the context where that action was performed.';


COMMENT ON COLUMN karmacache.person IS 'The person which performed the actions of this category, and thus got the karma.';


COMMENT ON COLUMN karmacache.category IS 'The category of the actions.';


COMMENT ON COLUMN karmacache.karmavalue IS 'The karma points of all actions of this category performed by this person on this context (product/distribution).';


CREATE SEQUENCE karmacache_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE karmacache_id_seq OWNED BY karmacache.id;


CREATE TABLE karmacategory (
    id integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    summary text NOT NULL
);


COMMENT ON TABLE karmacategory IS 'A category of karma. This allows us to
present an overall picture of the different areas where a user has been
active.';


CREATE SEQUENCE karmacategory_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE karmacategory_id_seq OWNED BY karmacategory.id;


CREATE TABLE karmatotalcache (
    id integer NOT NULL,
    person integer NOT NULL,
    karma_total integer NOT NULL
);


CREATE SEQUENCE karmatotalcache_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE karmatotalcache_id_seq OWNED BY karmatotalcache.id;


CREATE TABLE language (
    id integer NOT NULL,
    code text NOT NULL,
    englishname text NOT NULL,
    nativename text,
    pluralforms integer,
    pluralexpression text,
    visible boolean NOT NULL,
    direction integer DEFAULT 0 NOT NULL,
    uuid text,
    CONSTRAINT valid_language CHECK (((pluralforms IS NULL) = (pluralexpression IS NULL)))
);


COMMENT ON TABLE language IS 'A human language.';


COMMENT ON COLUMN language.code IS 'The ISO 639 code for this language';


COMMENT ON COLUMN language.englishname IS 'The english name for this language';


COMMENT ON COLUMN language.nativename IS 'The name of this language in the language itself';


COMMENT ON COLUMN language.pluralforms IS 'The number of plural forms this language has';


COMMENT ON COLUMN language.pluralexpression IS 'The plural expression for this language, as used by gettext';


COMMENT ON COLUMN language.visible IS 'Whether this language should usually be visible or not';


COMMENT ON COLUMN language.direction IS 'The direction that text is written in this language';


COMMENT ON COLUMN language.uuid IS 'Mozilla language pack unique ID';


CREATE SEQUENCE language_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE language_id_seq OWNED BY language.id;


CREATE TABLE languagepack (
    id integer NOT NULL,
    file integer NOT NULL,
    date_exported timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_last_used timestamp without time zone DEFAULT timezone('UTC'::text, now()),
    distroseries integer NOT NULL,
    type integer DEFAULT 1 NOT NULL,
    updates integer,
    CONSTRAINT valid_updates CHECK ((((type = 2) AND (updates IS NOT NULL)) OR ((type = 1) AND (updates IS NULL))))
);


COMMENT ON TABLE languagepack IS 'Store exported language packs for DistroSeries.';


COMMENT ON COLUMN languagepack.file IS 'Librarian file where the language pack is stored.';


COMMENT ON COLUMN languagepack.date_exported IS 'When was exported the language pack.';


COMMENT ON COLUMN languagepack.date_last_used IS 'When did we stop using the language pack. It''s used to decide whether we can remove it completely from the system. When it''s being used, its value is NULL';


COMMENT ON COLUMN languagepack.distroseries IS 'The distribution series from where this language pack was exported.';


COMMENT ON COLUMN languagepack.type IS 'Type of language pack. There are two types available, 1: Full export, 2: Update export based on language_pack_that_updates export.';


COMMENT ON COLUMN languagepack.updates IS 'The LanguagePack that this one updates.';


CREATE SEQUENCE languagepack_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE languagepack_id_seq OWNED BY languagepack.id;


CREATE VIEW latestdatabasediskutilization AS
    SELECT databasediskutilization.date_created, databasediskutilization.namespace, databasediskutilization.name, databasediskutilization.sub_namespace, databasediskutilization.sub_name, databasediskutilization.kind, databasediskutilization.sort, databasediskutilization.table_len, databasediskutilization.tuple_count, databasediskutilization.tuple_len, databasediskutilization.tuple_percent, databasediskutilization.dead_tuple_count, databasediskutilization.dead_tuple_len, databasediskutilization.dead_tuple_percent, databasediskutilization.free_space, databasediskutilization.free_percent FROM databasediskutilization WHERE (databasediskutilization.date_created = (SELECT max(databasediskutilization.date_created) AS max FROM databasediskutilization));


CREATE TABLE launchpaddatabaserevision (
    major integer NOT NULL,
    minor integer NOT NULL,
    patch integer NOT NULL,
    start_time timestamp without time zone DEFAULT timezone('UTC'::text, transaction_timestamp()),
    end_time timestamp without time zone DEFAULT timezone('UTC'::text, statement_timestamp()),
    branch_nick text,
    revno integer,
    revid text
);


COMMENT ON TABLE launchpaddatabaserevision IS 'This table contains a list of the database patches that have been successfully applied to this database.';


COMMENT ON COLUMN launchpaddatabaserevision.major IS 'Major number. This is the version of the baseline schema the patch was made agains.';


COMMENT ON COLUMN launchpaddatabaserevision.minor IS 'Minor number. Patches made during development each increment the minor number.';


COMMENT ON COLUMN launchpaddatabaserevision.patch IS 'The patch number will hopefully always be ''0'', as it exists to support emergency patches made to the production server. eg. If production is running ''4.0.0'' and needs to have a patch applied ASAP, we would create a ''4.0.1'' patch and roll it out. We then may need to refactor all the existing ''4.x.0'' patches.';


CREATE TABLE launchpaddatabaseupdatelog (
    id integer NOT NULL,
    start_time timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    end_time timestamp without time zone,
    branch_nick text,
    revno integer,
    revid text
);


CREATE SEQUENCE launchpaddatabaseupdatelog_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE launchpaddatabaseupdatelog_id_seq OWNED BY launchpaddatabaseupdatelog.id;


CREATE TABLE launchpadstatistic (
    id integer NOT NULL,
    name text NOT NULL,
    value integer NOT NULL,
    dateupdated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL
);


COMMENT ON TABLE launchpadstatistic IS 'A store of system-wide statistics or other integer values, keyed by names. The names are unique and the values can be any integer. Each field has a place to store the timestamp when it was last updated, so it is possible to know how far out of date any given statistic is.';


CREATE SEQUENCE launchpadstatistic_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE launchpadstatistic_id_seq OWNED BY launchpadstatistic.id;


CREATE SEQUENCE libraryfilealias_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE libraryfilealias_id_seq OWNED BY libraryfilealias.id;


CREATE TABLE libraryfilecontent (
    id integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    filesize bigint NOT NULL,
    sha1 character(40) NOT NULL,
    md5 character(32) NOT NULL,
    sha256 character(64)
)
WITH (fillfactor=100);


COMMENT ON TABLE libraryfilecontent IS 'LibraryFileContent: A librarian file''s contents. The librarian stores files in a safe and transactional way. This table represents the contents of those files within the database.';


COMMENT ON COLUMN libraryfilecontent.datecreated IS 'The date on which this librarian file was created';


COMMENT ON COLUMN libraryfilecontent.filesize IS 'The size of the file';


COMMENT ON COLUMN libraryfilecontent.sha1 IS 'The SHA1 sum of the file''s contents';


COMMENT ON COLUMN libraryfilecontent.md5 IS 'The MD5 sum of the file''s contents';


COMMENT ON COLUMN libraryfilecontent.sha256 IS 'The SHA256 sum of the file''s contents';


CREATE SEQUENCE libraryfilecontent_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE libraryfilecontent_id_seq OWNED BY libraryfilecontent.id;


CREATE TABLE libraryfiledownloadcount (
    id integer NOT NULL,
    libraryfilealias integer NOT NULL,
    day date NOT NULL,
    count integer NOT NULL,
    country integer
);


COMMENT ON TABLE libraryfiledownloadcount IS 'The number of daily downloads for a given LibraryFileAlias.';


COMMENT ON COLUMN libraryfiledownloadcount.libraryfilealias IS 'The LibraryFileAlias.';


COMMENT ON COLUMN libraryfiledownloadcount.day IS 'The day of the downloads.';


COMMENT ON COLUMN libraryfiledownloadcount.count IS 'The number of downloads.';


COMMENT ON COLUMN libraryfiledownloadcount.country IS 'The country from where the download requests came from.';


CREATE SEQUENCE libraryfiledownloadcount_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE libraryfiledownloadcount_id_seq OWNED BY libraryfiledownloadcount.id;


CREATE TABLE logintoken (
    id integer NOT NULL,
    requester integer,
    requesteremail text,
    email text NOT NULL,
    created timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    tokentype integer NOT NULL,
    token text,
    fingerprint text,
    redirection_url text,
    date_consumed timestamp without time zone,
    CONSTRAINT valid_fingerprint CHECK (((fingerprint IS NULL) OR valid_fingerprint(fingerprint)))
);


COMMENT ON TABLE logintoken IS 'LoginToken stores one time tokens used by Launchpad for validating email addresses and other tasks that require verifying an email address is valid such as password recovery and account merging. This table will be cleaned occasionally to remove expired tokens. Expiry time is not yet defined.';


COMMENT ON COLUMN logintoken.requester IS 'The Person that made this request. This will be null for password recovery requests.';


COMMENT ON COLUMN logintoken.requesteremail IS 'The email address that was used to login when making this request. This provides an audit trail to help the end user confirm that this is a valid request. It is not a link to the EmailAddress table as this may be changed after the request is made. This field will be null for password recovery requests.';


COMMENT ON COLUMN logintoken.email IS 'The email address that this request was sent to.';


COMMENT ON COLUMN logintoken.created IS 'The timestamp that this request was made.';


COMMENT ON COLUMN logintoken.tokentype IS 'The type of request, as per dbschema.TokenType.';


COMMENT ON COLUMN logintoken.token IS 'The token (not the URL) emailed used to uniquely identify this request. This token will be used to generate a URL that when clicked on will continue a workflow.';


COMMENT ON COLUMN logintoken.fingerprint IS 'The GPG key fingerprint to be validated on this transaction, it means that a new register will be created relating this given key with the requester in question. The requesteremail still passing for the same usual checks.';


COMMENT ON COLUMN logintoken.date_consumed IS 'The date and time when this token was consumed. It''s NULL if it hasn''t been consumed yet.';


CREATE SEQUENCE logintoken_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE logintoken_id_seq OWNED BY logintoken.id;


CREATE TABLE lp_account (
    id integer NOT NULL,
    openid_identifier text NOT NULL
);


CREATE TABLE lp_openididentifier (
    identifier text NOT NULL,
    account integer NOT NULL,
    date_created timestamp without time zone NOT NULL
);


CREATE TABLE lp_person (
    id integer NOT NULL,
    displayname text,
    teamowner integer,
    teamdescription text,
    name text,
    language integer,
    fti ts2.tsvector,
    defaultmembershipperiod integer,
    defaultrenewalperiod integer,
    subscriptionpolicy integer,
    merged integer,
    datecreated timestamp without time zone,
    addressline1 text,
    addressline2 text,
    organization text,
    city text,
    province text,
    country integer,
    postcode text,
    phone text,
    homepage_content text,
    icon integer,
    mugshot integer,
    hide_email_addresses boolean,
    creation_rationale integer,
    creation_comment text,
    registrant integer,
    logo integer,
    renewal_policy integer,
    personal_standing integer,
    personal_standing_reason text,
    mail_resumption_date date,
    mailing_list_auto_subscribe_policy integer,
    mailing_list_receive_duplicates boolean,
    visibility integer,
    verbose_bugnotifications boolean,
    account integer
);


CREATE TABLE lp_personlocation (
    id integer NOT NULL,
    date_created timestamp without time zone,
    person integer,
    latitude double precision,
    longitude double precision,
    time_zone text,
    last_modified_by integer,
    date_last_modified timestamp without time zone,
    visible boolean,
    locked boolean
);


CREATE TABLE lp_teamparticipation (
    id integer NOT NULL,
    team integer,
    person integer
);


CREATE TABLE mailinglist (
    id integer NOT NULL,
    team integer NOT NULL,
    registrant integer NOT NULL,
    date_registered timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    reviewer integer,
    date_reviewed timestamp without time zone DEFAULT timezone('UTC'::text, now()),
    date_activated timestamp without time zone DEFAULT timezone('UTC'::text, now()),
    status integer DEFAULT 1 NOT NULL,
    welcome_message text
);


COMMENT ON TABLE mailinglist IS 'The mailing list for a team.  Teams may have zero or one mailing list, and a mailing list is associated with exactly one team.  This table manages the state changes that a team mailing list can go through, and it contains information that will be used to instruct Mailman how to create, delete, and modify mailing lists (via XMLRPC).';


COMMENT ON COLUMN mailinglist.team IS 'The team this mailing list is associated with.';


COMMENT ON COLUMN mailinglist.registrant IS 'The id of the Person who requested this list be created.';


COMMENT ON COLUMN mailinglist.date_registered IS 'Date the list was requested to be created';


COMMENT ON COLUMN mailinglist.reviewer IS 'The id of the Person who reviewed the creation request, or NULL if not yet reviewed.';


COMMENT ON COLUMN mailinglist.date_reviewed IS 'The date the request was reviewed, or NULL if not yet reviewed.';


COMMENT ON COLUMN mailinglist.date_activated IS 'The date the list was (last) activated.  If the list is not yet active, this field will be NULL.';


COMMENT ON COLUMN mailinglist.status IS 'The current status of the mailing list, as a dbschema.MailingListStatus value.';


COMMENT ON COLUMN mailinglist.welcome_message IS 'Text sent to new members when they are subscribed to the team list.  If NULL, no welcome message is sent.';


CREATE SEQUENCE mailinglist_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE mailinglist_id_seq OWNED BY mailinglist.id;


CREATE TABLE mailinglistsubscription (
    id integer NOT NULL,
    person integer NOT NULL,
    mailing_list integer NOT NULL,
    date_joined timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    email_address integer
);


COMMENT ON TABLE mailinglistsubscription IS 'Track the subscriptions of a person to team mailing lists.';


COMMENT ON COLUMN mailinglistsubscription.person IS 'The person who is subscribed to the mailing list.';


COMMENT ON COLUMN mailinglistsubscription.mailing_list IS 'The mailing list this person is subscribed to.';


COMMENT ON COLUMN mailinglistsubscription.date_joined IS 'The date this person subscribed to the mailing list.';


COMMENT ON COLUMN mailinglistsubscription.email_address IS 'Which of the person''s email addresses are subscribed to the mailing list.  This may be NULL to indicate that it''s the person''s preferred address.';


CREATE SEQUENCE mailinglistsubscription_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE mailinglistsubscription_id_seq OWNED BY mailinglistsubscription.id;


CREATE TABLE mergedirectivejob (
    id integer NOT NULL,
    job integer NOT NULL,
    merge_directive integer NOT NULL,
    action integer NOT NULL
);


COMMENT ON TABLE mergedirectivejob IS 'A job to process a merge directive.';


COMMENT ON COLUMN mergedirectivejob.job IS 'The job associated with this MergeDirectiveJob.';


COMMENT ON COLUMN mergedirectivejob.merge_directive IS 'Full MIME content of the message containing the merge directive.';


COMMENT ON COLUMN mergedirectivejob.action IS 'Enumeration of the action to perform with the merge directive; push or create merge proposal.';


CREATE SEQUENCE mergedirectivejob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE mergedirectivejob_id_seq OWNED BY mergedirectivejob.id;


CREATE TABLE message (
    id integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    subject text,
    owner integer,
    parent integer,
    distribution integer,
    rfc822msgid text NOT NULL,
    fti ts2.tsvector,
    raw integer,
    visible boolean DEFAULT true NOT NULL
)
WITH (fillfactor=100);


COMMENT ON TABLE message IS 'This table stores a single RFC822-style message. Messages can be threaded (using the parent field). These messages can then be referenced from elsewhere in the system, such as the BugMessage table, integrating messageboard facilities with the rest of The Launchpad.';


COMMENT ON COLUMN message.subject IS 'The title text of the message, or the subject if it was an email.';


COMMENT ON COLUMN message.parent IS 'A "parent message". This allows for some level of threading in Messages.';


COMMENT ON COLUMN message.distribution IS 'The distribution in which this message originated, if we know it.';


COMMENT ON COLUMN message.raw IS 'The original unadulterated message if it arrived via email. This is required to provide access to the original, undecoded message.';


CREATE SEQUENCE message_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE message_id_seq OWNED BY message.id;


CREATE TABLE messageapproval (
    id integer NOT NULL,
    posted_by integer NOT NULL,
    mailing_list integer NOT NULL,
    posted_message integer NOT NULL,
    posted_date timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    status integer DEFAULT 0 NOT NULL,
    disposed_by integer,
    disposal_date timestamp without time zone DEFAULT timezone('UTC'::text, now()),
    reason text,
    message integer NOT NULL
);


COMMENT ON TABLE messageapproval IS 'Track mailing list postings awaiting approval from the team owner.';


COMMENT ON COLUMN messageapproval.posted_by IS 'The person who posted the message.';


COMMENT ON COLUMN messageapproval.mailing_list IS 'The mailing list to which the message was posted.';


COMMENT ON COLUMN messageapproval.posted_message IS 'Foreign key to libraryfilealias table pointing to where the posted message''s text lives.';


COMMENT ON COLUMN messageapproval.posted_date IS 'The date the message was posted.';


COMMENT ON COLUMN messageapproval.status IS 'The status of the posted message.  Values are described in dbschema.PostedMessageStatus.';


COMMENT ON COLUMN messageapproval.disposed_by IS 'The person who disposed of (i.e. approved or rejected) the message, or NULL if no disposition has yet been made.';


COMMENT ON COLUMN messageapproval.disposal_date IS 'The date on which this message was disposed, or NULL if no disposition has yet been made.';


COMMENT ON COLUMN messageapproval.reason IS 'The reason for the current status if any. This information will be displayed to the end user and mailing list moderators need to be aware of this - not a private whiteboard.';


COMMENT ON COLUMN messageapproval.message IS 'Foreign key to message table pointing to the posted message.';


CREATE SEQUENCE messageapproval_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE messageapproval_id_seq OWNED BY messageapproval.id;


CREATE TABLE messagechunk (
    id integer NOT NULL,
    message integer NOT NULL,
    sequence integer NOT NULL,
    content text,
    blob integer,
    fti ts2.tsvector,
    CONSTRAINT text_or_content CHECK ((((blob IS NULL) AND (content IS NULL)) OR ((blob IS NULL) <> (content IS NULL))))
)
WITH (fillfactor=100);


COMMENT ON TABLE messagechunk IS 'This table stores a single chunk of a possibly multipart message. There will be at least one row in this table for each message. text/* parts are stored in the content column. All other parts are stored in the Librarian and referenced via the blob column. If both content and blob are NULL, then this chunk has been removed (eg. offensive, legal reasons, virus etc.)';


COMMENT ON COLUMN messagechunk.sequence IS 'Order of a particular chunk. Chunks are orders in ascending order starting from 1.';


COMMENT ON COLUMN messagechunk.content IS 'Text content for this chunk of the message. This content is full text searchable.';


COMMENT ON COLUMN messagechunk.blob IS 'Binary content for this chunk of the message.';


CREATE SEQUENCE messagechunk_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE messagechunk_id_seq OWNED BY messagechunk.id;


CREATE TABLE milestone (
    id integer NOT NULL,
    product integer,
    name text NOT NULL,
    distribution integer,
    dateexpected timestamp without time zone,
    active boolean DEFAULT true NOT NULL,
    productseries integer,
    distroseries integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    summary text,
    codename text,
    CONSTRAINT valid_name CHECK (valid_name(name)),
    CONSTRAINT valid_target CHECK ((NOT ((product IS NULL) AND (distribution IS NULL))))
);


COMMENT ON TABLE milestone IS 'An identifier that helps a maintainer group together things in some way, e.g. "1.2" could be a Milestone that bazaar developers could use to mark a task as needing fixing in bazaar 1.2.';


COMMENT ON COLUMN milestone.product IS 'The product for which this is a milestone.';


COMMENT ON COLUMN milestone.name IS 'The identifier text, e.g. "1.2."';


COMMENT ON COLUMN milestone.distribution IS 'The distribution to which this milestone belongs, if it is a distro milestone.';


COMMENT ON COLUMN milestone.dateexpected IS 'If set, the date on which we expect this milestone to be delivered. This allows for optional sorting by date.';


COMMENT ON COLUMN milestone.active IS 'Whether or not this milestone should be displayed in general listings. All milestones will be visible on the "page of milestones for product foo", but we want to be able to screen out obviously old milestones over time, for the general listings and vocabularies.';


COMMENT ON COLUMN milestone.productseries IS 'The productseries for which this is a milestone. A milestone on a productseries is ALWAYS also a milestone for the same product. This is because milestones started out on products/distributions but are moving to being on series/distroseries.';


COMMENT ON COLUMN milestone.distroseries IS 'The distroseries for which this is a milestone. A milestone on a distroseries is ALWAYS also a milestone for the same distribution. This is because milestones started out on products/distributions but are moving to being on series/distroseries.';


COMMENT ON COLUMN milestone.summary IS 'This can be used to summarize the changes included in past milestones and to document the status of current milestones.';


COMMENT ON COLUMN milestone.codename IS 'A fun or easier to remember name for the milestone/release.';


CREATE SEQUENCE milestone_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE milestone_id_seq OWNED BY milestone.id;


CREATE TABLE mirror (
    id integer NOT NULL,
    owner integer NOT NULL,
    baseurl text NOT NULL,
    country integer NOT NULL,
    name text NOT NULL,
    description text NOT NULL,
    freshness integer DEFAULT 99 NOT NULL,
    lastcheckeddate timestamp without time zone,
    approved boolean DEFAULT false NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE mirror IS 'Stores general information about mirror sites. Both regular pull mirrors and top tier mirrors are included.';


COMMENT ON COLUMN mirror.baseurl IS 'The base URL to the mirror, including protocol and optional trailing slash.';


COMMENT ON COLUMN mirror.country IS 'The country where the mirror is located.';


COMMENT ON COLUMN mirror.name IS 'Unique name for the mirror, suitable for use in URLs.';


COMMENT ON COLUMN mirror.description IS 'Description of the mirror.';


COMMENT ON COLUMN mirror.freshness IS 'dbschema.MirrorFreshness enumeration indicating freshness.';


COMMENT ON COLUMN mirror.lastcheckeddate IS 'UTC timestamp of when the last check for freshness and consistency was made. NULL indicates no check has ever been made.';


COMMENT ON COLUMN mirror.approved IS 'True if this mirror has been approved by the Ubuntu/Canonical mirror manager, otherwise False.';


CREATE SEQUENCE mirror_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE mirror_id_seq OWNED BY mirror.id;


CREATE TABLE mirrorcdimagedistroseries (
    id integer NOT NULL,
    distribution_mirror integer NOT NULL,
    distroseries integer NOT NULL,
    flavour text NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE mirrorcdimagedistroseries IS 'The mirror of a given CD/DVD image.';


COMMENT ON COLUMN mirrorcdimagedistroseries.distribution_mirror IS 'The distribution mirror.';


COMMENT ON COLUMN mirrorcdimagedistroseries.distroseries IS 'The Distribution Release.';


COMMENT ON COLUMN mirrorcdimagedistroseries.flavour IS 'The Distribution Release Flavour.';


CREATE SEQUENCE mirrorcdimagedistroseries_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE mirrorcdimagedistroseries_id_seq OWNED BY mirrorcdimagedistroseries.id;


CREATE TABLE mirrorcontent (
    id integer NOT NULL,
    mirror integer NOT NULL,
    distroarchseries integer NOT NULL,
    component integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE mirrorcontent IS 'Stores which distroarchseries and compoenents a given mirror has.';


COMMENT ON COLUMN mirrorcontent.distroarchseries IS 'A distroarchseries that this mirror contains.';


COMMENT ON COLUMN mirrorcontent.component IS 'What component of the distroarchseries that this mirror contains.';


CREATE SEQUENCE mirrorcontent_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE mirrorcontent_id_seq OWNED BY mirrorcontent.id;


CREATE TABLE mirrordistroarchseries (
    id integer NOT NULL,
    distribution_mirror integer NOT NULL,
    distroarchseries integer NOT NULL,
    freshness integer NOT NULL,
    pocket integer NOT NULL,
    component integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE mirrordistroarchseries IS 'The mirror of the packages of a given Distro Arch Release.';


COMMENT ON COLUMN mirrordistroarchseries.distribution_mirror IS 'The distribution mirror.';


COMMENT ON COLUMN mirrordistroarchseries.distroarchseries IS 'The distro arch series.';


COMMENT ON COLUMN mirrordistroarchseries.freshness IS 'The freshness of the mirror, that is, how up-to-date it is.';


COMMENT ON COLUMN mirrordistroarchseries.pocket IS 'The PackagePublishingPocket.';


CREATE SEQUENCE mirrordistroarchseries_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE mirrordistroarchseries_id_seq OWNED BY mirrordistroarchseries.id;


CREATE TABLE mirrordistroseriessource (
    id integer NOT NULL,
    distribution_mirror integer NOT NULL,
    distroseries integer NOT NULL,
    freshness integer NOT NULL,
    pocket integer NOT NULL,
    component integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE mirrordistroseriessource IS 'The mirror of a given Distro Release';


COMMENT ON COLUMN mirrordistroseriessource.distribution_mirror IS 'The distribution mirror.';


COMMENT ON COLUMN mirrordistroseriessource.distroseries IS 'The Distribution Release.';


COMMENT ON COLUMN mirrordistroseriessource.freshness IS 'The freshness of the mirror, that is, how up-to-date it is.';


CREATE SEQUENCE mirrordistroseriessource_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE mirrordistroseriessource_id_seq OWNED BY mirrordistroseriessource.id;


CREATE TABLE mirrorproberecord (
    id integer NOT NULL,
    distribution_mirror integer NOT NULL,
    log_file integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL
);


COMMENT ON TABLE mirrorproberecord IS 'Records stored when a mirror is probed.';


COMMENT ON COLUMN mirrorproberecord.distribution_mirror IS 'The DistributionMirror.';


COMMENT ON COLUMN mirrorproberecord.log_file IS 'The log file of the probe.';


COMMENT ON COLUMN mirrorproberecord.date_created IS 'The date and time the probe was performed.';


CREATE SEQUENCE mirrorproberecord_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE mirrorproberecord_id_seq OWNED BY mirrorproberecord.id;


CREATE TABLE mirrorsourcecontent (
    id integer NOT NULL,
    mirror integer NOT NULL,
    distroseries integer NOT NULL,
    component integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE mirrorsourcecontent IS 'Stores which distroseries and components a given mirror that includes source packages has.';


COMMENT ON COLUMN mirrorsourcecontent.distroseries IS 'A distroseries that this mirror contains.';


COMMENT ON COLUMN mirrorsourcecontent.component IS 'What component of the distroseries that this sourcepackage mirror contains.';


CREATE SEQUENCE mirrorsourcecontent_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE mirrorsourcecontent_id_seq OWNED BY mirrorsourcecontent.id;


CREATE TABLE nameblacklist (
    id integer NOT NULL,
    regexp text NOT NULL,
    comment text,
    admin integer,
    CONSTRAINT valid_regexp CHECK (valid_regexp(regexp))
);


COMMENT ON TABLE nameblacklist IS 'A list of regular expressions used to blacklist names.';


COMMENT ON COLUMN nameblacklist.regexp IS 'A Python regular expression. It will be compiled with the IGNORECASE, UNICODE and VERBOSE flags. The Python search method will be used rather than match, so ^ markers should be used to indicate the start of a string.';


COMMENT ON COLUMN nameblacklist.comment IS 'An optional comment on why this regexp was entered. It should not be displayed to non-admins and its only purpose is documentation.';


CREATE SEQUENCE nameblacklist_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE nameblacklist_id_seq OWNED BY nameblacklist.id;


CREATE TABLE oauthaccesstoken (
    id integer NOT NULL,
    consumer integer NOT NULL,
    person integer NOT NULL,
    permission integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_expires timestamp without time zone,
    key text NOT NULL,
    secret text NOT NULL,
    product integer,
    project integer,
    distribution integer,
    sourcepackagename integer,
    CONSTRAINT just_one_context CHECK ((null_count(ARRAY[product, project, distribution]) >= 2)),
    CONSTRAINT sourcepackagename_needs_distro CHECK (((sourcepackagename IS NULL) OR (distribution IS NOT NULL)))
);


COMMENT ON TABLE oauthaccesstoken IS 'An access token used by the consumer to act on behalf of one of our users.';


COMMENT ON COLUMN oauthaccesstoken.consumer IS 'The consumer which is going to access the protected resources.';


COMMENT ON COLUMN oauthaccesstoken.person IS 'The person on whose behalf the
consumer will access Launchpad.';


COMMENT ON COLUMN oauthaccesstoken.permission IS 'The permission given by that person to the consumer.';


COMMENT ON COLUMN oauthaccesstoken.date_created IS 'The date/time in which the token was created.';


COMMENT ON COLUMN oauthaccesstoken.date_expires IS 'The date/time in which this token will stop being accepted by Launchpad.';


COMMENT ON COLUMN oauthaccesstoken.key IS 'This token''s unique key.';


COMMENT ON COLUMN oauthaccesstoken.secret IS 'The secret used by the consumer (together with the token''s key) to access Launchpad on behalf of the person.';


COMMENT ON COLUMN oauthaccesstoken.product IS 'The product associated with this token.';


COMMENT ON COLUMN oauthaccesstoken.project IS 'The project associated with this token.';


COMMENT ON COLUMN oauthaccesstoken.distribution IS 'The distribution associated with this token.';


COMMENT ON COLUMN oauthaccesstoken.sourcepackagename IS 'The sourcepackagename associated with this token.';


CREATE SEQUENCE oauthaccesstoken_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE oauthaccesstoken_id_seq OWNED BY oauthaccesstoken.id;


CREATE TABLE oauthconsumer (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    disabled boolean DEFAULT false NOT NULL,
    key text NOT NULL,
    secret text
);


COMMENT ON TABLE oauthconsumer IS 'A third part application that will access Launchpad on behalf of one of our users.';


COMMENT ON COLUMN oauthconsumer.date_created IS 'The creation date.';


COMMENT ON COLUMN oauthconsumer.disabled IS 'Is this consumer disabled?';


COMMENT ON COLUMN oauthconsumer.key IS 'The unique key for this consumer.';


COMMENT ON COLUMN oauthconsumer.secret IS 'The secret used by this consumer (together with its key) to identify itself with Launchpad.';


CREATE SEQUENCE oauthconsumer_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE oauthconsumer_id_seq OWNED BY oauthconsumer.id;


CREATE TABLE oauthnonce (
    request_timestamp timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    nonce text NOT NULL,
    access_token integer NOT NULL
);


COMMENT ON TABLE oauthnonce IS 'The unique nonce for any request with a given timestamp and access token. This is generated by the consumer.';


COMMENT ON COLUMN oauthnonce.request_timestamp IS 'The date and time (as a timestamp) in which the request was made.';


COMMENT ON COLUMN oauthnonce.nonce IS 'The nonce itself.';


COMMENT ON COLUMN oauthnonce.access_token IS 'The access token.';


CREATE TABLE oauthrequesttoken (
    id integer NOT NULL,
    consumer integer NOT NULL,
    person integer,
    permission integer,
    date_expires timestamp without time zone,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_reviewed timestamp without time zone,
    key text NOT NULL,
    secret text NOT NULL,
    product integer,
    project integer,
    distribution integer,
    sourcepackagename integer,
    CONSTRAINT just_one_context CHECK ((null_count(ARRAY[product, project, distribution]) >= 2)),
    CONSTRAINT reviewed_request CHECK ((((date_reviewed IS NULL) = (person IS NULL)) AND ((date_reviewed IS NULL) = (permission IS NULL)))),
    CONSTRAINT sourcepackagename_needs_distro CHECK (((sourcepackagename IS NULL) OR (distribution IS NOT NULL)))
);


COMMENT ON TABLE oauthrequesttoken IS 'A request token which, once authorized by the user, is exchanged for an access token.';


COMMENT ON COLUMN oauthrequesttoken.consumer IS 'The consumer which is going to access the protected resources.';


COMMENT ON COLUMN oauthrequesttoken.person IS 'The person who authorized this token.';


COMMENT ON COLUMN oauthrequesttoken.permission IS 'The permission given by the
person to the consumer.';


COMMENT ON COLUMN oauthrequesttoken.date_expires IS 'When the authorization is to expire.';


COMMENT ON COLUMN oauthrequesttoken.date_created IS 'The date/time in which the token was created.';


COMMENT ON COLUMN oauthrequesttoken.date_reviewed IS 'When the authorization request was authorized or rejected by the person.';


COMMENT ON COLUMN oauthrequesttoken.key IS 'This token''s unique key.';


COMMENT ON COLUMN oauthrequesttoken.secret IS 'The secret used by the consumer (together with the token''s key) to get an access token once the user has authorized its use.';


COMMENT ON COLUMN oauthrequesttoken.product IS 'The product associated with this token.';


COMMENT ON COLUMN oauthrequesttoken.project IS 'The project associated with this token.';


COMMENT ON COLUMN oauthrequesttoken.distribution IS 'The distribution associated with this token.';


COMMENT ON COLUMN oauthrequesttoken.sourcepackagename IS 'The sourcepackagename associated with this token.';


CREATE SEQUENCE oauthrequesttoken_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE oauthrequesttoken_id_seq OWNED BY oauthrequesttoken.id;


CREATE TABLE officialbugtag (
    id integer NOT NULL,
    tag text NOT NULL,
    distribution integer,
    project integer,
    product integer,
    CONSTRAINT context_required CHECK (((product IS NOT NULL) OR (distribution IS NOT NULL)))
);


COMMENT ON TABLE officialbugtag IS 'Bug tags that have been officially endorced by this product''s or distribution''s lead';


CREATE SEQUENCE officialbugtag_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE officialbugtag_id_seq OWNED BY officialbugtag.id;


CREATE TABLE openidconsumerassociation (
    server_url character varying(2047) NOT NULL,
    handle character varying(255) NOT NULL,
    secret bytea,
    issued integer,
    lifetime integer,
    assoc_type character varying(64),
    CONSTRAINT secret_length_constraint CHECK ((length(secret) <= 128))
);


CREATE TABLE openidconsumernonce (
    server_url character varying(2047) NOT NULL,
    "timestamp" integer NOT NULL,
    salt character(40) NOT NULL
);


CREATE TABLE openididentifier (
    identifier text NOT NULL,
    account integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE openididentifier IS 'OpenId Identifiers that can be used to log into an Account.';


COMMENT ON COLUMN openididentifier.identifier IS 'OpenId Identifier. This should be a URL, but is currently just a token that can be used to generate the Identity URL for the Canonical SSO OpenId Provider.';


CREATE TABLE packagebuild (
    id integer NOT NULL,
    build_farm_job integer NOT NULL,
    archive integer NOT NULL,
    pocket integer DEFAULT 0 NOT NULL,
    upload_log integer,
    dependencies text
);


COMMENT ON TABLE packagebuild IS 'PackageBuild: This table stores the information common to build farm jobs that build source or binary packages.';


COMMENT ON COLUMN packagebuild.build_farm_job IS 'Points to the build farm job with the base information.';


COMMENT ON COLUMN packagebuild.archive IS 'Targeted archive for this package build.';


COMMENT ON COLUMN packagebuild.pocket IS 'Stores the target pocket identifier for this package build.';


COMMENT ON COLUMN packagebuild.upload_log IS 'Reference to a LibraryFileAlias containing the upload log messages generated while processing the packages resulting from this package build.';


COMMENT ON COLUMN packagebuild.dependencies IS 'Contains a debian-like dependency line specifying the current missing-dependencies for this package.';


CREATE SEQUENCE packagebuild_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packagebuild_id_seq OWNED BY packagebuild.id;


CREATE TABLE packagecopyjob (
    id integer NOT NULL,
    job integer NOT NULL,
    source_archive integer NOT NULL,
    target_archive integer NOT NULL,
    target_distroseries integer,
    job_type integer NOT NULL,
    json_data text,
    package_name text NOT NULL,
    copy_policy integer
);


CREATE SEQUENCE packagecopyjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packagecopyjob_id_seq OWNED BY packagecopyjob.id;


CREATE TABLE packagecopyrequest (
    id integer NOT NULL,
    target_archive integer NOT NULL,
    target_distroseries integer,
    target_component integer,
    target_pocket integer,
    copy_binaries boolean DEFAULT false NOT NULL,
    source_archive integer NOT NULL,
    source_distroseries integer,
    source_component integer,
    source_pocket integer,
    requester integer NOT NULL,
    status integer NOT NULL,
    reason text,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_started timestamp without time zone,
    date_completed timestamp without time zone
);


COMMENT ON TABLE packagecopyrequest IS 'PackageCopyRequest: A table that captures the status and the details of an inter-archive package copy operation.';


COMMENT ON COLUMN packagecopyrequest.target_archive IS 'The archive to which packages will be copied.';


COMMENT ON COLUMN packagecopyrequest.target_distroseries IS 'The target distroseries.';


COMMENT ON COLUMN packagecopyrequest.target_component IS 'The target component.';


COMMENT ON COLUMN packagecopyrequest.target_pocket IS 'The target pocket.';


COMMENT ON COLUMN packagecopyrequest.source_archive IS 'The archive from which packages are to be copied.';


COMMENT ON COLUMN packagecopyrequest.source_distroseries IS 'The distroseries to which the packages to be copied belong in the source archive.';


COMMENT ON COLUMN packagecopyrequest.source_component IS 'The component to which the packages to be copied belong in the source archive.';


COMMENT ON COLUMN packagecopyrequest.source_pocket IS 'The pocket for the packages to be copied.';


COMMENT ON COLUMN packagecopyrequest.requester IS 'The person who requested the archive operation.';


COMMENT ON COLUMN packagecopyrequest.status IS 'Archive operation status, may be one of: new, in-progress, complete, failed, cancelling, cancelled.';


COMMENT ON COLUMN packagecopyrequest.reason IS 'The reason why this copy operation was requested.';


COMMENT ON COLUMN packagecopyrequest.date_created IS 'Date of creation for this archive operation.';


COMMENT ON COLUMN packagecopyrequest.date_started IS 'Start date/time of this archive operation.';


COMMENT ON COLUMN packagecopyrequest.date_completed IS 'When did this archive operation conclude?';


CREATE SEQUENCE packagecopyrequest_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packagecopyrequest_id_seq OWNED BY packagecopyrequest.id;


CREATE TABLE packagediff (
    id integer NOT NULL,
    date_requested timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    requester integer NOT NULL,
    from_source integer NOT NULL,
    to_source integer NOT NULL,
    date_fulfilled timestamp without time zone,
    diff_content integer,
    status integer DEFAULT 0 NOT NULL,
    CONSTRAINT distinct_sources CHECK ((from_source <> to_source))
);


COMMENT ON TABLE packagediff IS 'This table stores diffs bettwen two scpecific SourcePackageRelease versions.';


COMMENT ON COLUMN packagediff.date_requested IS 'Instant when the diff was requested.';


COMMENT ON COLUMN packagediff.requester IS 'The Person responsible for the request.';


COMMENT ON COLUMN packagediff.from_source IS 'The SourcePackageRelease to diff from.';


COMMENT ON COLUMN packagediff.to_source IS 'The SourcePackageRelease to diff to.';


COMMENT ON COLUMN packagediff.date_fulfilled IS 'Instant when the diff was completed.';


COMMENT ON COLUMN packagediff.diff_content IS 'LibraryFileAlias containing the th diff results.';


COMMENT ON COLUMN packagediff.status IS 'Request status, PENDING(0) when created then goes to COMPLETED(1) or FAILED(2), both terminal status where diff_content and date_fulfilled will contain the results of the request.';


CREATE SEQUENCE packagediff_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packagediff_id_seq OWNED BY packagediff.id;


CREATE TABLE packageset (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    owner integer NOT NULL,
    name text NOT NULL,
    description text NOT NULL,
    packagesetgroup integer NOT NULL,
    distroseries integer NOT NULL,
    CONSTRAINT packageset_name_check CHECK (valid_name(name))
);


COMMENT ON TABLE packageset IS 'Package sets facilitate the grouping of packages (in a given distro series) for purposes like the control of upload permissions, etc.';


COMMENT ON COLUMN packageset.date_created IS 'Date and time of creation.';


COMMENT ON COLUMN packageset.owner IS 'The Person or team who owns the package
set group.';


COMMENT ON COLUMN packageset.name IS 'The name for the package set on hand.';


COMMENT ON COLUMN packageset.description IS 'The description for the package set on hand.';


COMMENT ON COLUMN packageset.packagesetgroup IS 'The group this package set is affiliated with.';


COMMENT ON COLUMN packageset.distroseries IS 'The distro series this package set belongs to.';


CREATE SEQUENCE packageset_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packageset_id_seq OWNED BY packageset.id;


CREATE TABLE packagesetgroup (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    owner integer NOT NULL
);


COMMENT ON TABLE packagesetgroup IS 'Package set groups keep track of equivalent package sets across distro series boundaries.';


CREATE SEQUENCE packagesetgroup_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packagesetgroup_id_seq OWNED BY packagesetgroup.id;


CREATE TABLE packagesetinclusion (
    id integer NOT NULL,
    parent integer NOT NULL,
    child integer NOT NULL
);


COMMENT ON TABLE packagesetinclusion IS 'sets may form a set-subset hierarchy; this table facilitates the definition of these set-subset relationships.';


COMMENT ON COLUMN packagesetinclusion.parent IS 'The package set that is including a subset.';


COMMENT ON COLUMN packagesetinclusion.child IS 'The package set that is being included as a subset.';


CREATE SEQUENCE packagesetinclusion_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packagesetinclusion_id_seq OWNED BY packagesetinclusion.id;


CREATE TABLE packagesetsources (
    id integer NOT NULL,
    packageset integer NOT NULL,
    sourcepackagename integer NOT NULL
);


COMMENT ON TABLE packagesetsources IS 'This table associates package sets and source package names.';


COMMENT ON COLUMN packagesetsources.packageset IS 'The associated package set.';


COMMENT ON COLUMN packagesetsources.sourcepackagename IS 'The associated source package name.';


CREATE SEQUENCE packagesetsources_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packagesetsources_id_seq OWNED BY packagesetsources.id;


CREATE TABLE packageupload (
    id integer NOT NULL,
    status integer DEFAULT 0 NOT NULL,
    distroseries integer NOT NULL,
    pocket integer NOT NULL,
    changesfile integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    signing_key integer,
    archive integer NOT NULL,
    package_copy_job integer
);


COMMENT ON TABLE packageupload IS 'An upload. This table stores information pertaining to uploads to a given DistroSeries/Archive.';


COMMENT ON COLUMN packageupload.status IS 'This is an integer field containing the current status of the upload. Possible values are given by the UploadStatus class in dbschema.py';


COMMENT ON COLUMN packageupload.distroseries IS 'This integer field refers to the DistroSeries to which this upload is targeted';


COMMENT ON COLUMN packageupload.pocket IS 'This is the pocket the upload is targeted at.';


COMMENT ON COLUMN packageupload.changesfile IS 'The changes file associated with this upload. It is null for records refering to a delayed-copy.';


COMMENT ON COLUMN packageupload.archive IS 'The archive to which this upload is targetted.';


CREATE SEQUENCE packageupload_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packageupload_id_seq OWNED BY packageupload.id;


CREATE TABLE packageuploadbuild (
    id integer NOT NULL,
    packageupload integer NOT NULL,
    build integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE packageuploadbuild IS 'An upload binary build. This table stores information pertaining to the builds in a package upload.';


COMMENT ON COLUMN packageuploadbuild.packageupload IS 'This integer field refers to the PackageUpload row that this source belongs to.';


COMMENT ON COLUMN packageuploadbuild.build IS 'This integer field refers to the Build record related to this upload.';


CREATE SEQUENCE packageuploadbuild_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packageuploadbuild_id_seq OWNED BY packageuploadbuild.id;


CREATE TABLE packageuploadcustom (
    id integer NOT NULL,
    packageupload integer NOT NULL,
    customformat integer NOT NULL,
    libraryfilealias integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE packageuploadcustom IS 'An uploaded custom format file. This table stores information pertaining to the custom upload formats in a package upload.';


COMMENT ON COLUMN packageuploadcustom.packageupload IS 'The PackageUpload row this refers to.';


COMMENT ON COLUMN packageuploadcustom.customformat IS 'The format of this particular custom uploaded file.';


COMMENT ON COLUMN packageuploadcustom.libraryfilealias IS 'The actual file as a librarian alias.';


CREATE SEQUENCE packageuploadcustom_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packageuploadcustom_id_seq OWNED BY packageuploadcustom.id;


CREATE TABLE packageuploadsource (
    id integer NOT NULL,
    packageupload integer NOT NULL,
    sourcepackagerelease integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE packageuploadsource IS 'Link between an upload and a source package. This table stores information pertaining to the source files in a package upload.';


COMMENT ON COLUMN packageuploadsource.packageupload IS 'This integer field refers to the PackageUpload row that this source belongs to.';


COMMENT ON COLUMN packageuploadsource.sourcepackagerelease IS 'This integer field refers to the SourcePackageRelease record related to this upload.';


CREATE SEQUENCE packageuploadsource_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packageuploadsource_id_seq OWNED BY packageuploadsource.id;


CREATE TABLE packaging (
    packaging integer NOT NULL,
    id integer DEFAULT nextval(('packaging_id_seq'::text)::regclass) NOT NULL,
    sourcepackagename integer,
    distroseries integer NOT NULL,
    productseries integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    owner integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE packaging IS 'DO NOT JOIN THROUGH THIS TABLE. This is a set
of information linking upstream product series (branches) to distro
packages, but it''s not planned or likely to be complete, in the sense that
we do not attempt to have information for every branch in every derivative
distro managed in Launchpad. So don''t join through this table to get from
product to source package, or vice versa. Rather, use the
ProductSeries.sourcepackages attribute, or the
SourcePackage.productseries attribute. You may need to create a
SourcePackage with a given sourcepackagename and distroseries, then use its
.productrelease attribute. The code behind those methods does more than just
join through the tables, it is also smart enough to look at related
distro''s and parent distroseries, and at Ubuntu in particular.';


COMMENT ON COLUMN packaging.packaging IS 'A dbschema Enum (PackagingType)
describing the way the upstream productseries has been packaged. Generally
it will be of type PRIME, meaning that the upstream productseries is the
primary substance of the package, but it might also be INCLUDES, if the
productseries has been included as a statically linked library, for example.
This allows us to say that a given Source Package INCLUDES libneon but is a
PRIME package of tla, for example. By INCLUDES we mean that the code is
actually lumped into the package as ancilliary support material, rather
than simply depending on a separate packaging of that code.';


COMMENT ON COLUMN packaging.sourcepackagename IS 'The source package name for
the source package that includes the upstream productseries described in
this Packaging record. There is no requirement that such a sourcepackage
actually be published in the distro.';


COMMENT ON COLUMN packaging.distroseries IS 'The distroseries in which the
productseries has been packaged.';


COMMENT ON COLUMN packaging.productseries IS 'The upstream product series
that has been packaged in this distroseries sourcepackage.';


COMMENT ON COLUMN packaging.owner IS 'This is not the "owner" in the sense
of giving the person any special privileges to edit the Packaging record,
it is simply a record of who told us about this packaging relationship. Note
that we do not keep a history of these, so if someone sets it correctly,
then someone else sets it incorrectly, we lose the first setting.';


CREATE SEQUENCE packaging_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packaging_id_seq OWNED BY packaging.id;


CREATE TABLE packagingjob (
    id integer NOT NULL,
    job integer NOT NULL,
    job_type integer NOT NULL,
    productseries integer,
    sourcepackagename integer,
    distroseries integer,
    potemplate integer,
    CONSTRAINT translationtemplatejob_valid_link CHECK ((((((potemplate IS NOT NULL) AND (productseries IS NULL)) AND (distroseries IS NULL)) AND (sourcepackagename IS NULL)) OR ((((potemplate IS NULL) AND (productseries IS NOT NULL)) AND (distroseries IS NOT NULL)) AND (sourcepackagename IS NOT NULL))))
);


CREATE SEQUENCE packagingjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE packagingjob_id_seq OWNED BY packagingjob.id;


CREATE TABLE parsedapachelog (
    id integer NOT NULL,
    first_line text NOT NULL,
    bytes_read bigint NOT NULL,
    date_last_parsed timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE parsedapachelog IS 'A parsed apache log file for librarian.';


COMMENT ON COLUMN parsedapachelog.first_line IS 'The first line of this log file, smashed to ASCII. This uniquely identifies the log file, even if its filename is changed by log rotation or archival.';


COMMENT ON COLUMN parsedapachelog.bytes_read IS 'The number of bytes from this log file that have been parsed.';


CREATE SEQUENCE parsedapachelog_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE parsedapachelog_id_seq OWNED BY parsedapachelog.id;


CREATE TABLE person (
    id integer NOT NULL,
    displayname text NOT NULL,
    teamowner integer,
    teamdescription text,
    name text NOT NULL,
    language integer,
    fti ts2.tsvector,
    defaultmembershipperiod integer,
    defaultrenewalperiod integer,
    subscriptionpolicy integer DEFAULT 1 NOT NULL,
    merged integer,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    homepage_content text,
    icon integer,
    mugshot integer,
    hide_email_addresses boolean DEFAULT false NOT NULL,
    creation_rationale integer,
    creation_comment text,
    registrant integer,
    logo integer,
    renewal_policy integer DEFAULT 10 NOT NULL,
    personal_standing integer DEFAULT 0 NOT NULL,
    personal_standing_reason text,
    mail_resumption_date date,
    mailing_list_auto_subscribe_policy integer DEFAULT 1 NOT NULL,
    mailing_list_receive_duplicates boolean DEFAULT true NOT NULL,
    visibility integer DEFAULT 1 NOT NULL,
    verbose_bugnotifications boolean DEFAULT false NOT NULL,
    account integer,
    description text,
    CONSTRAINT creation_rationale_not_null_for_people CHECK (((creation_rationale IS NULL) = (teamowner IS NOT NULL))),
    CONSTRAINT no_loops CHECK ((id <> teamowner)),
    CONSTRAINT non_empty_displayname CHECK ((btrim(displayname) <> ''::text)),
    CONSTRAINT people_have_no_emblems CHECK (((icon IS NULL) OR (teamowner IS NOT NULL))),
    CONSTRAINT sane_defaultrenewalperiod CHECK (CASE WHEN (teamowner IS NULL) THEN (defaultrenewalperiod IS NULL) WHEN (renewal_policy = ANY (ARRAY[20, 30])) THEN ((defaultrenewalperiod IS NOT NULL) AND (defaultrenewalperiod > 0)) ELSE ((defaultrenewalperiod IS NULL) OR (defaultrenewalperiod > 0)) END),
    CONSTRAINT teams_have_no_account CHECK (((account IS NULL) OR (teamowner IS NULL))),
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE person IS 'A row represents a person if teamowner is NULL, and represents a team if teamowner is set.';


COMMENT ON COLUMN person.displayname IS 'Person or group''s name as it should be rendered to screen';


COMMENT ON COLUMN person.teamowner IS 'id of the team owner. Team owners will have authority to add or remove people from the team.';


COMMENT ON COLUMN person.teamdescription IS 'Informative description of the team. Format and restrictions are as yet undefined.';


COMMENT ON COLUMN person.name IS 'Short mneumonic name uniquely identifying this person or team. Useful for url traversal or in places where we need to unambiguously refer to a person or team (as displayname is not unique).';


COMMENT ON COLUMN person.language IS 'Preferred language for this person (unset for teams). UI should be displayed in this language wherever possible.';


COMMENT ON COLUMN person.subscriptionpolicy IS 'The policy for new members to join this team.';


COMMENT ON COLUMN person.homepage_content IS 'A home page for this person in the Launchpad. In short, this is like a personal wiki page. The person will get to edit their own page, and it will be published on /people/foo/. Note that this is in text format, and will migrate to being in Moin format as a sort of mini-wiki-homepage.';


COMMENT ON COLUMN person.icon IS 'The library file alias to a small image to be used as an icon whenever we are referring to that person.';


COMMENT ON COLUMN person.mugshot IS 'The library file alias of a hackermugshot image to display as the "face" of a person, on their home page.';


COMMENT ON COLUMN person.creation_rationale IS 'The rationale for the creation of this person -- a dbschema value.';


COMMENT ON COLUMN person.creation_comment IS 'A text comment for the creation of this person.';


COMMENT ON COLUMN person.registrant IS 'The user who created this profile.';


COMMENT ON COLUMN person.logo IS 'The library file alias of a smaller version of this person''s mugshot.';


COMMENT ON COLUMN person.renewal_policy IS 'The policy for membership renewal on this team.';


COMMENT ON COLUMN person.personal_standing IS 'The standing of the person, which indicates (for now, just) whether the person can post to a mailing list without requiring first post moderation.  Values are documented in dbschema.PersonalStanding.';


COMMENT ON COLUMN person.personal_standing_reason IS 'The reason a person''s standing has changed.';


COMMENT ON COLUMN person.mail_resumption_date IS 'A NULL resumption date or a date in the past indicates that there is no vacation in effect.  Vacations are granular to the day, so a datetime is not necessary.';


COMMENT ON COLUMN person.mailing_list_auto_subscribe_policy IS 'The auto-subscription policy for the person, i.e. whether and how the user is automatically subscribed to mailing lists for teams they join.  Values are described in dbschema.MailingListAutoSubscribePolicy.';


COMMENT ON COLUMN person.mailing_list_receive_duplicates IS 'True means the user wants to receive list copies of messages on which they are explicitly named as a recipient.';


COMMENT ON COLUMN person.visibility IS 'person.PersonVisibility enumeration which can be set to Public, Public with Private Membership, or Private.';


COMMENT ON COLUMN person.verbose_bugnotifications IS 'If true, all bugnotifications sent to this Person will include the bug description.';


COMMENT ON COLUMN person.account IS 'The Account linked to this Person, if there is one.';


CREATE SEQUENCE person_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE person_id_seq OWNED BY person.id;


CREATE TABLE personlanguage (
    id integer NOT NULL,
    person integer NOT NULL,
    language integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE personlanguage IS 'PersonLanguage: This table stores the preferred languages that a Person has, it''s used in Rosetta to select the languages that should be showed to be translated.';


COMMENT ON COLUMN personlanguage.person IS 'This field is a reference to a Person object that has this preference.';


COMMENT ON COLUMN personlanguage.language IS 'This field is a reference to a Language object that says that the Person associated to this row knows how to translate/understand this language.';


CREATE SEQUENCE personlanguage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE personlanguage_id_seq OWNED BY personlanguage.id;


CREATE TABLE personlocation (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    person integer NOT NULL,
    latitude double precision,
    longitude double precision,
    time_zone text,
    last_modified_by integer NOT NULL,
    date_last_modified timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    visible boolean DEFAULT true,
    locked boolean DEFAULT false,
    CONSTRAINT latitude_and_longitude_together CHECK (((latitude IS NULL) = (longitude IS NULL)))
);


COMMENT ON TABLE personlocation IS 'The geographical coordinates and time zone for a person.';


COMMENT ON COLUMN personlocation.latitude IS 'The latitude this person has given for their default location.';


COMMENT ON COLUMN personlocation.longitude IS 'The longitude this person has given for their default location.';


COMMENT ON COLUMN personlocation.time_zone IS 'The name of the time zone this person prefers (if unset, UTC is used).  UI should display dates and times in this time zone wherever possible.';


COMMENT ON COLUMN personlocation.last_modified_by IS 'The person who last updated this record. We allow people to provide location and time zone information for other users, when those users have not specified their own location. This allows people to garden the location information for their teams, for example, like a wiki.';


COMMENT ON COLUMN personlocation.date_last_modified IS 'The date this record was last modified.';


COMMENT ON COLUMN personlocation.visible IS 'Should this person''s location and time zone be visible to others?';


COMMENT ON COLUMN personlocation.locked IS 'Whether or not this record can be modified by someone other than the person himself?';


CREATE SEQUENCE personlocation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE personlocation_id_seq OWNED BY personlocation.id;


CREATE TABLE personnotification (
    id integer NOT NULL,
    person integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_emailed timestamp without time zone,
    body text NOT NULL,
    subject text NOT NULL
);


COMMENT ON TABLE personnotification IS 'Notifications to be sent that are related to edits and changes of the details of a specific person or team. Note that these are not keyed against the "person who will be notified", these are notifications "about a person". We use this table to queue up notifications that can then be sent asyncronously - when one user edits information about another person (like the PersonLocation) we want to notify the person concerned that their details have been modified but we do not want to do this during the handling of the form submission. So we store the reminder to notify here, and send it later in a batch. This is modelled on the pattern of BugNotification.';


COMMENT ON COLUMN personnotification.person IS 'The Person who has been edited or modified.';


COMMENT ON COLUMN personnotification.date_emailed IS 'When this notification was emailed to the relevant people.';


COMMENT ON COLUMN personnotification.body IS 'The textual body of the notification to be sent.';


COMMENT ON COLUMN personnotification.subject IS 'The subject of the mail to be sent.';


CREATE SEQUENCE personnotification_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE personnotification_id_seq OWNED BY personnotification.id;


CREATE TABLE personsettings (
    person integer NOT NULL,
    selfgenerated_bugnotifications boolean DEFAULT false NOT NULL
);


CREATE TABLE persontransferjob (
    id integer NOT NULL,
    job integer NOT NULL,
    job_type integer NOT NULL,
    minor_person integer NOT NULL,
    major_person integer NOT NULL,
    json_data text
);


COMMENT ON TABLE persontransferjob IS 'Contains references to jobs for adding team members or merging person entries.';


COMMENT ON COLUMN persontransferjob.job IS 'A reference to a row in the Job table that has all the common job details.';


COMMENT ON COLUMN persontransferjob.job_type IS 'The type of job, like add-member notification or merge persons.';


COMMENT ON COLUMN persontransferjob.minor_person IS 'The person that is being added is a new member or being merged into another person.';


COMMENT ON COLUMN persontransferjob.major_person IS 'The team receiving a new member or the person that another person is merged into.';


COMMENT ON COLUMN persontransferjob.json_data IS 'Data that is specific to the type of job, normally stores text to append to email notifications.';


CREATE SEQUENCE persontransferjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE persontransferjob_id_seq OWNED BY persontransferjob.id;


CREATE TABLE pillarname (
    id integer NOT NULL,
    name text NOT NULL,
    product integer,
    project integer,
    distribution integer,
    active boolean DEFAULT true NOT NULL,
    alias_for integer,
    CONSTRAINT only_one_target CHECK ((null_count(ARRAY[product, project, distribution, alias_for]) = 3)),
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE pillarname IS 'A cache of the names of our "Pillar''s" (distribution, product, project) to ensure uniqueness in this shared namespace. This is a materialized view maintained by database triggers.';


COMMENT ON COLUMN pillarname.alias_for IS 'An alias for another pillarname. Rows with this column set are not maintained by triggers.';


CREATE SEQUENCE pillarname_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE pillarname_id_seq OWNED BY pillarname.id;


CREATE TABLE pocketchroot (
    id integer NOT NULL,
    distroarchseries integer,
    pocket integer NOT NULL,
    chroot integer,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE pocketchroot IS 'PocketChroots: Which chroot belongs to which pocket of which distroarchseries. Any given pocket of any given distroarchseries needs a specific chroot in order to be built. This table links it all together.';


COMMENT ON COLUMN pocketchroot.distroarchseries IS 'Which distroarchseries this chroot applies to.';


COMMENT ON COLUMN pocketchroot.pocket IS 'Which pocket of the distroarchseries this chroot applies to. Valid values are specified in dbschema.PackagePublishingPocket';


COMMENT ON COLUMN pocketchroot.chroot IS 'The chroot used by the pocket of the distroarchseries.';


CREATE SEQUENCE pocketchroot_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE pocketchroot_id_seq OWNED BY pocketchroot.id;


CREATE TABLE poexportrequest (
    id integer NOT NULL,
    person integer NOT NULL,
    potemplate integer NOT NULL,
    pofile integer,
    format integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE poexportrequest IS 'A request from a user that a PO template or a PO file be exported
asynchronously.';


COMMENT ON COLUMN poexportrequest.person IS 'The person who made the request.';


COMMENT ON COLUMN poexportrequest.potemplate IS 'The PO template being requested.';


COMMENT ON COLUMN poexportrequest.pofile IS 'The PO file being requested, or NULL.';


COMMENT ON COLUMN poexportrequest.format IS 'The format the user would like the export to be in. See the RosettaFileFormat DB schema for possible values.';


CREATE SEQUENCE poexportrequest_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE poexportrequest_id_seq OWNED BY poexportrequest.id;


CREATE TABLE pofile (
    id integer NOT NULL,
    potemplate integer NOT NULL,
    language integer NOT NULL,
    description text,
    topcomment text,
    header text,
    fuzzyheader boolean NOT NULL,
    lasttranslator integer,
    currentcount integer NOT NULL,
    updatescount integer NOT NULL,
    rosettacount integer NOT NULL,
    lastparsed timestamp without time zone,
    owner integer NOT NULL,
    path text NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    from_sourcepackagename integer,
    unreviewed_count integer DEFAULT 0 NOT NULL,
    date_changed timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE pofile IS 'This table stores a PO file for a given PO template.';


COMMENT ON COLUMN pofile.path IS 'The path (included the filename) inside the tree from where the content was imported.';


COMMENT ON COLUMN pofile.from_sourcepackagename IS 'The sourcepackagename from where the last .po file came (only if it''s different from POFile.potemplate.sourcepackagename)';


COMMENT ON COLUMN pofile.unreviewed_count IS 'Number of POTMsgSets with new,
unreviewed TranslationMessages for this POFile.';


CREATE SEQUENCE pofile_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE pofile_id_seq OWNED BY pofile.id;


CREATE TABLE pofilestatsjob (
    job integer NOT NULL,
    pofile integer NOT NULL
);


CREATE TABLE pofiletranslator (
    id integer NOT NULL,
    person integer NOT NULL,
    pofile integer NOT NULL,
    latest_message integer NOT NULL,
    date_last_touched timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE pofiletranslator IS 'A materialized view caching who has translated what pofile.';


COMMENT ON COLUMN pofiletranslator.person IS 'The person who submitted the translation.';


COMMENT ON COLUMN pofiletranslator.pofile IS 'The pofile the translation was submitted for.';


COMMENT ON COLUMN pofiletranslator.latest_message IS 'Latest translation
message added to the translation file.';


COMMENT ON COLUMN pofiletranslator.date_last_touched IS 'When was added latest
translation message.';


CREATE SEQUENCE pofiletranslator_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE pofiletranslator_id_seq OWNED BY pofiletranslator.id;


CREATE TABLE poll (
    id integer NOT NULL,
    team integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    dateopens timestamp without time zone NOT NULL,
    datecloses timestamp without time zone NOT NULL,
    proposition text NOT NULL,
    type integer NOT NULL,
    allowspoilt boolean DEFAULT false NOT NULL,
    secrecy integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    CONSTRAINT sane_dates CHECK ((dateopens < datecloses))
);


COMMENT ON TABLE poll IS 'The polls belonging to teams.';


COMMENT ON COLUMN poll.team IS 'The team this poll belongs to';


COMMENT ON COLUMN poll.name IS 'The unique name of this poll.';


COMMENT ON COLUMN poll.title IS 'The title of this poll.';


COMMENT ON COLUMN poll.dateopens IS 'The date and time when this poll opens.';


COMMENT ON COLUMN poll.datecloses IS 'The date and time when this poll closes.';


COMMENT ON COLUMN poll.proposition IS 'The proposition that is going to be voted.';


COMMENT ON COLUMN poll.type IS 'The type of this poll (Simple, Preferential, etc).';


COMMENT ON COLUMN poll.allowspoilt IS 'If people can spoil their votes.';


COMMENT ON COLUMN poll.secrecy IS 'If people votes are SECRET (no one can see), ADMIN (team administrators can see) or PUBLIC (everyone can see).';


CREATE SEQUENCE poll_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE poll_id_seq OWNED BY poll.id;


CREATE TABLE polloption (
    id integer NOT NULL,
    poll integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    active boolean DEFAULT true NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE polloption IS 'The options belonging to polls.';


COMMENT ON COLUMN polloption.poll IS 'The poll this options belongs to.';


COMMENT ON COLUMN polloption.name IS 'The name of this option.';


COMMENT ON COLUMN polloption.title IS 'A short title for this option.';


COMMENT ON COLUMN polloption.active IS 'If TRUE, people will be able to vote on this option. Otherwise they don''t.';


CREATE SEQUENCE polloption_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE polloption_id_seq OWNED BY polloption.id;


CREATE TABLE pomsgid (
    id integer NOT NULL,
    msgid text NOT NULL
);


CREATE SEQUENCE pomsgid_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE pomsgid_id_seq OWNED BY pomsgid.id;


CREATE TABLE potemplate (
    id integer NOT NULL,
    priority integer DEFAULT 0 NOT NULL,
    description text,
    copyright text,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    path text NOT NULL,
    iscurrent boolean NOT NULL,
    messagecount integer NOT NULL,
    owner integer NOT NULL,
    sourcepackagename integer,
    distroseries integer,
    sourcepackageversion text,
    header text NOT NULL,
    binarypackagename integer,
    languagepack boolean DEFAULT false NOT NULL,
    productseries integer,
    from_sourcepackagename integer,
    date_last_updated timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    source_file integer,
    source_file_format integer DEFAULT 1 NOT NULL,
    name text NOT NULL,
    translation_domain text NOT NULL,
    CONSTRAINT potemplate_valid_name CHECK (valid_name(name)),
    CONSTRAINT valid_from_sourcepackagename CHECK (((sourcepackagename IS NOT NULL) OR (from_sourcepackagename IS NULL))),
    CONSTRAINT valid_link CHECK ((((productseries IS NULL) <> (distroseries IS NULL)) AND ((distroseries IS NULL) = (sourcepackagename IS NULL))))
);


COMMENT ON TABLE potemplate IS 'This table stores a pot file for a given product.';


COMMENT ON COLUMN potemplate.path IS 'The path to the .pot source file inside the tarball tree, including the filename.';


COMMENT ON COLUMN potemplate.sourcepackagename IS 'A reference to a sourcepackage name from where this POTemplate comes.';


COMMENT ON COLUMN potemplate.distroseries IS 'A reference to the distribution from where this POTemplate comes.';


COMMENT ON COLUMN potemplate.sourcepackageversion IS 'The sourcepackage version string from where this potemplate was imported last time with our buildd <-> Rosetta gateway.';


COMMENT ON COLUMN potemplate.header IS 'The header of a .pot file when we import it. Most important info from it is POT-Creation-Date and custom headers.';


COMMENT ON COLUMN potemplate.productseries IS 'A reference to a ProductSeries from where this POTemplate comes.';


COMMENT ON COLUMN potemplate.from_sourcepackagename IS 'The sourcepackagename from where the last .pot file came (only if it''s different from POTemplate.sourcepackagename)';


COMMENT ON COLUMN potemplate.source_file IS 'Reference to Librarian file storing the last uploaded template file.';


COMMENT ON COLUMN potemplate.source_file_format IS 'File format for the Librarian file referenced in "source_file" column.';


COMMENT ON COLUMN potemplate.name IS 'The name of the POTemplate set. It must be unique';


COMMENT ON COLUMN potemplate.translation_domain IS 'The translation domain for this POTemplate';


CREATE SEQUENCE potemplate_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE potemplate_id_seq OWNED BY potemplate.id;


CREATE TABLE potmsgset (
    id integer NOT NULL,
    msgid_singular integer NOT NULL,
    potemplate integer,
    commenttext text,
    filereferences text,
    sourcecomment text,
    flagscomment text,
    context text,
    msgid_plural integer
);


COMMENT ON TABLE potmsgset IS 'This table is stores a collection of msgids
without their translations and all kind of information associated to that set
of messages that could be found in a potemplate file.';


COMMENT ON COLUMN potmsgset.msgid_singular IS 'The singular msgid for this message.';


COMMENT ON COLUMN potmsgset.potemplate IS 'The potemplate where this message set is stored.';


COMMENT ON COLUMN potmsgset.commenttext IS 'The comment text that is associated to this message set.';


COMMENT ON COLUMN potmsgset.filereferences IS 'The list of files and their line number where this message set was extracted from.';


COMMENT ON COLUMN potmsgset.sourcecomment IS 'The comment that was extracted from the source code.';


COMMENT ON COLUMN potmsgset.flagscomment IS 'The flags associated with this set (like c-format).';


COMMENT ON COLUMN potmsgset.context IS 'Context uniquely defining a message when there are messages with same primemsgids.';


COMMENT ON COLUMN potmsgset.msgid_plural IS 'The plural msgid for this message.';


CREATE TABLE translationtemplateitem (
    id integer NOT NULL,
    potemplate integer NOT NULL,
    sequence integer NOT NULL,
    potmsgset integer NOT NULL,
    CONSTRAINT translationtemplateitem_sequence_check CHECK ((sequence >= 0))
);


CREATE VIEW potexport AS
    SELECT COALESCE((potmsgset.id)::text, 'X'::text) AS id, potemplate.productseries, potemplate.sourcepackagename, potemplate.distroseries, potemplate.id AS potemplate, potemplate.header AS template_header, potemplate.languagepack, translationtemplateitem.sequence, potmsgset.id AS potmsgset, potmsgset.commenttext AS comment, potmsgset.sourcecomment AS source_comment, potmsgset.filereferences AS file_references, potmsgset.flagscomment AS flags_comment, potmsgset.context, msgid_singular.msgid AS msgid_singular, msgid_plural.msgid AS msgid_plural FROM ((((potmsgset JOIN translationtemplateitem ON ((translationtemplateitem.potmsgset = potmsgset.id))) JOIN potemplate ON ((potemplate.id = translationtemplateitem.potemplate))) LEFT JOIN pomsgid msgid_singular ON ((potmsgset.msgid_singular = msgid_singular.id))) LEFT JOIN pomsgid msgid_plural ON ((potmsgset.msgid_plural = msgid_plural.id)));


CREATE SEQUENCE potmsgset_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE potmsgset_id_seq OWNED BY potmsgset.id;


CREATE TABLE potranslation (
    id integer NOT NULL,
    translation text NOT NULL
)
WITH (fillfactor=100);


CREATE SEQUENCE potranslation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE potranslation_id_seq OWNED BY potranslation.id;


CREATE TABLE previewdiff (
    id integer NOT NULL,
    source_revision_id text NOT NULL,
    target_revision_id text NOT NULL,
    dependent_revision_id text,
    diff integer NOT NULL,
    conflicts text
);


COMMENT ON TABLE previewdiff IS 'Contains information about preview diffs, without duplicating information with BranchMergeProposal.';


COMMENT ON COLUMN previewdiff.source_revision_id IS 'The source branch revision_id used to generate this diff.';


COMMENT ON COLUMN previewdiff.target_revision_id IS 'The target branch revision_id used to generate this diff.';


COMMENT ON COLUMN previewdiff.dependent_revision_id IS 'The dependant branch revision_id used to generate this diff.';


COMMENT ON COLUMN previewdiff.diff IS 'The last Diff generated for this PreviewDiff.';


COMMENT ON COLUMN previewdiff.conflicts IS 'The text description of any conflicts present.';


CREATE SEQUENCE previewdiff_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE previewdiff_id_seq OWNED BY previewdiff.id;


CREATE TABLE processor (
    id integer NOT NULL,
    family integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    description text NOT NULL
);


COMMENT ON TABLE processor IS 'A single processor for which code might be compiled. For example, i386, P2, P3, P4, Itanium1, Itanium2... each processor belongs to a ProcessorFamily, and it might be that a package is compiled several times for a given Family, with different optimisation settings for each processor.';


COMMENT ON COLUMN processor.family IS 'The ProcessorFamily for this Processor.';


COMMENT ON COLUMN processor.name IS 'The name of this processor, for example, i386, Pentium, P2, P3, P4, Itanium, Itanium2, K7, Athlon, Opteron... it should be short and unique.';


CREATE SEQUENCE processor_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE processor_id_seq OWNED BY processor.id;


CREATE TABLE processorfamily (
    id integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    description text NOT NULL,
    restricted boolean DEFAULT false NOT NULL
);


COMMENT ON TABLE processorfamily IS 'An architecture, that might consist of several actual processors. Different distributions call these architectures different things, so we have an "architecturetag" in DistroArchSeries that might be different to the architecture''s name.';


COMMENT ON COLUMN processorfamily.name IS 'The name of the architecture. This is a short unix-style name such as i386 or amd64';


COMMENT ON COLUMN processorfamily.title IS 'A title for the architecture. For example "Intel i386 Compatible".';


COMMENT ON COLUMN processorfamily.description IS 'A description for this processor family. It might include any gotchas such as the fact that i386 does not necessarily mean that code would run on a 386... Ubuntu for example requires a 486.';


CREATE SEQUENCE processorfamily_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE processorfamily_id_seq OWNED BY processorfamily.id;


CREATE TABLE product (
    id integer NOT NULL,
    project integer,
    owner integer NOT NULL,
    name text NOT NULL,
    displayname text NOT NULL,
    title text NOT NULL,
    summary text NOT NULL,
    description text,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    homepageurl text,
    screenshotsurl text,
    wikiurl text,
    listurl text,
    programminglang text,
    downloadurl text,
    lastdoap text,
    sourceforgeproject text,
    freshmeatproject text,
    reviewed boolean DEFAULT false NOT NULL,
    active boolean DEFAULT true NOT NULL,
    fti ts2.tsvector,
    autoupdate boolean DEFAULT false NOT NULL,
    translationgroup integer,
    translationpermission integer DEFAULT 1 NOT NULL,
    official_rosetta boolean DEFAULT false NOT NULL,
    official_malone boolean DEFAULT false NOT NULL,
    bug_supervisor integer,
    security_contact integer,
    driver integer,
    bugtracker integer,
    development_focus integer,
    homepage_content text,
    icon integer,
    mugshot integer,
    logo integer,
    official_answers boolean DEFAULT false NOT NULL,
    private_bugs boolean DEFAULT false NOT NULL,
    private_specs boolean DEFAULT false NOT NULL,
    license_info text,
    official_blueprints boolean DEFAULT false NOT NULL,
    enable_bug_expiration boolean DEFAULT false NOT NULL,
    bug_reporting_guidelines text,
    reviewer_whiteboard text,
    license_approved boolean DEFAULT false NOT NULL,
    registrant integer NOT NULL,
    remote_product text,
    translation_focus integer,
    max_bug_heat integer,
    date_next_suggest_packaging timestamp without time zone,
    bug_reported_acknowledgement text,
    answers_usage integer DEFAULT 10 NOT NULL,
    blueprints_usage integer DEFAULT 10 NOT NULL,
    translations_usage integer DEFAULT 10 NOT NULL,
    enable_bugfiling_duplicate_search boolean DEFAULT true NOT NULL,
    CONSTRAINT only_launchpad_has_expiration CHECK (((enable_bug_expiration IS FALSE) OR (official_malone IS TRUE))),
    CONSTRAINT private_bugs_need_contact CHECK (((private_bugs IS FALSE) OR (bug_supervisor IS NOT NULL))),
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE product IS 'Product: a DOAP Product. This table stores core information about an open source product. In Launchpad, anything that can be shipped as a tarball would be a product, and in some cases there might be products for things that never actually ship, depending on the project. For example, most projects will have a ''website'' product, because that allows you to file a Malone bug against the project website. Note that these are not actual product releases, which are stored in the ProductRelease table.';


COMMENT ON COLUMN product.project IS 'Every Product belongs to one and only one Project, which is referenced in this column.';


COMMENT ON COLUMN product.owner IS 'The Product owner would typically be the person who created this product in Launchpad. But we will encourage the upstream maintainer of a product to become the owner in Launchpad. The Product owner can edit any aspect of the Product, as well as appointing people to specific roles with regard to the Product. Also, the owner can add a new ProductRelease and also edit Rosetta POTemplates associated with this product.';


COMMENT ON COLUMN product.summary IS 'A brief summary of the product. This will be displayed in bold at the top of the product page, above the description.';


COMMENT ON COLUMN product.description IS 'A detailed description of the product, highlighting primary features of the product that may be of interest to end-users. The description may also include links and other references to useful information on the web about this product. The description will be displayed on the product page, below the product summary.';


COMMENT ON COLUMN product.listurl IS 'This is the URL where information about a mailing list for this Product can be found. The URL might point at a web archive or at the page where one can subscribe to the mailing list.';


COMMENT ON COLUMN product.programminglang IS 'This field records, in plain text, the name of any significant programming languages used in this product. There are no rules, conventions or restrictions on this field at present, other than basic sanity. Examples might be "Python", "Python, C" and "Java".';


COMMENT ON COLUMN product.downloadurl IS 'The download URL for a Product should be the best place to download that product, typically off the relevant Project web site. This should not point at the actual file, but at a web page with download information.';


COMMENT ON COLUMN product.lastdoap IS 'This column stores a cached copy of the last DOAP description we saw for this product. See the Project.lastdoap field for more info.';


COMMENT ON COLUMN product.sourceforgeproject IS 'The SourceForge project name for this product. This is not unique as SourceForge doesn''t use the same project/product structure as DOAP.';


COMMENT ON COLUMN product.freshmeatproject IS 'The FreshMeat project name for this product. This is not unique as FreshMeat does not have the same project/product structure as DOAP';


COMMENT ON COLUMN product.reviewed IS 'Whether or not someone at Canonical has reviewed this product.';


COMMENT ON COLUMN product.active IS 'Whether or not this product should be considered active.';


COMMENT ON COLUMN product.translationgroup IS 'The TranslationGroup that is responsible for translations for this product. Note that the Product may be part of a Project which also has a TranslationGroup, in which case the translators from both the product and project translation group have permission to edit the translations of this product.';


COMMENT ON COLUMN product.translationpermission IS 'The level of openness of this product''s translation process. The enum lists different approaches to translation, from the very open (anybody can edit any translation in any language) to the completely closed (only designated translators can make any changes at all).';


COMMENT ON COLUMN product.official_rosetta IS 'Whether or not this product upstream uses Rosetta for its official translation team and coordination. This is a useful indicator in terms of whether translations in Rosetta for this upstream will quickly move upstream.';


COMMENT ON COLUMN product.official_malone IS 'Whether or not this product upstream uses Malone for an official bug tracker. This is useful to help indicate whether or not people are likely to pick up on bugs registered in Malone.';


COMMENT ON COLUMN product.bug_supervisor IS 'Person who is responsible for managing bugs on this product.';


COMMENT ON COLUMN product.security_contact IS 'The person or team who handles security-related issues in the product.';


COMMENT ON COLUMN product.driver IS 'This is a driver for the overall product. This driver will be able to approve nominations of bugs and specs to any series in the product, including backporting to old stable series. You want the smallest group of "overall drivers" here, because you can add specific drivers to each series individually.';


COMMENT ON COLUMN product.development_focus IS 'The product series that is the current focus of development.';


COMMENT ON COLUMN product.homepage_content IS 'A home page for this product in the Launchpad.';


COMMENT ON COLUMN product.icon IS 'The library file alias to a small image to be used as an icon whenever we are referring to a product.';


COMMENT ON COLUMN product.mugshot IS 'The library file alias of a mugshot image to display as the branding of a product, on its home page.';


COMMENT ON COLUMN product.logo IS 'The library file alias of a smaller version of this product''s mugshot.';


COMMENT ON COLUMN product.official_answers IS 'Whether or not this product upstream uses Answers officialy. This is useful to help indicate whether or not that a question will receive an answer.';


COMMENT ON COLUMN product.private_bugs IS 'Indicates whether bugs filed in this product are automatically marked as private.';


COMMENT ON COLUMN product.private_specs IS 'Indicates whether specs filed in this product are automatically marked as private.';


COMMENT ON COLUMN product.license_info IS 'Additional information about licenses that are not included in the License enumeration.';


COMMENT ON COLUMN product.official_blueprints IS 'Whether or not this product upstream uses Blueprints officially. This is useful to help indicate whether or not the upstream project will be actively watching the blueprints in Launchpad.';


COMMENT ON COLUMN product.enable_bug_expiration IS 'Indicates whether automatic bug expiration is enabled.';


COMMENT ON COLUMN product.bug_reporting_guidelines IS 'Guidelines to the end user for reporting bugs on this product.';


COMMENT ON COLUMN product.reviewer_whiteboard IS 'A whiteboard for Launchpad admins, registry experts and the project owners to capture the state of current issues with the project.';


COMMENT ON COLUMN product.license_approved IS 'The Other/Open Source license has been approved by an administrator.';


COMMENT ON COLUMN product.registrant IS 'The Product registrant is the Person who created the product in Launchpad.  It is set at creation and is never changed thereafter.';


COMMENT ON COLUMN product.remote_product IS 'The ID of this product on its remote bug tracker.';


COMMENT ON COLUMN product.translation_focus IS 'The ProductSeries that should get the translation effort focus.';


COMMENT ON COLUMN product.max_bug_heat IS 'The highest heat value across bugs for this product.';


COMMENT ON COLUMN product.date_next_suggest_packaging IS 'The date when Launchpad can resume suggesting Ubuntu packages that the project provides.';


COMMENT ON COLUMN product.bug_reported_acknowledgement IS 'A message of acknowledgement to display to a bug reporter after they''ve reported a new bug.';


COMMENT ON COLUMN product.enable_bugfiling_duplicate_search IS 'Enable/disable a search for posiible duplicates when a bug is filed.';


CREATE SEQUENCE product_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE product_id_seq OWNED BY product.id;


CREATE TABLE productlicense (
    id integer NOT NULL,
    product integer NOT NULL,
    license integer NOT NULL
);


COMMENT ON TABLE productlicense IS 'The licenses that cover the software for a product.';


COMMENT ON COLUMN productlicense.product IS 'Foreign key to the product that has licenses associated with it.';


COMMENT ON COLUMN productlicense.license IS 'An integer referencing a value in the License enumeration in product.py';


CREATE SEQUENCE productlicense_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE productlicense_id_seq OWNED BY productlicense.id;


CREATE TABLE productrelease (
    id integer NOT NULL,
    datereleased timestamp without time zone NOT NULL,
    release_notes text,
    changelog text,
    owner integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    milestone integer NOT NULL
);


COMMENT ON TABLE productrelease IS 'A Product Release. This is table stores information about a specific ''upstream'' software release, like Apache 2.0.49 or Evolution 1.5.4.';


COMMENT ON COLUMN productrelease.datereleased IS 'The date when this version of the product was released.';


COMMENT ON COLUMN productrelease.release_notes IS 'Description of changes in this product release.';


COMMENT ON COLUMN productrelease.changelog IS 'Detailed description of changes in this product release.';


COMMENT ON COLUMN productrelease.owner IS 'The person who created this product release.';


COMMENT ON COLUMN productrelease.datecreated IS 'The timestamp when this product release was created.';


COMMENT ON COLUMN productrelease.milestone IS 'The milestone for this product release. This is scheduled to become a NOT NULL column, so every product release will be linked to a unique milestone.';


CREATE SEQUENCE productrelease_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE productrelease_id_seq OWNED BY productrelease.id;


CREATE TABLE productreleasefile (
    productrelease integer NOT NULL,
    libraryfile integer NOT NULL,
    filetype integer NOT NULL,
    id integer DEFAULT nextval(('productreleasefile_id_seq'::text)::regclass) NOT NULL,
    description text,
    uploader integer NOT NULL,
    date_uploaded timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    fti ts2.tsvector,
    signature integer
);


COMMENT ON TABLE productreleasefile IS 'Links a ProductRelease to one or more files in the Librarian.';


COMMENT ON COLUMN productreleasefile.productrelease IS 'This is the product release this file is associated with';


COMMENT ON COLUMN productreleasefile.libraryfile IS 'This is the librarian entry';


COMMENT ON COLUMN productreleasefile.filetype IS 'An enum of what kind of file this is. Code tarballs are marked for special treatment (importing into bzr)';


COMMENT ON COLUMN productreleasefile.description IS 'A description of what the file contains';


COMMENT ON COLUMN productreleasefile.uploader IS 'The person who uploaded this file.';


COMMENT ON COLUMN productreleasefile.date_uploaded IS 'The date this file was uploaded.';


COMMENT ON COLUMN productreleasefile.signature IS 'This is the signature of the librarian entry as uploaded by the user.';


CREATE SEQUENCE productreleasefile_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE productreleasefile_id_seq OWNED BY productreleasefile.id;


CREATE TABLE productseries (
    id integer NOT NULL,
    product integer NOT NULL,
    name text NOT NULL,
    summary text NOT NULL,
    releasefileglob text,
    releaseverstyle integer,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    driver integer,
    owner integer NOT NULL,
    status integer DEFAULT 2 NOT NULL,
    translations_autoimport_mode integer DEFAULT 1 NOT NULL,
    branch integer,
    translations_branch integer,
    CONSTRAINT valid_name CHECK (valid_name(name)),
    CONSTRAINT valid_releasefileglob CHECK (valid_absolute_url(releasefileglob))
);


COMMENT ON TABLE productseries IS 'A ProductSeries is a set of product releases that are related to a specific version of the product. Typically, each major release of the product starts a new ProductSeries. These often map to a branch in the revision control system of the project, such as "2_0_STABLE". A few conventional Series names are "head" for releases of the HEAD branch, "1.0" for releases with version numbers like "1.0.0" and "1.0.1".  Each product has at least one ProductSeries';


COMMENT ON COLUMN productseries.name IS 'The name of the ProductSeries is like a unix name, it should not contain any spaces and should start with a letter or number. Good examples are "2.0", "3.0", "head" and "development".';


COMMENT ON COLUMN productseries.summary IS 'A summary of this Product Series. A good example would include the date the series was initiated and whether this is the current recommended series for people to use. The summary is usually displayed at the top of the page, in bold, just beneath the title and above the description, if there is a description field.';


COMMENT ON COLUMN productseries.releasefileglob IS 'A fileglob that lets us
see which URLs are potentially new upstream tarball releases. For example:
http://ftp.gnu.org/gnu/libtool/libtool-1.5.*.gz.';


COMMENT ON COLUMN productseries.releaseverstyle IS 'An enum giving the style
of this product series release version numbering system.  The options are
documented in dbschema.UpstreamReleaseVersionStyle.  Most applications use
Gnu style numbering, but there are other alternatives.';


COMMENT ON COLUMN productseries.driver IS 'This is a person or team who can approve spes and bugs for implementation or fixing in this specific series. Note that the product drivers and project drivers can also do this for any series in the product or project, so use this only for the specific team responsible for this specific series.';


COMMENT ON COLUMN productseries.status IS 'The current status of this productseries.';


COMMENT ON COLUMN productseries.translations_autoimport_mode IS 'Level of
translations imports from codehosting branch: None, templates only, templates
and translations. See TranslationsBranchImportMode.';


COMMENT ON COLUMN productseries.branch IS 'The branch for this product
series.';


COMMENT ON COLUMN productseries.translations_branch IS 'Branch to push translations updates to.';


CREATE SEQUENCE productseries_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE productseries_id_seq OWNED BY productseries.id;


CREATE TABLE project (
    id integer NOT NULL,
    owner integer NOT NULL,
    name text NOT NULL,
    displayname text NOT NULL,
    title text NOT NULL,
    summary text NOT NULL,
    description text NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    homepageurl text,
    wikiurl text,
    lastdoap text,
    sourceforgeproject text,
    freshmeatproject text,
    reviewed boolean DEFAULT false NOT NULL,
    active boolean DEFAULT true NOT NULL,
    fti ts2.tsvector,
    translationgroup integer,
    translationpermission integer DEFAULT 1 NOT NULL,
    driver integer,
    bugtracker integer,
    homepage_content text,
    icon integer,
    mugshot integer,
    logo integer,
    bug_reporting_guidelines text,
    reviewer_whiteboard text,
    registrant integer NOT NULL,
    max_bug_heat integer,
    bug_reported_acknowledgement text,
    CONSTRAINT valid_name CHECK (valid_name(name))
);


COMMENT ON TABLE project IS 'Project: A DOAP Project. This table is the core of the DOAP section of the Launchpad database. It contains details of a single open source Project and is the anchor point for products, potemplates, and translationefforts.';


COMMENT ON COLUMN project.owner IS 'The owner of the project will initially be the person who creates this Project in the system. We will encourage upstream project leaders to take on this role. The Project owner is able to edit the project.';


COMMENT ON COLUMN project.name IS 'A short lowercase name uniquely identifying the product. Use cases include being used as a key in URL traversal.';


COMMENT ON COLUMN project.summary IS 'A brief summary of this project. This
will be displayed in bold text just above the description and below the
title. It should be a single paragraph of not more than 80 words.';


COMMENT ON COLUMN project.description IS 'A detailed description of this
project. This should primarily be focused on the organisational aspects of
the project, such as the people involved and the structures that the project
uses to govern itself. It might refer to the primary products of the project
but the detailed descriptions of those products should be in the
Product.description field, not here. So, for example, useful information
such as the dates the project was started and the way the project
coordinates itself are suitable here.';


COMMENT ON COLUMN project.homepageurl IS 'The home page URL of this project. Note that this could well be the home page of the main product of this project as well, if the project is too small to have a separate home page for project and product.';


COMMENT ON COLUMN project.wikiurl IS 'This is the URL of a wiki that includes information about the project. It might be a page in a bigger wiki, or it might be the top page of a wiki devoted to this project.';


COMMENT ON COLUMN project.lastdoap IS 'This column stores a cached copy of the last DOAP description we saw for this project. We cache the last DOAP fragment for this project because there may be some aspects of it which we are unable to represent in the database (such as multiple homepageurl''s instead of just a single homepageurl) and storing the DOAP file allows us to re-parse it later and recover this information when our database model has been updated appropriately.';


COMMENT ON COLUMN project.sourceforgeproject IS 'The SourceForge project name for this project. This is not unique as SourceForge doesn''t use the same project/product structure as DOAP.';


COMMENT ON COLUMN project.freshmeatproject IS 'The FreshMeat project name for this project. This is not unique as FreshMeat does not have the same project/product structure as DOAP';


COMMENT ON COLUMN project.reviewed IS 'Whether or not someone at Canonical has reviewed this project.';


COMMENT ON COLUMN project.active IS 'Whether or not this project should be considered active.';


COMMENT ON COLUMN project.translationgroup IS 'The translation group that has permission to edit translations across all products in this project. Note that individual products may have their own translationgroup, in which case those translators will also have permission to edit translations for that product.';


COMMENT ON COLUMN project.translationpermission IS 'The level of openness of
this project''s translation process. The enum lists different approaches to
translation, from the very open (anybody can edit any translation in any
language) to the completely closed (only designated translators can make any
changes at all).';


COMMENT ON COLUMN project.driver IS 'This person or team has the ability to approve specs as goals for any series in any product in the project. Similarly, this person or team can approve bugs as targets for fixing in any series, or backporting of fixes to any series.';


COMMENT ON COLUMN project.homepage_content IS 'A home page for this project in the Launchpad.';


COMMENT ON COLUMN project.icon IS 'The library file alias to a small image to be used as an icon whenever we are referring to a project.';


COMMENT ON COLUMN project.mugshot IS 'The library file alias of a mugshot image to display as the branding of a project, on its home page.';


COMMENT ON COLUMN project.logo IS 'The library file alias of a smaller version of this product''s mugshot.';


COMMENT ON COLUMN project.bug_reporting_guidelines IS 'Guidelines to the end user for reporting bugs on products in this project.';


COMMENT ON COLUMN project.reviewer_whiteboard IS 'A whiteboard for Launchpad admins, registry experts and the project owners to capture the state of current issues with the project.';


COMMENT ON COLUMN project.registrant IS 'The registrant is the Person who created the project in Launchpad.  It is set at creation and is never changed thereafter.';


COMMENT ON COLUMN project.max_bug_heat IS 'The highest heat value across bugs for products in this project.';


COMMENT ON COLUMN project.bug_reported_acknowledgement IS 'A message of acknowledgement to display to a bug reporter after they''ve reported a new bug.';


CREATE SEQUENCE project_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE project_id_seq OWNED BY project.id;


CREATE TABLE publisherconfig (
    id integer NOT NULL,
    distribution integer NOT NULL,
    root_dir text NOT NULL,
    base_url text NOT NULL,
    copy_base_url text NOT NULL
);


CREATE SEQUENCE publisherconfig_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE publisherconfig_id_seq OWNED BY publisherconfig.id;


CREATE TABLE question (
    id integer NOT NULL,
    owner integer NOT NULL,
    title text NOT NULL,
    description text NOT NULL,
    assignee integer,
    answerer integer,
    product integer,
    distribution integer,
    sourcepackagename integer,
    status integer NOT NULL,
    priority integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    datelastquery timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    dateaccepted timestamp without time zone,
    datedue timestamp without time zone,
    datelastresponse timestamp without time zone,
    date_solved timestamp without time zone,
    dateclosed timestamp without time zone,
    whiteboard text,
    fti ts2.tsvector,
    answer integer,
    language integer NOT NULL,
    faq integer,
    CONSTRAINT product_or_distro CHECK (((product IS NULL) <> (distribution IS NULL))),
    CONSTRAINT sourcepackagename_needs_distro CHECK (((sourcepackagename IS NULL) OR (distribution IS NOT NULL)))
);


COMMENT ON TABLE question IS 'A question, or support request, for a distribution or for an application. Such questions are created by end users who need support on a particular feature or package or product.';


COMMENT ON COLUMN question.assignee IS 'The person who has been assigned to resolve this question. Note that there is no requirement that every question be assigned somebody. Anybody can chip in to help resolve a question, and if they think they have done so we call them the "answerer".';


COMMENT ON COLUMN question.answerer IS 'The person who last claimed to have "solved" this support question, giving a response that the owner believe should be sufficient to close the question. This will move the status of the question to "SOLVED". Note that the only person who can actually set the status to SOLVED is the person who asked the question.';


COMMENT ON COLUMN question.product IS 'The upstream product to which this quesiton is related. Note that a quesiton MUST be linked either to a product, or to a distribution.';


COMMENT ON COLUMN question.distribution IS 'The distribution for which a question was filed. Note that a request MUST be linked either to a product or a distribution.';


COMMENT ON COLUMN question.sourcepackagename IS 'An optional source package name. This only makes sense if the question is bound to a distribution.';


COMMENT ON COLUMN question.datelastquery IS 'The date we last saw a comment from the requester (owner).';


COMMENT ON COLUMN question.dateaccepted IS 'The date we "confirmed" or "accepted" this question. It is usually set to the date of the first response by someone other than the requester. This allows us to track the time between first request and first response.';


COMMENT ON COLUMN question.datedue IS 'The date this question is "due", if such a date can be established. Usually this will be set automatically on the basis of a support contract SLA commitment.';


COMMENT ON COLUMN question.datelastresponse IS 'The date we last saw a comment from somebody other than the requester.';


COMMENT ON COLUMN question.date_solved IS 'The date this question was last marked as solved by the requester (owner). The requester either found a solution, or accepted an answer from another user.';


COMMENT ON COLUMN question.dateclosed IS 'The date the requester marked this question CLOSED.';


COMMENT ON COLUMN question.whiteboard IS 'A general status whiteboard. This is a scratch space to which arbitrary data can be added (there is only one constant whiteboard with no history). It is displayed at the top of the question. So its a useful way for projects to add their own semantics or metadata to the Answer Tracker.';


COMMENT ON COLUMN question.answer IS 'The QuestionMessage that was accepted by the submitter as the "answer" to the question';


COMMENT ON COLUMN question.language IS 'The language of the question''s title and description.';


COMMENT ON COLUMN question.faq IS 'The FAQ document that contains the long answer to this question.';


CREATE SEQUENCE question_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE question_id_seq OWNED BY question.id;


CREATE TABLE questionbug (
    id integer NOT NULL,
    question integer NOT NULL,
    bug integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE questionbug IS 'A link between a question and a bug, showing that the bug is somehow related to this question.';


CREATE SEQUENCE questionbug_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE questionbug_id_seq OWNED BY questionbug.id;


CREATE TABLE questionjob (
    id integer NOT NULL,
    job integer NOT NULL,
    job_type integer NOT NULL,
    question integer NOT NULL,
    json_data text
);


COMMENT ON TABLE questionjob IS 'Contains references to jobs regarding questions.';


COMMENT ON COLUMN questionjob.job IS 'A reference to a row in the Job table that has all the common job details.';


COMMENT ON COLUMN questionjob.job_type IS 'The type of job, such as new-answer-notification.';


COMMENT ON COLUMN questionjob.question IS 'The newly added question message.';


COMMENT ON COLUMN questionjob.json_data IS 'Data that is specific to the type of job, normally stores text to append to email notifications.';


CREATE SEQUENCE questionjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE questionjob_id_seq OWNED BY questionjob.id;


CREATE TABLE questionmessage (
    id integer NOT NULL,
    question integer NOT NULL,
    message integer NOT NULL,
    action integer NOT NULL,
    new_status integer NOT NULL,
    owner integer NOT NULL
);


COMMENT ON TABLE questionmessage IS 'A link between a question and a message. This means that the message will be displayed on the question page.';


COMMENT ON COLUMN questionmessage.action IS 'The action on the question that was done with this message. This is a value from the QuestionAction enum.';


COMMENT ON COLUMN questionmessage.new_status IS 'The status of the question after this message.';


CREATE SEQUENCE questionmessage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE questionmessage_id_seq OWNED BY questionmessage.id;


CREATE TABLE questionreopening (
    id integer NOT NULL,
    question integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    reopener integer NOT NULL,
    answerer integer,
    date_solved timestamp without time zone,
    priorstate integer NOT NULL
);


COMMENT ON TABLE questionreopening IS 'A record of the times when a question was re-opened. In each case we store the time that it happened, the person who did it, and the person who had previously answered / rejected the question.';


COMMENT ON COLUMN questionreopening.reopener IS 'The person who reopened the question.';


COMMENT ON COLUMN questionreopening.answerer IS 'The person who was previously listed as the answerer of the question.';


COMMENT ON COLUMN questionreopening.priorstate IS 'The state of the question before it was reopened. You can reopen a question that is ANSWERED, or CLOSED, or REJECTED.';


CREATE SEQUENCE questionreopening_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE questionreopening_id_seq OWNED BY questionreopening.id;


CREATE TABLE questionsubscription (
    id integer NOT NULL,
    question integer NOT NULL,
    person integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE questionsubscription IS 'A subscription of a person to a particular question.';


CREATE SEQUENCE questionsubscription_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE questionsubscription_id_seq OWNED BY questionsubscription.id;


CREATE TABLE revision (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    log_body text NOT NULL,
    revision_author integer NOT NULL,
    gpgkey integer,
    revision_id text NOT NULL,
    revision_date timestamp without time zone,
    karma_allocated boolean DEFAULT false
);
ALTER TABLE ONLY revision ALTER COLUMN revision_author SET STATISTICS 500;
ALTER TABLE ONLY revision ALTER COLUMN revision_date SET STATISTICS 500;


CREATE SEQUENCE revision_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE revision_id_seq OWNED BY revision.id;


CREATE TABLE revisionauthor (
    id integer NOT NULL,
    name text NOT NULL,
    email text,
    person integer
);


COMMENT ON TABLE revisionauthor IS 'All distinct authors for revisions.';


COMMENT ON COLUMN revisionauthor.name IS 'The exact text extracted from the branch revision.';


COMMENT ON COLUMN revisionauthor.email IS 'A valid email address extracted from the name.  This email address may or may not be associated with a Launchpad user at this stage.';


COMMENT ON COLUMN revisionauthor.person IS 'The Launchpad person that has a verified email address that matches the email address of the revision author.';


CREATE SEQUENCE revisionauthor_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE revisionauthor_id_seq OWNED BY revisionauthor.id;


CREATE TABLE revisioncache (
    id integer NOT NULL,
    revision integer NOT NULL,
    revision_author integer NOT NULL,
    revision_date timestamp without time zone NOT NULL,
    product integer,
    distroseries integer,
    sourcepackagename integer,
    private boolean NOT NULL,
    CONSTRAINT valid_target CHECK ((((distroseries IS NULL) = (sourcepackagename IS NULL)) AND (((distroseries IS NULL) AND (product IS NULL)) OR ((distroseries IS NULL) <> (product IS NULL)))))
);


COMMENT ON TABLE revisioncache IS 'A cache of revisions where the revision date is in the last 30 days.';


COMMENT ON COLUMN revisioncache.revision IS 'A reference to the actual revision.';


COMMENT ON COLUMN revisioncache.revision_author IS 'A refernce to the revision author for the revision.';


COMMENT ON COLUMN revisioncache.revision_date IS 'The date the revision was made.  Should be within 30 days of today (or the cleanup code is not cleaning up).';


COMMENT ON COLUMN revisioncache.product IS 'The product that the revision is found in (if it is indeed in a particular product).';


COMMENT ON COLUMN revisioncache.distroseries IS 'The distroseries for which a source package branch contains the revision.';


COMMENT ON COLUMN revisioncache.sourcepackagename IS 'The sourcepackagename for which a source package branch contains the revision.';


COMMENT ON COLUMN revisioncache.private IS 'True if the revision is only found in private branches, False if it can be found in a non-private branch.';


CREATE SEQUENCE revisioncache_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE revisioncache_id_seq OWNED BY revisioncache.id;


CREATE TABLE revisionparent (
    id integer NOT NULL,
    sequence integer NOT NULL,
    revision integer NOT NULL,
    parent_id text NOT NULL
);


CREATE SEQUENCE revisionparent_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE revisionparent_id_seq OWNED BY revisionparent.id;


CREATE TABLE revisionproperty (
    id integer NOT NULL,
    revision integer NOT NULL,
    name text NOT NULL,
    value text NOT NULL
);


COMMENT ON TABLE revisionproperty IS 'A collection of name and value pairs that appear on a revision.';


COMMENT ON COLUMN revisionproperty.revision IS 'The revision which has properties.';


COMMENT ON COLUMN revisionproperty.name IS 'The name of the property.';


COMMENT ON COLUMN revisionproperty.value IS 'The value of the property.';


CREATE SEQUENCE revisionproperty_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE revisionproperty_id_seq OWNED BY revisionproperty.id;


CREATE TABLE scriptactivity (
    id integer NOT NULL,
    name text NOT NULL,
    hostname text NOT NULL,
    date_started timestamp without time zone NOT NULL,
    date_completed timestamp without time zone NOT NULL
);


COMMENT ON TABLE scriptactivity IS 'Records of successful runs of scripts ';


COMMENT ON COLUMN scriptactivity.name IS 'The name of the script';


COMMENT ON COLUMN scriptactivity.hostname IS 'The hostname of the machine where the script was run';


COMMENT ON COLUMN scriptactivity.date_started IS 'The date at which the script started';


COMMENT ON COLUMN scriptactivity.date_completed IS 'The date at which the script completed';


CREATE SEQUENCE scriptactivity_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE scriptactivity_id_seq OWNED BY scriptactivity.id;


CREATE TABLE section (
    id integer NOT NULL,
    name text NOT NULL
);


COMMENT ON TABLE section IS 'Known sections in Launchpad';


COMMENT ON COLUMN section.name IS 'Section name text';


CREATE SEQUENCE section_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE section_id_seq OWNED BY section.id;


CREATE TABLE sectionselection (
    id integer NOT NULL,
    distroseries integer NOT NULL,
    section integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE sectionselection IS 'Allowed sections in a given distroseries.';


COMMENT ON COLUMN sectionselection.distroseries IS 'Refers to the distroseries in question.';


COMMENT ON COLUMN sectionselection.section IS 'Refers to the section in question.';


CREATE SEQUENCE sectionselection_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sectionselection_id_seq OWNED BY sectionselection.id;


CREATE TABLE seriessourcepackagebranch (
    id integer NOT NULL,
    distroseries integer NOT NULL,
    pocket integer NOT NULL,
    sourcepackagename integer NOT NULL,
    branch integer NOT NULL,
    registrant integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE seriessourcepackagebranch IS 'Link between branches and distribution suite.';


COMMENT ON COLUMN seriessourcepackagebranch.distroseries IS 'The distroseries the branch is linked to.';


COMMENT ON COLUMN seriessourcepackagebranch.pocket IS 'The pocket the branch is linked to.';


COMMENT ON COLUMN seriessourcepackagebranch.sourcepackagename IS 'The sourcepackagename the branch is linked to.';


COMMENT ON COLUMN seriessourcepackagebranch.branch IS 'The branch being linked to a distribution suite.';


COMMENT ON COLUMN seriessourcepackagebranch.registrant IS 'The person who registered this link.';


COMMENT ON COLUMN seriessourcepackagebranch.date_created IS 'The date this link was created.';


CREATE SEQUENCE seriessourcepackagebranch_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE seriessourcepackagebranch_id_seq OWNED BY seriessourcepackagebranch.id;


CREATE TABLE signedcodeofconduct (
    id integer NOT NULL,
    owner integer NOT NULL,
    signingkey integer,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    signedcode text,
    recipient integer,
    active boolean DEFAULT false NOT NULL,
    admincomment text
);


CREATE SEQUENCE signedcodeofconduct_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE signedcodeofconduct_id_seq OWNED BY signedcodeofconduct.id;


CREATE TABLE sourcepackagepublishinghistory (
    id integer NOT NULL,
    sourcepackagerelease integer NOT NULL,
    distroseries integer NOT NULL,
    status integer NOT NULL,
    component integer NOT NULL,
    section integer NOT NULL,
    datecreated timestamp without time zone NOT NULL,
    datepublished timestamp without time zone,
    datesuperseded timestamp without time zone,
    supersededby integer,
    datemadepending timestamp without time zone,
    scheduleddeletiondate timestamp without time zone,
    dateremoved timestamp without time zone,
    pocket integer DEFAULT 0 NOT NULL,
    archive integer NOT NULL,
    removed_by integer,
    removal_comment text,
    ancestor integer,
    sourcepackagename integer,
    creator integer
);


COMMENT ON TABLE sourcepackagepublishinghistory IS 'SourcePackagePublishingHistory: The history of a SourcePackagePublishing record. This table represents the lifetime of a publishing record from inception to deletion. Records are never removed from here and in time the publishing table may become a view onto this table. A column being NULL indicates there''s no data for that state transition. E.g. a package which is removed without being superseded won''t have datesuperseded or supersededby filled in.';


COMMENT ON COLUMN sourcepackagepublishinghistory.sourcepackagerelease IS 'The sourcepackagerelease being published.';


COMMENT ON COLUMN sourcepackagepublishinghistory.distroseries IS 'The distroseries into which the sourcepackagerelease is being published.';


COMMENT ON COLUMN sourcepackagepublishinghistory.status IS 'The current status of the publishing.';


COMMENT ON COLUMN sourcepackagepublishinghistory.component IS 'The component into which the publishing takes place.';


COMMENT ON COLUMN sourcepackagepublishinghistory.section IS 'The section into which the publishing takes place.';


COMMENT ON COLUMN sourcepackagepublishinghistory.datecreated IS 'The date/time on which the publishing record was created.';


COMMENT ON COLUMN sourcepackagepublishinghistory.datepublished IS 'The date/time on which the source was actually published into an archive.';


COMMENT ON COLUMN sourcepackagepublishinghistory.datesuperseded IS 'The date/time on which the source was superseded by a new source.';


COMMENT ON COLUMN sourcepackagepublishinghistory.supersededby IS 'The source which superseded this one.';


COMMENT ON COLUMN sourcepackagepublishinghistory.datemadepending IS 'The date/time on which this publishing record was made to be pending removal from the archive.';


COMMENT ON COLUMN sourcepackagepublishinghistory.scheduleddeletiondate IS 'The date/time at which the source is/was scheduled to be deleted.';


COMMENT ON COLUMN sourcepackagepublishinghistory.dateremoved IS 'The date/time at which the source was actually deleted.';


COMMENT ON COLUMN sourcepackagepublishinghistory.pocket IS 'The pocket into which this record is published. The RELEASE pocket (zero) provides behaviour as normal. Other pockets may append things to the distroseries name such as the UPDATES pocket (-updates), the SECURITY pocket (-security) and the PROPOSED pocket (-proposed)';


COMMENT ON COLUMN sourcepackagepublishinghistory.archive IS 'The target archive for thi publishing record.';


COMMENT ON COLUMN sourcepackagepublishinghistory.removed_by IS 'Person responsible for the removal.';


COMMENT ON COLUMN sourcepackagepublishinghistory.removal_comment IS 'Reason why the publication was removed.';


CREATE TABLE sourcepackagereleasefile (
    sourcepackagerelease integer NOT NULL,
    libraryfile integer NOT NULL,
    filetype integer NOT NULL,
    id integer DEFAULT nextval(('sourcepackagereleasefile_id_seq'::text)::regclass) NOT NULL
);


COMMENT ON TABLE sourcepackagereleasefile IS 'SourcePackageReleaseFile: A soyuz source package release file. This table links sourcepackagereleasehistory records to the files which comprise the input.';


COMMENT ON COLUMN sourcepackagereleasefile.sourcepackagerelease IS 'The sourcepackagerelease that this file belongs to';


COMMENT ON COLUMN sourcepackagereleasefile.libraryfile IS 'The libraryfilealias embodying this file';


COMMENT ON COLUMN sourcepackagereleasefile.filetype IS 'The type of the file. E.g. TAR, DIFF, DSC';


CREATE VIEW sourcepackagefilepublishing AS
    SELECT (((libraryfilealias.id)::text || '.'::text) || (securesourcepackagepublishinghistory.id)::text) AS id, distroseries.distribution, securesourcepackagepublishinghistory.id AS sourcepackagepublishing, sourcepackagereleasefile.libraryfile AS libraryfilealias, libraryfilealias.filename AS libraryfilealiasfilename, sourcepackagename.name AS sourcepackagename, component.name AS componentname, distroseries.name AS distroseriesname, securesourcepackagepublishinghistory.status AS publishingstatus, securesourcepackagepublishinghistory.pocket, securesourcepackagepublishinghistory.archive FROM ((((((sourcepackagepublishinghistory securesourcepackagepublishinghistory JOIN sourcepackagerelease ON ((securesourcepackagepublishinghistory.sourcepackagerelease = sourcepackagerelease.id))) JOIN sourcepackagename ON ((sourcepackagerelease.sourcepackagename = sourcepackagename.id))) JOIN sourcepackagereleasefile ON ((sourcepackagereleasefile.sourcepackagerelease = sourcepackagerelease.id))) JOIN libraryfilealias ON ((libraryfilealias.id = sourcepackagereleasefile.libraryfile))) JOIN distroseries ON ((securesourcepackagepublishinghistory.distroseries = distroseries.id))) JOIN component ON ((securesourcepackagepublishinghistory.component = component.id))) WHERE (securesourcepackagepublishinghistory.dateremoved IS NULL);


COMMENT ON VIEW sourcepackagefilepublishing IS 'This view is used mostly by Lucille while performing publishing and unpublishing operations. It lists all the files associated with a sourcepackagerelease and collates all the textual representations needed for publishing components etc to allow rapid queries from SQLObject.';


CREATE TABLE sourcepackageformatselection (
    id integer NOT NULL,
    distroseries integer NOT NULL,
    format integer NOT NULL
);


COMMENT ON TABLE sourcepackageformatselection IS 'Allowed source package formats for a given distroseries.';


COMMENT ON COLUMN sourcepackageformatselection.distroseries IS 'Refers to the distroseries in question.';


COMMENT ON COLUMN sourcepackageformatselection.format IS 'The SourcePackageFormat to allow.';


CREATE SEQUENCE sourcepackageformatselection_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackageformatselection_id_seq OWNED BY sourcepackageformatselection.id;


CREATE SEQUENCE sourcepackagename_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackagename_id_seq OWNED BY sourcepackagename.id;


CREATE SEQUENCE sourcepackagepublishinghistory_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackagepublishinghistory_id_seq OWNED BY sourcepackagepublishinghistory.id;


CREATE TABLE sourcepackagerecipe (
    id integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_last_modified timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    registrant integer NOT NULL,
    owner integer NOT NULL,
    name text NOT NULL,
    description text,
    build_daily boolean DEFAULT false NOT NULL,
    daily_build_archive integer,
    is_stale boolean DEFAULT true NOT NULL
);


COMMENT ON TABLE sourcepackagerecipe IS 'A recipe for assembling a source package from branches.';


COMMENT ON COLUMN sourcepackagerecipe.registrant IS 'The person who created this recipe.';


COMMENT ON COLUMN sourcepackagerecipe.owner IS 'The person or team who can edit this recipe.';


COMMENT ON COLUMN sourcepackagerecipe.name IS 'The name of the recipe in the web/URL.';


COMMENT ON COLUMN sourcepackagerecipe.build_daily IS 'If true, this recipe should be built daily.';


COMMENT ON COLUMN sourcepackagerecipe.daily_build_archive IS 'The archive to build into for daily builds.';


COMMENT ON COLUMN sourcepackagerecipe.is_stale IS 'True if this recipe has not been built since a branch was updated.';


CREATE SEQUENCE sourcepackagerecipe_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackagerecipe_id_seq OWNED BY sourcepackagerecipe.id;


CREATE TABLE sourcepackagerecipebuild (
    id integer NOT NULL,
    distroseries integer NOT NULL,
    requester integer NOT NULL,
    recipe integer,
    manifest integer,
    package_build integer NOT NULL
);


COMMENT ON TABLE sourcepackagerecipebuild IS 'The build record for the process of building a source package as described by a recipe.';


COMMENT ON COLUMN sourcepackagerecipebuild.distroseries IS 'The distroseries the build was for.';


COMMENT ON COLUMN sourcepackagerecipebuild.requester IS 'Who requested the build.';


COMMENT ON COLUMN sourcepackagerecipebuild.recipe IS 'The recipe being processed.';


COMMENT ON COLUMN sourcepackagerecipebuild.manifest IS 'The evaluated recipe that was built.';


COMMENT ON COLUMN sourcepackagerecipebuild.package_build IS 'The package_build with the base information about this build.';


CREATE SEQUENCE sourcepackagerecipebuild_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackagerecipebuild_id_seq OWNED BY sourcepackagerecipebuild.id;


CREATE TABLE sourcepackagerecipebuildjob (
    id integer NOT NULL,
    job integer NOT NULL,
    sourcepackage_recipe_build integer NOT NULL
);


COMMENT ON TABLE sourcepackagerecipebuildjob IS 'The link between a SourcePackageRecipeBuild row and a Job row to schedule a build of a source package recipe.';


COMMENT ON COLUMN sourcepackagerecipebuildjob.sourcepackage_recipe_build IS 'The build record describing the package being built.';


CREATE SEQUENCE sourcepackagerecipebuildjob_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackagerecipebuildjob_id_seq OWNED BY sourcepackagerecipebuildjob.id;


CREATE TABLE sourcepackagerecipedata (
    id integer NOT NULL,
    base_branch integer NOT NULL,
    recipe_format text NOT NULL,
    deb_version_template text NOT NULL,
    revspec text,
    sourcepackage_recipe integer,
    sourcepackage_recipe_build integer,
    CONSTRAINT sourcepackagerecipedata__recipe_or_build_is_not_null CHECK (((sourcepackage_recipe IS NULL) <> (sourcepackage_recipe_build IS NULL)))
);


COMMENT ON TABLE sourcepackagerecipedata IS 'The database representation of a BaseRecipeBranch from bzr-builder.  Exactly one of sourcepackage_recipe or sourcepackage_recipe_build will be non-NULL.';


COMMENT ON COLUMN sourcepackagerecipedata.base_branch IS 'The branch the recipe is based on.';


COMMENT ON COLUMN sourcepackagerecipedata.recipe_format IS 'The format version of the recipe.';


COMMENT ON COLUMN sourcepackagerecipedata.deb_version_template IS 'The template for the revision number of the build.';


COMMENT ON COLUMN sourcepackagerecipedata.revspec IS 'The revision from base_branch to use.';


COMMENT ON COLUMN sourcepackagerecipedata.sourcepackage_recipe IS 'The recipe that this data is for.';


COMMENT ON COLUMN sourcepackagerecipedata.sourcepackage_recipe_build IS 'The build that resulted in this manifest.';


CREATE SEQUENCE sourcepackagerecipedata_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackagerecipedata_id_seq OWNED BY sourcepackagerecipedata.id;


CREATE TABLE sourcepackagerecipedatainstruction (
    id integer NOT NULL,
    name text NOT NULL,
    type integer NOT NULL,
    comment text,
    line_number integer NOT NULL,
    branch integer NOT NULL,
    revspec text,
    directory text,
    recipe_data integer NOT NULL,
    parent_instruction integer,
    source_directory text,
    CONSTRAINT sourcepackagerecipedatainstruction__directory_not_null CHECK ((((type = 3) OR ((type = 1) AND (directory IS NULL))) OR ((type = 2) AND (directory IS NOT NULL)))),
    CONSTRAINT sourcepackagerecipedatainstruction__source_directory_null CHECK ((((type = ANY (ARRAY[1, 2])) AND (source_directory IS NULL)) OR ((type = 3) AND (source_directory IS NOT NULL))))
);


COMMENT ON TABLE sourcepackagerecipedatainstruction IS 'A line from the recipe, specifying a branch to nest or merge.';


COMMENT ON COLUMN sourcepackagerecipedatainstruction.name IS 'The name of the instruction.';


COMMENT ON COLUMN sourcepackagerecipedatainstruction.type IS 'The type of the instruction (MERGE == 1, NEST == 2).';


COMMENT ON COLUMN sourcepackagerecipedatainstruction.comment IS 'The comment from the recipe about this instruction.';


COMMENT ON COLUMN sourcepackagerecipedatainstruction.line_number IS 'The line number of the instruction in the recipe.';


COMMENT ON COLUMN sourcepackagerecipedatainstruction.branch IS 'The branch being merged or nested.';


COMMENT ON COLUMN sourcepackagerecipedatainstruction.revspec IS 'The revision of the branch to use.';


COMMENT ON COLUMN sourcepackagerecipedatainstruction.directory IS 'The location to nest at, if this is a nest/nest-part instruction.';


COMMENT ON COLUMN sourcepackagerecipedatainstruction.recipe_data IS 'The SourcePackageRecipeData this instruction is part of.';


COMMENT ON COLUMN sourcepackagerecipedatainstruction.parent_instruction IS 'The nested branch this instruction applies to, or NULL for a top-level instruction.';


COMMENT ON COLUMN sourcepackagerecipedatainstruction.source_directory IS 'The location in the branch to nest, if this is a nest-part instruction.';


CREATE SEQUENCE sourcepackagerecipedatainstruction_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackagerecipedatainstruction_id_seq OWNED BY sourcepackagerecipedatainstruction.id;


CREATE TABLE sourcepackagerecipedistroseries (
    id integer NOT NULL,
    sourcepackagerecipe integer NOT NULL,
    distroseries integer NOT NULL
);


COMMENT ON TABLE sourcepackagerecipedistroseries IS 'Link table for sourcepackagerecipe and distroseries.';


COMMENT ON COLUMN sourcepackagerecipedistroseries.sourcepackagerecipe IS 'The primary key of the SourcePackageRecipe.';


COMMENT ON COLUMN sourcepackagerecipedistroseries.distroseries IS 'The primary key of the DistroSeries.';


CREATE SEQUENCE sourcepackagerecipedistroseries_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackagerecipedistroseries_id_seq OWNED BY sourcepackagerecipedistroseries.id;


CREATE SEQUENCE sourcepackagerelease_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackagerelease_id_seq OWNED BY sourcepackagerelease.id;


CREATE SEQUENCE sourcepackagereleasefile_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sourcepackagereleasefile_id_seq OWNED BY sourcepackagereleasefile.id;


CREATE TABLE specification (
    id integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    summary text,
    owner integer NOT NULL,
    assignee integer,
    drafter integer,
    approver integer,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    product integer,
    productseries integer,
    distribution integer,
    distroseries integer,
    milestone integer,
    definition_status integer NOT NULL,
    priority integer DEFAULT 5 NOT NULL,
    specurl text,
    whiteboard text,
    superseded_by integer,
    direction_approved boolean DEFAULT false NOT NULL,
    man_days integer,
    implementation_status integer DEFAULT 0 NOT NULL,
    goalstatus integer DEFAULT 30 NOT NULL,
    fti ts2.tsvector,
    goal_proposer integer,
    date_goal_proposed timestamp without time zone,
    goal_decider integer,
    date_goal_decided timestamp without time zone,
    completer integer,
    date_completed timestamp without time zone,
    starter integer,
    date_started timestamp without time zone,
    private boolean DEFAULT false NOT NULL,
    CONSTRAINT distribution_and_distroseries CHECK (((distroseries IS NULL) OR (distribution IS NOT NULL))),
    CONSTRAINT product_and_productseries CHECK (((productseries IS NULL) OR (product IS NOT NULL))),
    CONSTRAINT product_xor_distribution CHECK (((product IS NULL) <> (distribution IS NULL))),
    CONSTRAINT specification_completion_fully_recorded_chk CHECK (((date_completed IS NULL) = (completer IS NULL))),
    CONSTRAINT specification_completion_recorded_chk CHECK (((date_completed IS NULL) <> (((implementation_status = 90) OR (definition_status = ANY (ARRAY[60, 70]))) OR ((implementation_status = 95) AND (definition_status = 10))))),
    CONSTRAINT specification_decision_recorded CHECK (((goalstatus = 30) OR ((goal_decider IS NOT NULL) AND (date_goal_decided IS NOT NULL)))),
    CONSTRAINT specification_goal_nomination_chk CHECK ((((productseries IS NULL) AND (distroseries IS NULL)) OR ((goal_proposer IS NOT NULL) AND (date_goal_proposed IS NOT NULL)))),
    CONSTRAINT specification_not_self_superseding CHECK ((superseded_by <> id)),
    CONSTRAINT specification_start_fully_recorded_chk CHECK (((date_started IS NULL) = (starter IS NULL))),
    CONSTRAINT specification_start_recorded_chk CHECK (((date_started IS NULL) <> ((implementation_status <> ALL (ARRAY[0, 5, 10, 95])) OR ((implementation_status = 95) AND (definition_status = 10))))),
    CONSTRAINT valid_name CHECK (valid_name(name)),
    CONSTRAINT valid_url CHECK (valid_absolute_url(specurl))
);


COMMENT ON TABLE specification IS 'A feature specification. At the moment we do not store the actual specification, we store a URL for the spec, which is managed in a wiki somewhere else. We store the overall state of the spec, as well as queueing information about who needs to review the spec, and why.';


COMMENT ON COLUMN specification.assignee IS 'The person who has been assigned to implement this specification.';


COMMENT ON COLUMN specification.drafter IS 'The person who has been asked to draft this specification. They are responsible for getting the spec to "approved" state.';


COMMENT ON COLUMN specification.approver IS 'The person who is responsible for approving the specification in due course, and who will probably be required to review the code itself when it is being implemented.';


COMMENT ON COLUMN specification.product IS 'The product for which this is a feature specification. The specification must be connected either to a product, or to a distribution.';


COMMENT ON COLUMN specification.productseries IS 'This is an indicator that the specification is planned, or targeted, for implementation in a given product series. It is not necessary to target a spec to a series, but it is a useful way of showing which specs are planned to implement for a given series.';


COMMENT ON COLUMN specification.distribution IS 'The distribution for which this is a feature specification. The specification must be connected either to a product, or to a distribution.';


COMMENT ON COLUMN specification.distroseries IS 'If this is not NULL, then it means that the release managers have targeted this feature to be released in the given distroseries. It is not necessary to target a distroseries, but this is a useful way of know which specifications are, for example, BreezyGoals.';


COMMENT ON COLUMN specification.milestone IS 'This is an indicator that the feature defined in this specification is expected to be delivered for a given milestone. Note that milestones are not necessarily releases, they are a way of identifying a point in time and grouping bugs and features around that.';


COMMENT ON COLUMN specification.definition_status IS 'An enum called SpecificationDefinitionStatus that shows what the current status (new, draft, implemented etc) the spec is currently in.';


COMMENT ON COLUMN specification.priority IS 'An enum that gives the implementation priority (low, medium, high, emergency) of the feature defined in this specification.';


COMMENT ON COLUMN specification.specurl IS 'The URL where the specification itself can be found. This is usually a wiki page somewhere.';


COMMENT ON COLUMN specification.whiteboard IS 'As long as the specification is somewhere else (i.e. not in Launchpad) it will be useful to have a place to hold some arbitrary message or status flags that have meaning to the project, not Launchpad. This whiteboard is just the place for it.';


COMMENT ON COLUMN specification.superseded_by IS 'The specification which replaced this specification.';


COMMENT ON COLUMN specification.implementation_status IS 'The implementation status of this specification. This field is used to track the actual delivery of the feature (implementing the spec), as opposed to the definition of expected behaviour (writing the spec).';


COMMENT ON COLUMN specification.goalstatus IS 'Whether or not the drivers for the goal product series or distro release have accepted this specification as a goal.';


COMMENT ON COLUMN specification.goal_proposer IS 'The person who proposed this spec as a goal for the productseries or distroseries.';


COMMENT ON COLUMN specification.date_goal_proposed IS 'The date the spec was proposed as a goal.';


COMMENT ON COLUMN specification.goal_decider IS 'The person who approved or declined this goal.';


COMMENT ON COLUMN specification.date_goal_decided IS 'The date this goal was accepted or declined.';


COMMENT ON COLUMN specification.completer IS 'The person who changed the state of the spec in such a way that it was determined to be completed.';


COMMENT ON COLUMN specification.date_completed IS 'The date this specification was completed or marked obsolete. This lets us chart the progress of a project (or a release) over time in terms of features implemented.';


COMMENT ON COLUMN specification.private IS 'Specification is private.';


COMMENT ON CONSTRAINT specification_completion_fully_recorded_chk ON specification IS 'A constraint that ensures, where we have a date_completed, that we also have a completer. This means that the resolution was fully recorded.';


CREATE SEQUENCE specification_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE specification_id_seq OWNED BY specification.id;


CREATE TABLE specificationbranch (
    id integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    specification integer NOT NULL,
    branch integer NOT NULL,
    summary text,
    registrant integer NOT NULL
);


COMMENT ON TABLE specificationbranch IS 'A branch related to a specification, most likely a branch for implementing the specification.  It is possible to have multiple branches for a given specification especially in the situation where the specification requires modifying multiple products.';


COMMENT ON COLUMN specificationbranch.specification IS 'The specification associated with this branch.';


COMMENT ON COLUMN specificationbranch.branch IS 'The branch associated to the specification.';


COMMENT ON COLUMN specificationbranch.registrant IS 'The person who linked the specification to the branch.';


CREATE SEQUENCE specificationbranch_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE specificationbranch_id_seq OWNED BY specificationbranch.id;


CREATE TABLE specificationbug (
    id integer NOT NULL,
    specification integer NOT NULL,
    bug integer NOT NULL
);


COMMENT ON TABLE specificationbug IS 'A table linking a specification and a bug. This is used to provide for easy navigation from bugs to related specs, and vice versa.';


CREATE SEQUENCE specificationbug_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE specificationbug_id_seq OWNED BY specificationbug.id;


CREATE TABLE specificationdependency (
    id integer NOT NULL,
    specification integer NOT NULL,
    dependency integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    CONSTRAINT specificationdependency_not_self CHECK ((specification <> dependency))
);


COMMENT ON TABLE specificationdependency IS 'A table that stores information about which specification needs to be implemented before another specification can be implemented. We can create a chain of dependencies, and use that information for scheduling and prioritisation of work.';


COMMENT ON COLUMN specificationdependency.specification IS 'The spec for which we are creating a dependency.';


COMMENT ON COLUMN specificationdependency.dependency IS 'The spec on which it is dependant.';


CREATE SEQUENCE specificationdependency_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE specificationdependency_id_seq OWNED BY specificationdependency.id;


CREATE TABLE specificationfeedback (
    id integer NOT NULL,
    specification integer NOT NULL,
    reviewer integer NOT NULL,
    requester integer NOT NULL,
    queuemsg text,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE specificationfeedback IS 'A table representing a review request of a specification, from one user to another, with an optional message.';


COMMENT ON COLUMN specificationfeedback.reviewer IS 'The person who has been asked to do the review.';


COMMENT ON COLUMN specificationfeedback.requester IS 'The person who made the request.';


COMMENT ON COLUMN specificationfeedback.queuemsg IS 'An optional text message for the reviewer, from the requester.';


CREATE SEQUENCE specificationfeedback_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE specificationfeedback_id_seq OWNED BY specificationfeedback.id;


CREATE TABLE specificationmessage (
    id integer NOT NULL,
    specification integer,
    message integer,
    visible boolean DEFAULT true NOT NULL
);


COMMENT ON TABLE specificationmessage IS 'Comments and discussion on a Specification.';


CREATE SEQUENCE specificationmessage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE specificationmessage_id_seq OWNED BY specificationmessage.id;


CREATE TABLE specificationsubscription (
    id integer NOT NULL,
    specification integer NOT NULL,
    person integer NOT NULL,
    essential boolean DEFAULT false NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE specificationsubscription IS 'A table capturing a subscription of a person to a specification.';


COMMENT ON COLUMN specificationsubscription.essential IS 'A field that indicates whether or not this person is essential to discussions on the planned feature. This is used by the meeting scheduler to ensure that all the essential people are at any automatically scheduled BOFs discussing that spec.';


CREATE SEQUENCE specificationsubscription_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE specificationsubscription_id_seq OWNED BY specificationsubscription.id;


CREATE TABLE spokenin (
    language integer NOT NULL,
    country integer NOT NULL,
    id integer DEFAULT nextval(('spokenin_id_seq'::text)::regclass) NOT NULL
);


CREATE SEQUENCE spokenin_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE spokenin_id_seq OWNED BY spokenin.id;


CREATE TABLE sprint (
    id integer NOT NULL,
    owner integer NOT NULL,
    name text NOT NULL,
    title text NOT NULL,
    summary text NOT NULL,
    home_page text,
    address text,
    time_zone text NOT NULL,
    time_starts timestamp without time zone NOT NULL,
    time_ends timestamp without time zone NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    driver integer,
    homepage_content text,
    icon integer,
    mugshot integer,
    logo integer,
    CONSTRAINT sprint_starts_before_ends CHECK ((time_starts < time_ends))
);


COMMENT ON TABLE sprint IS 'A meeting, sprint or conference. This is a convenient way to keep track of a collection of specs that will be discussed, and the people that will be attending.';


COMMENT ON COLUMN sprint.time_zone IS 'The timezone of the sprint, stored in text format from the Olsen database names, like "US/Eastern".';


COMMENT ON COLUMN sprint.driver IS 'The driver (together with the registrant or owner) is responsible for deciding which topics will be accepted onto the agenda of the sprint.';


COMMENT ON COLUMN sprint.homepage_content IS 'A home page for this sprint in the Launchpad.';


COMMENT ON COLUMN sprint.icon IS 'The library file alias to a small image to be used as an icon whenever we are referring to a sprint.';


COMMENT ON COLUMN sprint.mugshot IS 'The library file alias of a mugshot image to display as the branding of a sprint, on its home page.';


COMMENT ON COLUMN sprint.logo IS 'The library file alias of a smaller version of this sprint''s mugshot.';


CREATE SEQUENCE sprint_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sprint_id_seq OWNED BY sprint.id;


CREATE TABLE sprintattendance (
    id integer NOT NULL,
    attendee integer NOT NULL,
    sprint integer NOT NULL,
    time_starts timestamp without time zone NOT NULL,
    time_ends timestamp without time zone NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    is_physical boolean DEFAULT false NOT NULL,
    CONSTRAINT sprintattendance_starts_before_ends CHECK ((time_starts < time_ends))
);


COMMENT ON TABLE sprintattendance IS 'The record that someone will be attending a particular sprint or meeting.';


COMMENT ON COLUMN sprintattendance.attendee IS 'The person attending the sprint.';


COMMENT ON COLUMN sprintattendance.sprint IS 'The sprint the person is attending.';


COMMENT ON COLUMN sprintattendance.time_starts IS 'The time from which the person will be available to participate in meetings at the sprint.';


COMMENT ON COLUMN sprintattendance.time_ends IS 'The time of departure from the sprint or conference - this is the last time at which the person is available for meetings during the sprint.';


COMMENT ON COLUMN sprintattendance.is_physical IS 'Is the person physically attending the sprint';


CREATE SEQUENCE sprintattendance_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sprintattendance_id_seq OWNED BY sprintattendance.id;


CREATE TABLE sprintspecification (
    id integer NOT NULL,
    sprint integer NOT NULL,
    specification integer NOT NULL,
    status integer DEFAULT 30 NOT NULL,
    whiteboard text,
    registrant integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    decider integer,
    date_decided timestamp without time zone,
    CONSTRAINT sprintspecification_decision_recorded CHECK (((status = 30) OR ((decider IS NOT NULL) AND (date_decided IS NOT NULL))))
);


COMMENT ON TABLE sprintspecification IS 'The link between a sprint and a specification, so that we know which specs are going to be discussed at which sprint.';


COMMENT ON COLUMN sprintspecification.status IS 'Whether or not the spec has been approved on the agenda for this sprint.';


COMMENT ON COLUMN sprintspecification.whiteboard IS 'A place to store comments specifically related to this spec being on the agenda of this meeting.';


COMMENT ON COLUMN sprintspecification.registrant IS 'The person who nominated this specification for the agenda of the sprint.';


COMMENT ON COLUMN sprintspecification.decider IS 'The person who approved or declined this specification for the sprint agenda.';


COMMENT ON COLUMN sprintspecification.date_decided IS 'The date this specification was approved or declined for the agenda.';


CREATE SEQUENCE sprintspecification_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sprintspecification_id_seq OWNED BY sprintspecification.id;


CREATE TABLE sshkey (
    id integer NOT NULL,
    person integer,
    keytype integer NOT NULL,
    keytext text NOT NULL,
    comment text NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


CREATE SEQUENCE sshkey_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE sshkey_id_seq OWNED BY sshkey.id;


CREATE TABLE structuralsubscription (
    id integer NOT NULL,
    product integer,
    productseries integer,
    project integer,
    milestone integer,
    distribution integer,
    distroseries integer,
    sourcepackagename integer,
    subscriber integer NOT NULL,
    subscribed_by integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    date_last_updated timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    CONSTRAINT one_target CHECK ((null_count(ARRAY[product, productseries, project, distroseries, distribution, milestone]) = 5)),
    CONSTRAINT sourcepackagename_requires_distribution CHECK (((sourcepackagename IS NULL) OR (distribution IS NOT NULL)))
);


COMMENT ON TABLE structuralsubscription IS 'A subscription to notifications about a Launchpad structure';


COMMENT ON COLUMN structuralsubscription.product IS 'The subscription`s target, when it is a product.';


COMMENT ON COLUMN structuralsubscription.productseries IS 'The subscription`s target, when it is a product series.';


COMMENT ON COLUMN structuralsubscription.project IS 'The subscription`s target, when it is a project.';


COMMENT ON COLUMN structuralsubscription.milestone IS 'The subscription`s target, when it is a milestone.';


COMMENT ON COLUMN structuralsubscription.distribution IS 'The subscription`s target, when it is a distribution.';


COMMENT ON COLUMN structuralsubscription.distroseries IS 'The subscription`s target, when it is a distribution series.';


COMMENT ON COLUMN structuralsubscription.sourcepackagename IS 'The subscription`s target, when it is a source-package';


COMMENT ON COLUMN structuralsubscription.subscriber IS 'The person subscribed.';


COMMENT ON COLUMN structuralsubscription.subscribed_by IS 'The person initiating the subscription.';


COMMENT ON COLUMN structuralsubscription.date_created IS 'The date on which this subscription was created.';


COMMENT ON COLUMN structuralsubscription.date_last_updated IS 'The date on which this subscription was last updated.';


CREATE SEQUENCE structuralsubscription_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE structuralsubscription_id_seq OWNED BY structuralsubscription.id;


CREATE TABLE subunitstream (
    id integer NOT NULL,
    uploader integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    branch integer NOT NULL,
    stream integer NOT NULL
);


COMMENT ON TABLE subunitstream IS 'Raw gz compressed subunit streams.';


COMMENT ON COLUMN subunitstream.uploader IS 'The account used to upload the stream.';


COMMENT ON COLUMN subunitstream.date_created IS 'The date of the upload.';


COMMENT ON COLUMN subunitstream.branch IS 'The branch which the stream was created on/for/with.';


COMMENT ON COLUMN subunitstream.stream IS 'The library file alias which contains the stream content.';


CREATE SEQUENCE subunitstream_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE subunitstream_id_seq OWNED BY subunitstream.id;


CREATE TABLE suggestivepotemplate (
    potemplate integer NOT NULL
);


COMMENT ON TABLE suggestivepotemplate IS 'Cache of POTemplates that can provide external translation suggestions.';


CREATE TABLE teammembership (
    id integer NOT NULL,
    person integer NOT NULL,
    team integer NOT NULL,
    status integer NOT NULL,
    date_joined timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone),
    date_expires timestamp without time zone,
    last_changed_by integer,
    last_change_comment text,
    proposed_by integer,
    acknowledged_by integer,
    reviewed_by integer,
    date_proposed timestamp without time zone,
    date_last_changed timestamp without time zone,
    date_acknowledged timestamp without time zone,
    date_reviewed timestamp without time zone,
    proponent_comment text,
    acknowledger_comment text,
    reviewer_comment text,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE teammembership IS 'The direct membership of a person on a given team.';


COMMENT ON COLUMN teammembership.person IS 'The person.';


COMMENT ON COLUMN teammembership.team IS 'The team.';


COMMENT ON COLUMN teammembership.status IS 'The state of the membership.';


COMMENT ON COLUMN teammembership.date_joined IS 'The date this membership was made active for the first time.';


COMMENT ON COLUMN teammembership.date_expires IS 'The date this membership will expire, if any.';


COMMENT ON COLUMN teammembership.last_changed_by IS 'The person who reviewed the last change to this membership.';


COMMENT ON COLUMN teammembership.last_change_comment IS 'The comment left by the reviewer for the change.';


COMMENT ON COLUMN teammembership.proposed_by IS 'The user who proposed the person as member of the team.';


COMMENT ON COLUMN teammembership.acknowledged_by IS 'The member (or someone acting on his behalf) who accepts an invitation to join a team';


COMMENT ON COLUMN teammembership.reviewed_by IS 'The team admin who reviewed (approved/declined) the membership.';


COMMENT ON COLUMN teammembership.date_proposed IS 'The date of the proposal.';


COMMENT ON COLUMN teammembership.date_last_changed IS 'The date this membership was last changed.';


COMMENT ON COLUMN teammembership.date_acknowledged IS 'The date of acknowledgement.';


COMMENT ON COLUMN teammembership.date_reviewed IS 'The date the membership was
approved/declined.';


COMMENT ON COLUMN teammembership.proponent_comment IS 'The comment left by the proponent.';


COMMENT ON COLUMN teammembership.acknowledger_comment IS 'The comment left by the person who acknowledged the membership.';


COMMENT ON COLUMN teammembership.reviewer_comment IS 'The comment left by the approver.';


COMMENT ON COLUMN teammembership.date_created IS 'The date this membership was created.';


CREATE SEQUENCE teammembership_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE teammembership_id_seq OWNED BY teammembership.id;


CREATE TABLE teamparticipation (
    id integer NOT NULL,
    team integer NOT NULL,
    person integer NOT NULL
);


COMMENT ON TABLE teamparticipation IS 'The participation of a person on a team, which can be a direct or indirect membership.';


COMMENT ON COLUMN teamparticipation.team IS 'The team.';


COMMENT ON COLUMN teamparticipation.person IS 'The member.';


CREATE SEQUENCE teamparticipation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE teamparticipation_id_seq OWNED BY teamparticipation.id;


CREATE TABLE temporaryblobstorage (
    id integer NOT NULL,
    uuid text NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    file_alias integer NOT NULL
);


CREATE SEQUENCE temporaryblobstorage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE temporaryblobstorage_id_seq OWNED BY temporaryblobstorage.id;


CREATE TABLE translationgroup (
    id integer NOT NULL,
    name text NOT NULL,
    title text,
    summary text,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    owner integer NOT NULL,
    translation_guide_url text
);


COMMENT ON TABLE translationgroup IS 'This represents an organised translation group that spans multiple languages. Effectively it consists of a list of people (pointers to Person), and each Person is associated with a Language. So, for each TranslationGroup we can ask the question "in this TranslationGroup, who is responsible for translating into Arabic?", for example.';


COMMENT ON COLUMN translationgroup.translation_guide_url IS 'URL with documentation about general rules for translation work done by this translation group.';


CREATE SEQUENCE translationgroup_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE translationgroup_id_seq OWNED BY translationgroup.id;


CREATE TABLE translationimportqueueentry (
    id integer NOT NULL,
    path text NOT NULL,
    content integer NOT NULL,
    importer integer NOT NULL,
    dateimported timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    distroseries integer,
    sourcepackagename integer,
    productseries integer,
    by_maintainer boolean NOT NULL,
    pofile integer,
    potemplate integer,
    status integer DEFAULT 5 NOT NULL,
    date_status_changed timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    format integer DEFAULT 1 NOT NULL,
    error_output text,
    CONSTRAINT valid_link CHECK ((((productseries IS NULL) <> (distroseries IS NULL)) AND ((distroseries IS NULL) = (sourcepackagename IS NULL))))
);


COMMENT ON TABLE translationimportqueueentry IS 'Queue with translatable resources pending to be imported into Rosetta.';


COMMENT ON COLUMN translationimportqueueentry.path IS 'The path (included the filename) where this file was stored when we imported it.';


COMMENT ON COLUMN translationimportqueueentry.content IS 'The file content that is being imported.';


COMMENT ON COLUMN translationimportqueueentry.importer IS 'The person that did the import.';


COMMENT ON COLUMN translationimportqueueentry.dateimported IS 'The timestamp when the import was done.';


COMMENT ON COLUMN translationimportqueueentry.distroseries IS 'The distribution release related to this import.';


COMMENT ON COLUMN translationimportqueueentry.sourcepackagename IS 'The source package name related to this import.';


COMMENT ON COLUMN translationimportqueueentry.productseries IS 'The product series related to this import.';


COMMENT ON COLUMN translationimportqueueentry.by_maintainer IS 'Notes whether is a published upload.';


COMMENT ON COLUMN translationimportqueueentry.pofile IS 'Link to the POFile where this import will end.';


COMMENT ON COLUMN translationimportqueueentry.potemplate IS 'Link to the POTemplate where this import will end.';


COMMENT ON COLUMN translationimportqueueentry.status IS 'The status of the import: 1 Approved, 2 Imported, 3 Deleted, 4 Failed, 5 Needs Review, 6 Blocked.';


COMMENT ON COLUMN translationimportqueueentry.date_status_changed IS 'The date when the status of this entry was changed.';


COMMENT ON COLUMN translationimportqueueentry.format IS 'The file format of the content that is being imported.';


COMMENT ON COLUMN translationimportqueueentry.error_output IS 'Error output from last import attempt.';


CREATE SEQUENCE translationimportqueueentry_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE translationimportqueueentry_id_seq OWNED BY translationimportqueueentry.id;


CREATE TABLE translationmessage (
    id integer NOT NULL,
    potmsgset integer NOT NULL,
    date_created timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    submitter integer NOT NULL,
    date_reviewed timestamp without time zone,
    reviewer integer,
    msgstr0 integer,
    msgstr1 integer,
    msgstr2 integer,
    msgstr3 integer,
    comment text,
    origin integer NOT NULL,
    validation_status integer DEFAULT 0 NOT NULL,
    is_current_ubuntu boolean DEFAULT false NOT NULL,
    is_fuzzy boolean DEFAULT false NOT NULL,
    is_current_upstream boolean DEFAULT false NOT NULL,
    was_obsolete_in_last_import boolean DEFAULT false NOT NULL,
    was_fuzzy_in_last_import boolean DEFAULT false NOT NULL,
    msgstr4 integer,
    msgstr5 integer,
    potemplate integer,
    language integer,
    CONSTRAINT translationmessage__reviewer__date_reviewed__valid CHECK (((reviewer IS NULL) = (date_reviewed IS NULL)))
);


COMMENT ON TABLE translationmessage IS 'This table stores a concrete
translation for a POTMsgSet message. It knows who, when and where did it,
and whether it was reviewed by someone and when was it reviewed.';


COMMENT ON COLUMN translationmessage.potmsgset IS 'The template message which
this translation message is a translation of.';


COMMENT ON COLUMN translationmessage.date_created IS 'The date we saw this
translation first.';


COMMENT ON COLUMN translationmessage.submitter IS 'The person that made
the submission through the web to Launchpad, or the last translator on the
translation file that we are processing, or the person who uploaded that
pofile to Launchpad. In short, our best guess as to the person who is
contributing that translation.';


COMMENT ON COLUMN translationmessage.date_reviewed IS 'The date when this
message was reviewed for last time.';


COMMENT ON COLUMN translationmessage.reviewer IS 'The person who did the
review and accepted current translations.';


COMMENT ON COLUMN translationmessage.msgstr0 IS 'Translation for plural form 0
(if any).';


COMMENT ON COLUMN translationmessage.msgstr1 IS 'Translation for plural form 1
(if any).';


COMMENT ON COLUMN translationmessage.msgstr2 IS 'Translation for plural form 2
(if any).';


COMMENT ON COLUMN translationmessage.msgstr3 IS 'Translation for plural form 3
(if any).';


COMMENT ON COLUMN translationmessage.comment IS 'Text of translator
comment from the translation file.';


COMMENT ON COLUMN translationmessage.origin IS 'The source of this
translation. This indicates whether the translation was in a translation file
that we parsed (probably one published in a package or branch or tarball), in
which case its value will be 1, or was submitted through the web, in which
case its value will be 2.';


COMMENT ON COLUMN translationmessage.validation_status IS 'Whether we have
validated this translation. Being 0 the value that says this row has not been
validated yet, 1 the value that says it is correct and 2 the value noting that
there was an unknown error with the validation.';


COMMENT ON COLUMN translationmessage.is_current_ubuntu IS 'Whether this translation
is being used in Launchpad.';


COMMENT ON COLUMN translationmessage.is_fuzzy IS 'Whether this translation
must be checked before use it.';


COMMENT ON COLUMN translationmessage.is_current_upstream IS 'Whether this translation
is being used in latest imported file.';


COMMENT ON COLUMN translationmessage.was_obsolete_in_last_import IS 'Whether
this translation was obsolete in last imported file.';


COMMENT ON COLUMN translationmessage.was_fuzzy_in_last_import IS 'Whether this
imported translation must be checked before use it.';


CREATE SEQUENCE translationmessage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE translationmessage_id_seq OWNED BY translationmessage.id;


CREATE TABLE translationrelicensingagreement (
    id integer NOT NULL,
    person integer NOT NULL,
    allow_relicensing boolean DEFAULT true NOT NULL,
    date_decided timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL
);


COMMENT ON TABLE translationrelicensingagreement IS 'Who of translation contributors wants their translations relicensed and who does not.';


COMMENT ON COLUMN translationrelicensingagreement.person IS 'A translator which has submitted their answer.';


COMMENT ON COLUMN translationrelicensingagreement.allow_relicensing IS 'Does this person want their translations relicensed under BSD.';


COMMENT ON COLUMN translationrelicensingagreement.date_decided IS 'Date when the last change of opinion was registered.';


CREATE SEQUENCE translationrelicensingagreement_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE translationrelicensingagreement_id_seq OWNED BY translationrelicensingagreement.id;


CREATE SEQUENCE translationtemplateitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE translationtemplateitem_id_seq OWNED BY translationtemplateitem.id;


CREATE TABLE translationtemplatesbuild (
    id integer NOT NULL,
    build_farm_job integer NOT NULL,
    branch integer NOT NULL
);


COMMENT ON TABLE translationtemplatesbuild IS 'Build-farm record of a translation templates build.';


COMMENT ON COLUMN translationtemplatesbuild.build_farm_job IS 'Associated BuildFarmJob.';


COMMENT ON COLUMN translationtemplatesbuild.branch IS 'Branch to build templates out of.';


CREATE SEQUENCE translationtemplatesbuild_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE translationtemplatesbuild_id_seq OWNED BY translationtemplatesbuild.id;


CREATE TABLE translator (
    id integer NOT NULL,
    translationgroup integer NOT NULL,
    language integer NOT NULL,
    translator integer NOT NULL,
    datecreated timestamp without time zone DEFAULT timezone('UTC'::text, ('now'::text)::timestamp(6) with time zone) NOT NULL,
    style_guide_url text
);


COMMENT ON TABLE translator IS 'A translator is a person in a TranslationGroup who is responsible for a particular language. At the moment, there can only be one person in a TranslationGroup who is the Translator for a particular language. If you want multiple people, then create a launchpad team and assign that team to the language.';


COMMENT ON COLUMN translator.translationgroup IS 'The TranslationGroup for which this Translator is working.';


COMMENT ON COLUMN translator.language IS 'The language for which this Translator is responsible in this TranslationGroup. Note that the same person may be responsible for multiple languages, but any given language can only have one Translator within the TranslationGroup.';


COMMENT ON COLUMN translator.translator IS 'The Person who is responsible for this language in this translation group.';


COMMENT ON COLUMN translator.style_guide_url IS 'URL with translation style guide of a particular translation team.';


CREATE SEQUENCE translator_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE translator_id_seq OWNED BY translator.id;


CREATE TABLE usertouseremail (
    id integer NOT NULL,
    sender integer NOT NULL,
    recipient integer NOT NULL,
    date_sent timestamp without time zone DEFAULT timezone('UTC'::text, now()) NOT NULL,
    subject text NOT NULL,
    message_id text NOT NULL
);


COMMENT ON TABLE usertouseremail IS 'A log of all direct user-to-user email contacts that have gone through Launchpad.';


COMMENT ON COLUMN usertouseremail.sender IS 'The person sending this email.';


COMMENT ON COLUMN usertouseremail.recipient IS 'The person receiving this email.';


COMMENT ON COLUMN usertouseremail.date_sent IS 'The date the email was sent.';


COMMENT ON COLUMN usertouseremail.subject IS 'The Subject: header.';


COMMENT ON COLUMN usertouseremail.message_id IS 'The Message-ID: header.';


CREATE SEQUENCE usertouseremail_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE usertouseremail_id_seq OWNED BY usertouseremail.id;


CREATE VIEW validpersoncache AS
    SELECT emailaddress.person AS id FROM emailaddress, account WHERE ((((emailaddress.account = account.id) AND (emailaddress.person IS NOT NULL)) AND (emailaddress.status = 4)) AND (account.status = 20));


COMMENT ON VIEW validpersoncache IS 'A materialized view listing the Person.ids of all valid people (but not teams).';


CREATE VIEW validpersonorteamcache AS
    SELECT person.id FROM ((person LEFT JOIN emailaddress ON ((person.id = emailaddress.person))) LEFT JOIN account ON ((emailaddress.account = account.id))) WHERE (((person.teamowner IS NOT NULL) AND (person.merged IS NULL)) OR (((person.teamowner IS NULL) AND (account.status = 20)) AND (emailaddress.status = 4)));


CREATE TABLE vote (
    id integer NOT NULL,
    person integer,
    poll integer NOT NULL,
    preference integer,
    option integer,
    token text NOT NULL
);


COMMENT ON TABLE vote IS 'The table where we store the actual votes of people.  It may or may not have a reference to the person who voted, depending on the poll''s secrecy.';


COMMENT ON COLUMN vote.person IS 'The person who voted. It''s NULL for secret polls.';


COMMENT ON COLUMN vote.poll IS 'The poll for which this vote applies.';


COMMENT ON COLUMN vote.preference IS 'Used to identify in what order the options were chosen by a given user (in case of preferential voting).';


COMMENT ON COLUMN vote.option IS 'The choosen option.';


COMMENT ON COLUMN vote.token IS 'A unique token that''s give to the user so he can change his vote later.';


CREATE SEQUENCE vote_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE vote_id_seq OWNED BY vote.id;


CREATE TABLE votecast (
    id integer NOT NULL,
    person integer NOT NULL,
    poll integer NOT NULL
);


COMMENT ON TABLE votecast IS 'Here we store who has already voted in a poll, to ensure they do not vote again, and potentially to notify people that they may still vote.';


COMMENT ON COLUMN votecast.person IS 'The person who voted.';


COMMENT ON COLUMN votecast.poll IS 'The poll in which this person voted.';


CREATE SEQUENCE votecast_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE votecast_id_seq OWNED BY votecast.id;


CREATE TABLE wikiname (
    id integer NOT NULL,
    person integer NOT NULL,
    wiki text NOT NULL,
    wikiname text NOT NULL
);


CREATE SEQUENCE wikiname_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER SEQUENCE wikiname_id_seq OWNED BY wikiname.id;


ALTER TABLE accesspolicy ALTER COLUMN id SET DEFAULT nextval('accesspolicy_id_seq'::regclass);


ALTER TABLE accesspolicyartifact ALTER COLUMN id SET DEFAULT nextval('accesspolicyartifact_id_seq'::regclass);


ALTER TABLE accesspolicygrant ALTER COLUMN id SET DEFAULT nextval('accesspolicygrant_id_seq'::regclass);


ALTER TABLE account ALTER COLUMN id SET DEFAULT nextval('account_id_seq'::regclass);


ALTER TABLE accountpassword ALTER COLUMN id SET DEFAULT nextval('accountpassword_id_seq'::regclass);


ALTER TABLE announcement ALTER COLUMN id SET DEFAULT nextval('announcement_id_seq'::regclass);


ALTER TABLE answercontact ALTER COLUMN id SET DEFAULT nextval('answercontact_id_seq'::regclass);


ALTER TABLE apportjob ALTER COLUMN id SET DEFAULT nextval('apportjob_id_seq'::regclass);


ALTER TABLE archive ALTER COLUMN id SET DEFAULT nextval('archive_id_seq'::regclass);


ALTER TABLE archivearch ALTER COLUMN id SET DEFAULT nextval('archivearch_id_seq'::regclass);


ALTER TABLE archiveauthtoken ALTER COLUMN id SET DEFAULT nextval('archiveauthtoken_id_seq'::regclass);


ALTER TABLE archivedependency ALTER COLUMN id SET DEFAULT nextval('archivedependency_id_seq'::regclass);


ALTER TABLE archivejob ALTER COLUMN id SET DEFAULT nextval('archivejob_id_seq'::regclass);


ALTER TABLE archivepermission ALTER COLUMN id SET DEFAULT nextval('archivepermission_id_seq'::regclass);


ALTER TABLE archivesubscriber ALTER COLUMN id SET DEFAULT nextval('archivesubscriber_id_seq'::regclass);


ALTER TABLE binarypackagebuild ALTER COLUMN id SET DEFAULT nextval('binarypackagebuild_id_seq'::regclass);


ALTER TABLE binarypackagename ALTER COLUMN id SET DEFAULT nextval('binarypackagename_id_seq'::regclass);


ALTER TABLE binarypackagepath ALTER COLUMN id SET DEFAULT nextval('binarypackagepath_id_seq'::regclass);


ALTER TABLE binarypackagepublishinghistory ALTER COLUMN id SET DEFAULT nextval('binarypackagepublishinghistory_id_seq'::regclass);


ALTER TABLE binarypackagerelease ALTER COLUMN id SET DEFAULT nextval('binarypackagerelease_id_seq'::regclass);


ALTER TABLE binarypackagereleasedownloadcount ALTER COLUMN id SET DEFAULT nextval('binarypackagereleasedownloadcount_id_seq'::regclass);


ALTER TABLE branch ALTER COLUMN id SET DEFAULT nextval('branch_id_seq'::regclass);


ALTER TABLE branchjob ALTER COLUMN id SET DEFAULT nextval('branchjob_id_seq'::regclass);


ALTER TABLE branchmergeproposal ALTER COLUMN id SET DEFAULT nextval('branchmergeproposal_id_seq'::regclass);


ALTER TABLE branchmergeproposaljob ALTER COLUMN id SET DEFAULT nextval('branchmergeproposaljob_id_seq'::regclass);


ALTER TABLE branchmergequeue ALTER COLUMN id SET DEFAULT nextval('branchmergequeue_id_seq'::regclass);


ALTER TABLE branchsubscription ALTER COLUMN id SET DEFAULT nextval('branchsubscription_id_seq'::regclass);


ALTER TABLE branchvisibilitypolicy ALTER COLUMN id SET DEFAULT nextval('branchvisibilitypolicy_id_seq'::regclass);


ALTER TABLE bug ALTER COLUMN id SET DEFAULT nextval('bug_id_seq'::regclass);


ALTER TABLE bugactivity ALTER COLUMN id SET DEFAULT nextval('bugactivity_id_seq'::regclass);


ALTER TABLE bugaffectsperson ALTER COLUMN id SET DEFAULT nextval('bugaffectsperson_id_seq'::regclass);


ALTER TABLE bugattachment ALTER COLUMN id SET DEFAULT nextval('bugattachment_id_seq'::regclass);


ALTER TABLE bugbranch ALTER COLUMN id SET DEFAULT nextval('bugbranch_id_seq'::regclass);


ALTER TABLE bugcve ALTER COLUMN id SET DEFAULT nextval('bugcve_id_seq'::regclass);


ALTER TABLE bugjob ALTER COLUMN id SET DEFAULT nextval('bugjob_id_seq'::regclass);


ALTER TABLE bugmessage ALTER COLUMN id SET DEFAULT nextval('bugmessage_id_seq'::regclass);


ALTER TABLE bugnomination ALTER COLUMN id SET DEFAULT nextval('bugnomination_id_seq'::regclass);


ALTER TABLE bugnotification ALTER COLUMN id SET DEFAULT nextval('bugnotification_id_seq'::regclass);


ALTER TABLE bugnotificationattachment ALTER COLUMN id SET DEFAULT nextval('bugnotificationattachment_id_seq'::regclass);


ALTER TABLE bugnotificationrecipient ALTER COLUMN id SET DEFAULT nextval('bugnotificationrecipient_id_seq'::regclass);


ALTER TABLE bugsubscription ALTER COLUMN id SET DEFAULT nextval('bugsubscription_id_seq'::regclass);


ALTER TABLE bugsubscriptionfilter ALTER COLUMN id SET DEFAULT nextval('bugsubscriptionfilter_id_seq'::regclass);


ALTER TABLE bugsubscriptionfilterimportance ALTER COLUMN id SET DEFAULT nextval('bugsubscriptionfilterimportance_id_seq'::regclass);


ALTER TABLE bugsubscriptionfilterstatus ALTER COLUMN id SET DEFAULT nextval('bugsubscriptionfilterstatus_id_seq'::regclass);


ALTER TABLE bugsubscriptionfiltertag ALTER COLUMN id SET DEFAULT nextval('bugsubscriptionfiltertag_id_seq'::regclass);


ALTER TABLE bugsummary ALTER COLUMN id SET DEFAULT nextval('bugsummary_id_seq'::regclass);


ALTER TABLE bugsummaryjournal ALTER COLUMN id SET DEFAULT nextval('bugsummaryjournal_id_seq'::regclass);


ALTER TABLE bugtag ALTER COLUMN id SET DEFAULT nextval('bugtag_id_seq'::regclass);


ALTER TABLE bugtask ALTER COLUMN id SET DEFAULT nextval('bugtask_id_seq'::regclass);


ALTER TABLE bugtracker ALTER COLUMN id SET DEFAULT nextval('bugtracker_id_seq'::regclass);


ALTER TABLE bugtrackeralias ALTER COLUMN id SET DEFAULT nextval('bugtrackeralias_id_seq'::regclass);


ALTER TABLE bugtrackercomponent ALTER COLUMN id SET DEFAULT nextval('bugtrackercomponent_id_seq'::regclass);


ALTER TABLE bugtrackercomponentgroup ALTER COLUMN id SET DEFAULT nextval('bugtrackercomponentgroup_id_seq'::regclass);


ALTER TABLE bugtrackerperson ALTER COLUMN id SET DEFAULT nextval('bugtrackerperson_id_seq'::regclass);


ALTER TABLE bugwatch ALTER COLUMN id SET DEFAULT nextval('bugwatch_id_seq'::regclass);


ALTER TABLE bugwatchactivity ALTER COLUMN id SET DEFAULT nextval('bugwatchactivity_id_seq'::regclass);


ALTER TABLE builder ALTER COLUMN id SET DEFAULT nextval('builder_id_seq'::regclass);


ALTER TABLE buildfarmjob ALTER COLUMN id SET DEFAULT nextval('buildfarmjob_id_seq'::regclass);


ALTER TABLE buildpackagejob ALTER COLUMN id SET DEFAULT nextval('buildpackagejob_id_seq'::regclass);


ALTER TABLE buildqueue ALTER COLUMN id SET DEFAULT nextval('buildqueue_id_seq'::regclass);


ALTER TABLE codeimport ALTER COLUMN id SET DEFAULT nextval('codeimport_id_seq'::regclass);


ALTER TABLE codeimportevent ALTER COLUMN id SET DEFAULT nextval('codeimportevent_id_seq'::regclass);


ALTER TABLE codeimporteventdata ALTER COLUMN id SET DEFAULT nextval('codeimporteventdata_id_seq'::regclass);


ALTER TABLE codeimportjob ALTER COLUMN id SET DEFAULT nextval('codeimportjob_id_seq'::regclass);


ALTER TABLE codeimportmachine ALTER COLUMN id SET DEFAULT nextval('codeimportmachine_id_seq'::regclass);


ALTER TABLE codeimportresult ALTER COLUMN id SET DEFAULT nextval('codeimportresult_id_seq'::regclass);


ALTER TABLE codereviewmessage ALTER COLUMN id SET DEFAULT nextval('codereviewmessage_id_seq'::regclass);


ALTER TABLE codereviewvote ALTER COLUMN id SET DEFAULT nextval('codereviewvote_id_seq'::regclass);


ALTER TABLE commercialsubscription ALTER COLUMN id SET DEFAULT nextval('commercialsubscription_id_seq'::regclass);


ALTER TABLE component ALTER COLUMN id SET DEFAULT nextval('component_id_seq'::regclass);


ALTER TABLE componentselection ALTER COLUMN id SET DEFAULT nextval('componentselection_id_seq'::regclass);


ALTER TABLE continent ALTER COLUMN id SET DEFAULT nextval('continent_id_seq'::regclass);


ALTER TABLE country ALTER COLUMN id SET DEFAULT nextval('country_id_seq'::regclass);


ALTER TABLE customlanguagecode ALTER COLUMN id SET DEFAULT nextval('customlanguagecode_id_seq'::regclass);


ALTER TABLE cve ALTER COLUMN id SET DEFAULT nextval('cve_id_seq'::regclass);


ALTER TABLE cvereference ALTER COLUMN id SET DEFAULT nextval('cvereference_id_seq'::regclass);


ALTER TABLE diff ALTER COLUMN id SET DEFAULT nextval('diff_id_seq'::regclass);


ALTER TABLE distribution ALTER COLUMN id SET DEFAULT nextval('distribution_id_seq'::regclass);


ALTER TABLE distributionjob ALTER COLUMN id SET DEFAULT nextval('distributionjob_id_seq'::regclass);


ALTER TABLE distributionmirror ALTER COLUMN id SET DEFAULT nextval('distributionmirror_id_seq'::regclass);


ALTER TABLE distributionsourcepackage ALTER COLUMN id SET DEFAULT nextval('distributionsourcepackage_id_seq'::regclass);


ALTER TABLE distributionsourcepackagecache ALTER COLUMN id SET DEFAULT nextval('distributionsourcepackagecache_id_seq'::regclass);


ALTER TABLE distroarchseries ALTER COLUMN id SET DEFAULT nextval('distroarchseries_id_seq'::regclass);


ALTER TABLE distroseries ALTER COLUMN id SET DEFAULT nextval('distroseries_id_seq'::regclass);


ALTER TABLE distroseriesdifference ALTER COLUMN id SET DEFAULT nextval('distroseriesdifference_id_seq'::regclass);


ALTER TABLE distroseriesdifferencemessage ALTER COLUMN id SET DEFAULT nextval('distroseriesdifferencemessage_id_seq'::regclass);


ALTER TABLE distroserieslanguage ALTER COLUMN id SET DEFAULT nextval('distroserieslanguage_id_seq'::regclass);


ALTER TABLE distroseriespackagecache ALTER COLUMN id SET DEFAULT nextval('distroseriespackagecache_id_seq'::regclass);


ALTER TABLE distroseriesparent ALTER COLUMN id SET DEFAULT nextval('distroseriesparent_id_seq'::regclass);


ALTER TABLE emailaddress ALTER COLUMN id SET DEFAULT nextval('emailaddress_id_seq'::regclass);


ALTER TABLE entitlement ALTER COLUMN id SET DEFAULT nextval('entitlement_id_seq'::regclass);


ALTER TABLE faq ALTER COLUMN id SET DEFAULT nextval('faq_id_seq'::regclass);


ALTER TABLE featuredproject ALTER COLUMN id SET DEFAULT nextval('featuredproject_id_seq'::regclass);


ALTER TABLE featureflagchangelogentry ALTER COLUMN id SET DEFAULT nextval('featureflagchangelogentry_id_seq'::regclass);


ALTER TABLE flatpackagesetinclusion ALTER COLUMN id SET DEFAULT nextval('flatpackagesetinclusion_id_seq'::regclass);


ALTER TABLE fticache ALTER COLUMN id SET DEFAULT nextval('fticache_id_seq'::regclass);


ALTER TABLE gpgkey ALTER COLUMN id SET DEFAULT nextval('gpgkey_id_seq'::regclass);


ALTER TABLE hwdevice ALTER COLUMN id SET DEFAULT nextval('hwdevice_id_seq'::regclass);


ALTER TABLE hwdeviceclass ALTER COLUMN id SET DEFAULT nextval('hwdeviceclass_id_seq'::regclass);


ALTER TABLE hwdevicedriverlink ALTER COLUMN id SET DEFAULT nextval('hwdevicedriverlink_id_seq'::regclass);


ALTER TABLE hwdevicenamevariant ALTER COLUMN id SET DEFAULT nextval('hwdevicenamevariant_id_seq'::regclass);


ALTER TABLE hwdmihandle ALTER COLUMN id SET DEFAULT nextval('hwdmihandle_id_seq'::regclass);


ALTER TABLE hwdmivalue ALTER COLUMN id SET DEFAULT nextval('hwdmivalue_id_seq'::regclass);


ALTER TABLE hwdriver ALTER COLUMN id SET DEFAULT nextval('hwdriver_id_seq'::regclass);


ALTER TABLE hwsubmission ALTER COLUMN id SET DEFAULT nextval('hwsubmission_id_seq'::regclass);


ALTER TABLE hwsubmissionbug ALTER COLUMN id SET DEFAULT nextval('hwsubmissionbug_id_seq'::regclass);


ALTER TABLE hwsubmissiondevice ALTER COLUMN id SET DEFAULT nextval('hwsubmissiondevice_id_seq'::regclass);


ALTER TABLE hwsystemfingerprint ALTER COLUMN id SET DEFAULT nextval('hwsystemfingerprint_id_seq'::regclass);


ALTER TABLE hwtest ALTER COLUMN id SET DEFAULT nextval('hwtest_id_seq'::regclass);


ALTER TABLE hwtestanswer ALTER COLUMN id SET DEFAULT nextval('hwtestanswer_id_seq'::regclass);


ALTER TABLE hwtestanswerchoice ALTER COLUMN id SET DEFAULT nextval('hwtestanswerchoice_id_seq'::regclass);


ALTER TABLE hwtestanswercount ALTER COLUMN id SET DEFAULT nextval('hwtestanswercount_id_seq'::regclass);


ALTER TABLE hwtestanswercountdevice ALTER COLUMN id SET DEFAULT nextval('hwtestanswercountdevice_id_seq'::regclass);


ALTER TABLE hwtestanswerdevice ALTER COLUMN id SET DEFAULT nextval('hwtestanswerdevice_id_seq'::regclass);


ALTER TABLE hwvendorid ALTER COLUMN id SET DEFAULT nextval('hwvendorid_id_seq'::regclass);


ALTER TABLE hwvendorname ALTER COLUMN id SET DEFAULT nextval('hwvendorname_id_seq'::regclass);


ALTER TABLE incrementaldiff ALTER COLUMN id SET DEFAULT nextval('incrementaldiff_id_seq'::regclass);


ALTER TABLE ircid ALTER COLUMN id SET DEFAULT nextval('ircid_id_seq'::regclass);


ALTER TABLE jabberid ALTER COLUMN id SET DEFAULT nextval('jabberid_id_seq'::regclass);


ALTER TABLE job ALTER COLUMN id SET DEFAULT nextval('job_id_seq'::regclass);


ALTER TABLE karma ALTER COLUMN id SET DEFAULT nextval('karma_id_seq'::regclass);


ALTER TABLE karmaaction ALTER COLUMN id SET DEFAULT nextval('karmaaction_id_seq'::regclass);


ALTER TABLE karmacache ALTER COLUMN id SET DEFAULT nextval('karmacache_id_seq'::regclass);


ALTER TABLE karmacategory ALTER COLUMN id SET DEFAULT nextval('karmacategory_id_seq'::regclass);


ALTER TABLE karmatotalcache ALTER COLUMN id SET DEFAULT nextval('karmatotalcache_id_seq'::regclass);


ALTER TABLE language ALTER COLUMN id SET DEFAULT nextval('language_id_seq'::regclass);


ALTER TABLE languagepack ALTER COLUMN id SET DEFAULT nextval('languagepack_id_seq'::regclass);


ALTER TABLE launchpaddatabaseupdatelog ALTER COLUMN id SET DEFAULT nextval('launchpaddatabaseupdatelog_id_seq'::regclass);


ALTER TABLE launchpadstatistic ALTER COLUMN id SET DEFAULT nextval('launchpadstatistic_id_seq'::regclass);


ALTER TABLE libraryfilealias ALTER COLUMN id SET DEFAULT nextval('libraryfilealias_id_seq'::regclass);


ALTER TABLE libraryfilecontent ALTER COLUMN id SET DEFAULT nextval('libraryfilecontent_id_seq'::regclass);


ALTER TABLE libraryfiledownloadcount ALTER COLUMN id SET DEFAULT nextval('libraryfiledownloadcount_id_seq'::regclass);


ALTER TABLE logintoken ALTER COLUMN id SET DEFAULT nextval('logintoken_id_seq'::regclass);


ALTER TABLE mailinglist ALTER COLUMN id SET DEFAULT nextval('mailinglist_id_seq'::regclass);


ALTER TABLE mailinglistsubscription ALTER COLUMN id SET DEFAULT nextval('mailinglistsubscription_id_seq'::regclass);


ALTER TABLE mergedirectivejob ALTER COLUMN id SET DEFAULT nextval('mergedirectivejob_id_seq'::regclass);


ALTER TABLE message ALTER COLUMN id SET DEFAULT nextval('message_id_seq'::regclass);


ALTER TABLE messageapproval ALTER COLUMN id SET DEFAULT nextval('messageapproval_id_seq'::regclass);


ALTER TABLE messagechunk ALTER COLUMN id SET DEFAULT nextval('messagechunk_id_seq'::regclass);


ALTER TABLE milestone ALTER COLUMN id SET DEFAULT nextval('milestone_id_seq'::regclass);


ALTER TABLE mirror ALTER COLUMN id SET DEFAULT nextval('mirror_id_seq'::regclass);


ALTER TABLE mirrorcdimagedistroseries ALTER COLUMN id SET DEFAULT nextval('mirrorcdimagedistroseries_id_seq'::regclass);


ALTER TABLE mirrorcontent ALTER COLUMN id SET DEFAULT nextval('mirrorcontent_id_seq'::regclass);


ALTER TABLE mirrordistroarchseries ALTER COLUMN id SET DEFAULT nextval('mirrordistroarchseries_id_seq'::regclass);


ALTER TABLE mirrordistroseriessource ALTER COLUMN id SET DEFAULT nextval('mirrordistroseriessource_id_seq'::regclass);


ALTER TABLE mirrorproberecord ALTER COLUMN id SET DEFAULT nextval('mirrorproberecord_id_seq'::regclass);


ALTER TABLE mirrorsourcecontent ALTER COLUMN id SET DEFAULT nextval('mirrorsourcecontent_id_seq'::regclass);


ALTER TABLE nameblacklist ALTER COLUMN id SET DEFAULT nextval('nameblacklist_id_seq'::regclass);


ALTER TABLE oauthaccesstoken ALTER COLUMN id SET DEFAULT nextval('oauthaccesstoken_id_seq'::regclass);


ALTER TABLE oauthconsumer ALTER COLUMN id SET DEFAULT nextval('oauthconsumer_id_seq'::regclass);


ALTER TABLE oauthrequesttoken ALTER COLUMN id SET DEFAULT nextval('oauthrequesttoken_id_seq'::regclass);


ALTER TABLE officialbugtag ALTER COLUMN id SET DEFAULT nextval('officialbugtag_id_seq'::regclass);


ALTER TABLE packagebuild ALTER COLUMN id SET DEFAULT nextval('packagebuild_id_seq'::regclass);


ALTER TABLE packagecopyjob ALTER COLUMN id SET DEFAULT nextval('packagecopyjob_id_seq'::regclass);


ALTER TABLE packagecopyrequest ALTER COLUMN id SET DEFAULT nextval('packagecopyrequest_id_seq'::regclass);


ALTER TABLE packagediff ALTER COLUMN id SET DEFAULT nextval('packagediff_id_seq'::regclass);


ALTER TABLE packageset ALTER COLUMN id SET DEFAULT nextval('packageset_id_seq'::regclass);


ALTER TABLE packagesetgroup ALTER COLUMN id SET DEFAULT nextval('packagesetgroup_id_seq'::regclass);


ALTER TABLE packagesetinclusion ALTER COLUMN id SET DEFAULT nextval('packagesetinclusion_id_seq'::regclass);


ALTER TABLE packagesetsources ALTER COLUMN id SET DEFAULT nextval('packagesetsources_id_seq'::regclass);


ALTER TABLE packageupload ALTER COLUMN id SET DEFAULT nextval('packageupload_id_seq'::regclass);


ALTER TABLE packageuploadbuild ALTER COLUMN id SET DEFAULT nextval('packageuploadbuild_id_seq'::regclass);


ALTER TABLE packageuploadcustom ALTER COLUMN id SET DEFAULT nextval('packageuploadcustom_id_seq'::regclass);


ALTER TABLE packageuploadsource ALTER COLUMN id SET DEFAULT nextval('packageuploadsource_id_seq'::regclass);


ALTER TABLE packagingjob ALTER COLUMN id SET DEFAULT nextval('packagingjob_id_seq'::regclass);


ALTER TABLE parsedapachelog ALTER COLUMN id SET DEFAULT nextval('parsedapachelog_id_seq'::regclass);


ALTER TABLE person ALTER COLUMN id SET DEFAULT nextval('person_id_seq'::regclass);


ALTER TABLE personlanguage ALTER COLUMN id SET DEFAULT nextval('personlanguage_id_seq'::regclass);


ALTER TABLE personlocation ALTER COLUMN id SET DEFAULT nextval('personlocation_id_seq'::regclass);


ALTER TABLE personnotification ALTER COLUMN id SET DEFAULT nextval('personnotification_id_seq'::regclass);


ALTER TABLE persontransferjob ALTER COLUMN id SET DEFAULT nextval('persontransferjob_id_seq'::regclass);


ALTER TABLE pillarname ALTER COLUMN id SET DEFAULT nextval('pillarname_id_seq'::regclass);


ALTER TABLE pocketchroot ALTER COLUMN id SET DEFAULT nextval('pocketchroot_id_seq'::regclass);


ALTER TABLE poexportrequest ALTER COLUMN id SET DEFAULT nextval('poexportrequest_id_seq'::regclass);


ALTER TABLE pofile ALTER COLUMN id SET DEFAULT nextval('pofile_id_seq'::regclass);


ALTER TABLE pofiletranslator ALTER COLUMN id SET DEFAULT nextval('pofiletranslator_id_seq'::regclass);


ALTER TABLE poll ALTER COLUMN id SET DEFAULT nextval('poll_id_seq'::regclass);


ALTER TABLE polloption ALTER COLUMN id SET DEFAULT nextval('polloption_id_seq'::regclass);


ALTER TABLE pomsgid ALTER COLUMN id SET DEFAULT nextval('pomsgid_id_seq'::regclass);


ALTER TABLE potemplate ALTER COLUMN id SET DEFAULT nextval('potemplate_id_seq'::regclass);


ALTER TABLE potmsgset ALTER COLUMN id SET DEFAULT nextval('potmsgset_id_seq'::regclass);


ALTER TABLE potranslation ALTER COLUMN id SET DEFAULT nextval('potranslation_id_seq'::regclass);


ALTER TABLE previewdiff ALTER COLUMN id SET DEFAULT nextval('previewdiff_id_seq'::regclass);


ALTER TABLE processor ALTER COLUMN id SET DEFAULT nextval('processor_id_seq'::regclass);


ALTER TABLE processorfamily ALTER COLUMN id SET DEFAULT nextval('processorfamily_id_seq'::regclass);


ALTER TABLE product ALTER COLUMN id SET DEFAULT nextval('product_id_seq'::regclass);


ALTER TABLE productlicense ALTER COLUMN id SET DEFAULT nextval('productlicense_id_seq'::regclass);


ALTER TABLE productrelease ALTER COLUMN id SET DEFAULT nextval('productrelease_id_seq'::regclass);


ALTER TABLE productseries ALTER COLUMN id SET DEFAULT nextval('productseries_id_seq'::regclass);


ALTER TABLE project ALTER COLUMN id SET DEFAULT nextval('project_id_seq'::regclass);


ALTER TABLE publisherconfig ALTER COLUMN id SET DEFAULT nextval('publisherconfig_id_seq'::regclass);


ALTER TABLE question ALTER COLUMN id SET DEFAULT nextval('question_id_seq'::regclass);


ALTER TABLE questionbug ALTER COLUMN id SET DEFAULT nextval('questionbug_id_seq'::regclass);


ALTER TABLE questionjob ALTER COLUMN id SET DEFAULT nextval('questionjob_id_seq'::regclass);


ALTER TABLE questionmessage ALTER COLUMN id SET DEFAULT nextval('questionmessage_id_seq'::regclass);


ALTER TABLE questionreopening ALTER COLUMN id SET DEFAULT nextval('questionreopening_id_seq'::regclass);


ALTER TABLE questionsubscription ALTER COLUMN id SET DEFAULT nextval('questionsubscription_id_seq'::regclass);


ALTER TABLE revision ALTER COLUMN id SET DEFAULT nextval('revision_id_seq'::regclass);


ALTER TABLE revisionauthor ALTER COLUMN id SET DEFAULT nextval('revisionauthor_id_seq'::regclass);


ALTER TABLE revisioncache ALTER COLUMN id SET DEFAULT nextval('revisioncache_id_seq'::regclass);


ALTER TABLE revisionparent ALTER COLUMN id SET DEFAULT nextval('revisionparent_id_seq'::regclass);


ALTER TABLE revisionproperty ALTER COLUMN id SET DEFAULT nextval('revisionproperty_id_seq'::regclass);


ALTER TABLE scriptactivity ALTER COLUMN id SET DEFAULT nextval('scriptactivity_id_seq'::regclass);


ALTER TABLE section ALTER COLUMN id SET DEFAULT nextval('section_id_seq'::regclass);


ALTER TABLE sectionselection ALTER COLUMN id SET DEFAULT nextval('sectionselection_id_seq'::regclass);


ALTER TABLE seriessourcepackagebranch ALTER COLUMN id SET DEFAULT nextval('seriessourcepackagebranch_id_seq'::regclass);


ALTER TABLE signedcodeofconduct ALTER COLUMN id SET DEFAULT nextval('signedcodeofconduct_id_seq'::regclass);


ALTER TABLE sourcepackageformatselection ALTER COLUMN id SET DEFAULT nextval('sourcepackageformatselection_id_seq'::regclass);


ALTER TABLE sourcepackagename ALTER COLUMN id SET DEFAULT nextval('sourcepackagename_id_seq'::regclass);


ALTER TABLE sourcepackagepublishinghistory ALTER COLUMN id SET DEFAULT nextval('sourcepackagepublishinghistory_id_seq'::regclass);


ALTER TABLE sourcepackagerecipe ALTER COLUMN id SET DEFAULT nextval('sourcepackagerecipe_id_seq'::regclass);


ALTER TABLE sourcepackagerecipebuild ALTER COLUMN id SET DEFAULT nextval('sourcepackagerecipebuild_id_seq'::regclass);


ALTER TABLE sourcepackagerecipebuildjob ALTER COLUMN id SET DEFAULT nextval('sourcepackagerecipebuildjob_id_seq'::regclass);


ALTER TABLE sourcepackagerecipedata ALTER COLUMN id SET DEFAULT nextval('sourcepackagerecipedata_id_seq'::regclass);


ALTER TABLE sourcepackagerecipedatainstruction ALTER COLUMN id SET DEFAULT nextval('sourcepackagerecipedatainstruction_id_seq'::regclass);


ALTER TABLE sourcepackagerecipedistroseries ALTER COLUMN id SET DEFAULT nextval('sourcepackagerecipedistroseries_id_seq'::regclass);


ALTER TABLE sourcepackagerelease ALTER COLUMN id SET DEFAULT nextval('sourcepackagerelease_id_seq'::regclass);


ALTER TABLE specification ALTER COLUMN id SET DEFAULT nextval('specification_id_seq'::regclass);


ALTER TABLE specificationbranch ALTER COLUMN id SET DEFAULT nextval('specificationbranch_id_seq'::regclass);


ALTER TABLE specificationbug ALTER COLUMN id SET DEFAULT nextval('specificationbug_id_seq'::regclass);


ALTER TABLE specificationdependency ALTER COLUMN id SET DEFAULT nextval('specificationdependency_id_seq'::regclass);


ALTER TABLE specificationfeedback ALTER COLUMN id SET DEFAULT nextval('specificationfeedback_id_seq'::regclass);


ALTER TABLE specificationmessage ALTER COLUMN id SET DEFAULT nextval('specificationmessage_id_seq'::regclass);


ALTER TABLE specificationsubscription ALTER COLUMN id SET DEFAULT nextval('specificationsubscription_id_seq'::regclass);


ALTER TABLE sprint ALTER COLUMN id SET DEFAULT nextval('sprint_id_seq'::regclass);


ALTER TABLE sprintattendance ALTER COLUMN id SET DEFAULT nextval('sprintattendance_id_seq'::regclass);


ALTER TABLE sprintspecification ALTER COLUMN id SET DEFAULT nextval('sprintspecification_id_seq'::regclass);


ALTER TABLE sshkey ALTER COLUMN id SET DEFAULT nextval('sshkey_id_seq'::regclass);


ALTER TABLE structuralsubscription ALTER COLUMN id SET DEFAULT nextval('structuralsubscription_id_seq'::regclass);


ALTER TABLE subunitstream ALTER COLUMN id SET DEFAULT nextval('subunitstream_id_seq'::regclass);


ALTER TABLE teammembership ALTER COLUMN id SET DEFAULT nextval('teammembership_id_seq'::regclass);


ALTER TABLE teamparticipation ALTER COLUMN id SET DEFAULT nextval('teamparticipation_id_seq'::regclass);


ALTER TABLE temporaryblobstorage ALTER COLUMN id SET DEFAULT nextval('temporaryblobstorage_id_seq'::regclass);


ALTER TABLE translationgroup ALTER COLUMN id SET DEFAULT nextval('translationgroup_id_seq'::regclass);


ALTER TABLE translationimportqueueentry ALTER COLUMN id SET DEFAULT nextval('translationimportqueueentry_id_seq'::regclass);


ALTER TABLE translationmessage ALTER COLUMN id SET DEFAULT nextval('translationmessage_id_seq'::regclass);


ALTER TABLE translationrelicensingagreement ALTER COLUMN id SET DEFAULT nextval('translationrelicensingagreement_id_seq'::regclass);


ALTER TABLE translationtemplateitem ALTER COLUMN id SET DEFAULT nextval('translationtemplateitem_id_seq'::regclass);


ALTER TABLE translationtemplatesbuild ALTER COLUMN id SET DEFAULT nextval('translationtemplatesbuild_id_seq'::regclass);


ALTER TABLE translator ALTER COLUMN id SET DEFAULT nextval('translator_id_seq'::regclass);


ALTER TABLE usertouseremail ALTER COLUMN id SET DEFAULT nextval('usertouseremail_id_seq'::regclass);


ALTER TABLE vote ALTER COLUMN id SET DEFAULT nextval('vote_id_seq'::regclass);


ALTER TABLE votecast ALTER COLUMN id SET DEFAULT nextval('votecast_id_seq'::regclass);


ALTER TABLE wikiname ALTER COLUMN id SET DEFAULT nextval('wikiname_id_seq'::regclass);


ALTER TABLE ONLY accesspolicy
    ADD CONSTRAINT accesspolicy_pkey PRIMARY KEY (id);


ALTER TABLE ONLY accesspolicyartifact
    ADD CONSTRAINT accesspolicyartifact_pkey PRIMARY KEY (id);


ALTER TABLE ONLY accesspolicygrant
    ADD CONSTRAINT accesspolicygrant_pkey PRIMARY KEY (id);


ALTER TABLE ONLY account
    ADD CONSTRAINT account_pkey PRIMARY KEY (id);


ALTER TABLE ONLY accountpassword
    ADD CONSTRAINT accountpassword_account_key UNIQUE (account);


ALTER TABLE ONLY accountpassword
    ADD CONSTRAINT accountpassword_pkey PRIMARY KEY (id);


ALTER TABLE ONLY announcement
    ADD CONSTRAINT announcement_pkey PRIMARY KEY (id);


ALTER TABLE ONLY apportjob
    ADD CONSTRAINT apportjob__job__key UNIQUE (job);


ALTER TABLE ONLY apportjob
    ADD CONSTRAINT apportjob_pkey PRIMARY KEY (id);

ALTER TABLE apportjob CLUSTER ON apportjob_pkey;


ALTER TABLE ONLY archive
    ADD CONSTRAINT archive_pkey PRIMARY KEY (id);


ALTER TABLE ONLY archivearch
    ADD CONSTRAINT archivearch__processorfamily__archive__key UNIQUE (processorfamily, archive);


ALTER TABLE ONLY archivearch
    ADD CONSTRAINT archivearch_pkey PRIMARY KEY (id);


ALTER TABLE ONLY archiveauthtoken
    ADD CONSTRAINT archiveauthtoken_pkey PRIMARY KEY (id);


ALTER TABLE ONLY archiveauthtoken
    ADD CONSTRAINT archiveauthtoken_token_key UNIQUE (token);


ALTER TABLE ONLY archivedependency
    ADD CONSTRAINT archivedependency__unique UNIQUE (archive, dependency);


ALTER TABLE ONLY archivedependency
    ADD CONSTRAINT archivedependency_pkey PRIMARY KEY (id);


ALTER TABLE ONLY archivejob
    ADD CONSTRAINT archivejob__job__key UNIQUE (job);


ALTER TABLE ONLY archivejob
    ADD CONSTRAINT archivejob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY archivepermission
    ADD CONSTRAINT archivepermission_pkey PRIMARY KEY (id);


ALTER TABLE ONLY archivesubscriber
    ADD CONSTRAINT archivesubscriber_pkey PRIMARY KEY (id);


ALTER TABLE ONLY revisionauthor
    ADD CONSTRAINT archuserid_archuserid_key UNIQUE (name);


ALTER TABLE ONLY revisionauthor
    ADD CONSTRAINT archuserid_pkey PRIMARY KEY (id);


ALTER TABLE ONLY binarypackagerelease
    ADD CONSTRAINT binarypackage_pkey PRIMARY KEY (id);


ALTER TABLE ONLY binarypackagebuild
    ADD CONSTRAINT binarypackagebuild_pkey PRIMARY KEY (id);


ALTER TABLE ONLY binarypackagefile
    ADD CONSTRAINT binarypackagefile_pkey PRIMARY KEY (id);


ALTER TABLE ONLY binarypackagename
    ADD CONSTRAINT binarypackagename_name_key UNIQUE (name);


ALTER TABLE ONLY binarypackagename
    ADD CONSTRAINT binarypackagename_pkey PRIMARY KEY (id);


ALTER TABLE ONLY binarypackagepath
    ADD CONSTRAINT binarypackagepath_path_key UNIQUE (path);


ALTER TABLE ONLY binarypackagepath
    ADD CONSTRAINT binarypackagepath_pkey PRIMARY KEY (id);


ALTER TABLE ONLY binarypackagerelease
    ADD CONSTRAINT binarypackagerelease_binarypackagename_key UNIQUE (binarypackagename, build, version);


ALTER TABLE ONLY binarypackagerelease
    ADD CONSTRAINT binarypackagerelease_build_name_uniq UNIQUE (build, binarypackagename);


ALTER TABLE ONLY binarypackagereleasecontents
    ADD CONSTRAINT binarypackagereleasecontents_pkey PRIMARY KEY (binarypackagerelease, binarypackagepath);


ALTER TABLE ONLY binarypackagereleasedownloadcount
    ADD CONSTRAINT binarypackagereleasedownloadcount__archive__binary_package_rele UNIQUE (archive, binary_package_release, day, country);


ALTER TABLE ONLY binarypackagereleasedownloadcount
    ADD CONSTRAINT binarypackagereleasedownloadcount_pkey PRIMARY KEY (id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch__unique_name__key UNIQUE (unique_name);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_pkey PRIMARY KEY (id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_url_unique UNIQUE (url);


ALTER TABLE ONLY branchjob
    ADD CONSTRAINT branchjob_job_key UNIQUE (job);


ALTER TABLE ONLY branchjob
    ADD CONSTRAINT branchjob_pkey PRIMARY KEY (id);

ALTER TABLE branchjob CLUSTER ON branchjob_pkey;


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_pkey PRIMARY KEY (id);


ALTER TABLE ONLY branchmergeproposaljob
    ADD CONSTRAINT branchmergeproposaljob_job_key UNIQUE (job);


ALTER TABLE ONLY branchmergeproposaljob
    ADD CONSTRAINT branchmergeproposaljob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY branchmergequeue
    ADD CONSTRAINT branchmergequeue_pkey PRIMARY KEY (id);


ALTER TABLE ONLY branchsubscription
    ADD CONSTRAINT branchsubscription__person__branch__key UNIQUE (person, branch);


ALTER TABLE ONLY branchsubscription
    ADD CONSTRAINT branchsubscription_pkey PRIMARY KEY (id);


ALTER TABLE ONLY branchvisibilitypolicy
    ADD CONSTRAINT branchvisibilitypolicy_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugbranch
    ADD CONSTRAINT bug_branch_unique UNIQUE (bug, branch);


ALTER TABLE ONLY bug
    ADD CONSTRAINT bug_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugactivity
    ADD CONSTRAINT bugactivity_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugaffectsperson
    ADD CONSTRAINT bugaffectsperson_bug_person_uniq UNIQUE (bug, person);


ALTER TABLE ONLY bugaffectsperson
    ADD CONSTRAINT bugaffectsperson_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugattachment
    ADD CONSTRAINT bugattachment_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugbranch
    ADD CONSTRAINT bugbranch_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugcve
    ADD CONSTRAINT bugcve_bug_cve_uniq UNIQUE (bug, cve);


ALTER TABLE ONLY bugcve
    ADD CONSTRAINT bugcve_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugjob
    ADD CONSTRAINT bugjob__job__key UNIQUE (job);


ALTER TABLE ONLY bugjob
    ADD CONSTRAINT bugjob_pkey PRIMARY KEY (id);

ALTER TABLE bugjob CLUSTER ON bugjob_pkey;


ALTER TABLE ONLY bugmessage
    ADD CONSTRAINT bugmessage__bug__index__key UNIQUE (bug, index);


ALTER TABLE ONLY bugmessage
    ADD CONSTRAINT bugmessage__bug__message__key UNIQUE (bug, message);


ALTER TABLE ONLY bugmessage
    ADD CONSTRAINT bugmessage__bugwatch__remote_comment_id__key UNIQUE (bugwatch, remote_comment_id);


ALTER TABLE ONLY bugmessage
    ADD CONSTRAINT bugmessage_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugmute
    ADD CONSTRAINT bugmute_pkey PRIMARY KEY (person, bug);


ALTER TABLE ONLY bugnomination
    ADD CONSTRAINT bugnomination_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugnotification
    ADD CONSTRAINT bugnotification__bug__message__unq UNIQUE (bug, message);


ALTER TABLE ONLY bugnotification
    ADD CONSTRAINT bugnotification_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugnotificationarchive
    ADD CONSTRAINT bugnotificationarchive__bug__message__key UNIQUE (bug, message);


ALTER TABLE ONLY bugnotificationarchive
    ADD CONSTRAINT bugnotificationarchive_pk PRIMARY KEY (id);


ALTER TABLE ONLY bugnotificationattachment
    ADD CONSTRAINT bugnotificationattachment_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugnotificationfilter
    ADD CONSTRAINT bugnotificationfilter_pkey PRIMARY KEY (bug_notification, bug_subscription_filter);


ALTER TABLE ONLY bugnotificationrecipient
    ADD CONSTRAINT bugnotificationrecipient__bug_notificaion__person__key UNIQUE (bug_notification, person);


ALTER TABLE ONLY bugnotificationrecipient
    ADD CONSTRAINT bugnotificationrecipient_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugnotificationrecipientarchive
    ADD CONSTRAINT bugnotificationrecipientarchive_pk PRIMARY KEY (id);


ALTER TABLE ONLY bugsubscription
    ADD CONSTRAINT bugsubscription_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugsubscriptionfilter
    ADD CONSTRAINT bugsubscriptionfilter_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugsubscriptionfilterimportance
    ADD CONSTRAINT bugsubscriptionfilterimportance_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugsubscriptionfiltermute
    ADD CONSTRAINT bugsubscriptionfiltermute_pkey PRIMARY KEY (person, filter);


ALTER TABLE ONLY bugsubscriptionfilterstatus
    ADD CONSTRAINT bugsubscriptionfilterstatus_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugsubscriptionfiltertag
    ADD CONSTRAINT bugsubscriptionfiltertag_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugsummary
    ADD CONSTRAINT bugsummary_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugsummaryjournal
    ADD CONSTRAINT bugsummaryjournal_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugtracker
    ADD CONSTRAINT bugsystem_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugtag
    ADD CONSTRAINT bugtag__tag__bug__key UNIQUE (tag, bug);


ALTER TABLE ONLY bugtag
    ADD CONSTRAINT bugtag_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugtrackeralias
    ADD CONSTRAINT bugtracker__base_url__key UNIQUE (base_url);


ALTER TABLE ONLY bugtrackeralias
    ADD CONSTRAINT bugtrackeralias_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugtrackercomponent
    ADD CONSTRAINT bugtrackercomponent__component_group__name__key UNIQUE (component_group, name);


ALTER TABLE ONLY bugtrackercomponent
    ADD CONSTRAINT bugtrackercomponent__disto__spn__key UNIQUE (distribution, source_package_name);


ALTER TABLE ONLY bugtrackercomponent
    ADD CONSTRAINT bugtrackercomponent_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugtrackercomponentgroup
    ADD CONSTRAINT bugtrackercomponentgroup__bug_tracker__name__key UNIQUE (bug_tracker, name);


ALTER TABLE ONLY bugtrackercomponentgroup
    ADD CONSTRAINT bugtrackercomponentgroup_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugtrackerperson
    ADD CONSTRAINT bugtrackerperson__bugtracker__name__key UNIQUE (bugtracker, name);


ALTER TABLE ONLY bugtrackerperson
    ADD CONSTRAINT bugtrackerperson_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugwatch
    ADD CONSTRAINT bugwatch_bugtask_target UNIQUE (id, bug);


ALTER TABLE ONLY bugwatch
    ADD CONSTRAINT bugwatch_pkey PRIMARY KEY (id);


ALTER TABLE ONLY bugwatchactivity
    ADD CONSTRAINT bugwatchactivity_pkey PRIMARY KEY (id);


ALTER TABLE ONLY builder
    ADD CONSTRAINT builder_pkey PRIMARY KEY (id);


ALTER TABLE ONLY builder
    ADD CONSTRAINT builder_url_key UNIQUE (url);


ALTER TABLE ONLY buildfarmjob
    ADD CONSTRAINT buildfarmjob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY buildpackagejob
    ADD CONSTRAINT buildpackagejob__build__key UNIQUE (build);


ALTER TABLE ONLY buildpackagejob
    ADD CONSTRAINT buildpackagejob__job__key UNIQUE (job);


ALTER TABLE ONLY buildpackagejob
    ADD CONSTRAINT buildpackagejob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY buildqueue
    ADD CONSTRAINT buildqueue__job__key UNIQUE (job);


ALTER TABLE ONLY buildqueue
    ADD CONSTRAINT buildqueue_pkey PRIMARY KEY (id);


ALTER TABLE ONLY revision
    ADD CONSTRAINT changeset_pkey PRIMARY KEY (id);


ALTER TABLE ONLY codeimport
    ADD CONSTRAINT codeimport_branch_key UNIQUE (branch);


ALTER TABLE ONLY codeimport
    ADD CONSTRAINT codeimport_pkey PRIMARY KEY (id);


ALTER TABLE ONLY codeimportevent
    ADD CONSTRAINT codeimportevent_pkey PRIMARY KEY (id);


ALTER TABLE ONLY codeimporteventdata
    ADD CONSTRAINT codeimporteventdata__event__data_type__key UNIQUE (event, data_type);


ALTER TABLE ONLY codeimporteventdata
    ADD CONSTRAINT codeimporteventdata_pkey PRIMARY KEY (id);


ALTER TABLE ONLY codeimportjob
    ADD CONSTRAINT codeimportjob__code_import__key UNIQUE (code_import);


ALTER TABLE ONLY codeimportjob
    ADD CONSTRAINT codeimportjob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY codeimportmachine
    ADD CONSTRAINT codeimportmachine_hostname_key UNIQUE (hostname);


ALTER TABLE ONLY codeimportmachine
    ADD CONSTRAINT codeimportmachine_pkey PRIMARY KEY (id);


ALTER TABLE ONLY codeimportresult
    ADD CONSTRAINT codeimportresult_pkey PRIMARY KEY (id);


ALTER TABLE ONLY codereviewmessage
    ADD CONSTRAINT codereviewmessage__branch_merge_proposal__id_key UNIQUE (branch_merge_proposal, id);


ALTER TABLE ONLY codereviewmessage
    ADD CONSTRAINT codereviewmessage_message_key UNIQUE (message);


ALTER TABLE ONLY codereviewmessage
    ADD CONSTRAINT codereviewmessage_pkey PRIMARY KEY (id);


ALTER TABLE ONLY codereviewvote
    ADD CONSTRAINT codereviewvote_pkey PRIMARY KEY (id);


ALTER TABLE ONLY commercialsubscription
    ADD CONSTRAINT commercialsubscription_pkey PRIMARY KEY (id);


ALTER TABLE ONLY component
    ADD CONSTRAINT component_name_key UNIQUE (name);


ALTER TABLE ONLY component
    ADD CONSTRAINT component_pkey PRIMARY KEY (id);


ALTER TABLE ONLY componentselection
    ADD CONSTRAINT componentselection__distroseries__component__key UNIQUE (distroseries, component);


ALTER TABLE ONLY componentselection
    ADD CONSTRAINT componentselection_pkey PRIMARY KEY (id);


ALTER TABLE ONLY continent
    ADD CONSTRAINT continent_code_key UNIQUE (code);


ALTER TABLE ONLY continent
    ADD CONSTRAINT continent_name_key UNIQUE (name);


ALTER TABLE ONLY continent
    ADD CONSTRAINT continent_pkey PRIMARY KEY (id);


ALTER TABLE ONLY country
    ADD CONSTRAINT country_code2_uniq UNIQUE (iso3166code2);


ALTER TABLE ONLY country
    ADD CONSTRAINT country_code3_uniq UNIQUE (iso3166code3);


ALTER TABLE ONLY country
    ADD CONSTRAINT country_name_uniq UNIQUE (name);


ALTER TABLE ONLY country
    ADD CONSTRAINT country_pkey PRIMARY KEY (id);


ALTER TABLE ONLY customlanguagecode
    ADD CONSTRAINT customlanguagecode_pkey PRIMARY KEY (id);


ALTER TABLE ONLY cve
    ADD CONSTRAINT cve_pkey PRIMARY KEY (id);


ALTER TABLE ONLY cve
    ADD CONSTRAINT cve_sequence_uniq UNIQUE (sequence);


ALTER TABLE ONLY cvereference
    ADD CONSTRAINT cvereference_pkey PRIMARY KEY (id);


ALTER TABLE ONLY databasecpustats
    ADD CONSTRAINT databasecpustats_pkey PRIMARY KEY (date_created, username);


ALTER TABLE ONLY databasediskutilization
    ADD CONSTRAINT databasediskutilization_pkey PRIMARY KEY (date_created, sort);


ALTER TABLE ONLY databasereplicationlag
    ADD CONSTRAINT databasereplicationlag_pkey PRIMARY KEY (node);


ALTER TABLE ONLY databasetablestats
    ADD CONSTRAINT databasetablestats_pkey PRIMARY KEY (date_created, schemaname, relname);

ALTER TABLE databasetablestats CLUSTER ON databasetablestats_pkey;


ALTER TABLE ONLY diff
    ADD CONSTRAINT diff_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution_name_key UNIQUE (name);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distributionjob
    ADD CONSTRAINT distributionjob__job__key UNIQUE (job);


ALTER TABLE ONLY distributionjob
    ADD CONSTRAINT distributionjob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distributionmirror
    ADD CONSTRAINT distributionmirror_ftp_base_url_key UNIQUE (ftp_base_url);


ALTER TABLE ONLY distributionmirror
    ADD CONSTRAINT distributionmirror_http_base_url_key UNIQUE (http_base_url);


ALTER TABLE ONLY distributionmirror
    ADD CONSTRAINT distributionmirror_name_key UNIQUE (name);


ALTER TABLE ONLY distributionmirror
    ADD CONSTRAINT distributionmirror_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distributionmirror
    ADD CONSTRAINT distributionmirror_rsync_base_url_key UNIQUE (rsync_base_url);


ALTER TABLE ONLY distributionsourcepackage
    ADD CONSTRAINT distributionpackage__sourcepackagename__distribution__key UNIQUE (sourcepackagename, distribution);

ALTER TABLE distributionsourcepackage CLUSTER ON distributionpackage__sourcepackagename__distribution__key;


ALTER TABLE ONLY distributionsourcepackage
    ADD CONSTRAINT distributionsourcepackage_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distributionsourcepackagecache
    ADD CONSTRAINT distributionsourcepackagecache__distribution__sourcepackagename UNIQUE (distribution, sourcepackagename, archive);


ALTER TABLE ONLY distributionsourcepackagecache
    ADD CONSTRAINT distributionsourcepackagecache_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distroarchseries
    ADD CONSTRAINT distroarchrelease_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distroarchseries
    ADD CONSTRAINT distroarchseries__architecturetag__distroseries__key UNIQUE (architecturetag, distroseries);


ALTER TABLE ONLY distroarchseries
    ADD CONSTRAINT distroarchseries__processorfamily__distroseries__key UNIQUE (processorfamily, distroseries);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distrorelease__distribution__name__key UNIQUE (distribution, name);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distrorelease_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distroserieslanguage
    ADD CONSTRAINT distroreleaselanguage_distrorelease_language_uniq UNIQUE (distroseries, language);


ALTER TABLE ONLY distroserieslanguage
    ADD CONSTRAINT distroreleaselanguage_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distroseriespackagecache
    ADD CONSTRAINT distroreleasepackagecache_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packageupload
    ADD CONSTRAINT distroreleasequeue_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packageuploadbuild
    ADD CONSTRAINT distroreleasequeuebuild__distroreleasequeue__build__unique UNIQUE (packageupload, build);


ALTER TABLE ONLY packageuploadbuild
    ADD CONSTRAINT distroreleasequeuebuild_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packageuploadcustom
    ADD CONSTRAINT distroreleasequeuecustom_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packageuploadsource
    ADD CONSTRAINT distroreleasequeuesource_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distroseries__distribution__id__key UNIQUE (distribution, id);


ALTER TABLE ONLY distroseriesdifference
    ADD CONSTRAINT distroseriesdifference__derived_series__parent_series__source_p UNIQUE (derived_series, parent_series, source_package_name);


ALTER TABLE ONLY distroseriesdifference
    ADD CONSTRAINT distroseriesdifference_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distroseriesdifferencemessage
    ADD CONSTRAINT distroseriesdifferencemessage_message_key UNIQUE (message);


ALTER TABLE ONLY distroseriesdifferencemessage
    ADD CONSTRAINT distroseriesdifferencemessage_pkey PRIMARY KEY (id);


ALTER TABLE ONLY distroseriespackagecache
    ADD CONSTRAINT distroseriespackagecache__distroseries__binarypackagename__arch UNIQUE (distroseries, binarypackagename, archive);


ALTER TABLE ONLY distroseriesparent
    ADD CONSTRAINT distroseriesparent_pkey PRIMARY KEY (id);


ALTER TABLE ONLY emailaddress
    ADD CONSTRAINT emailaddress_pkey PRIMARY KEY (id);


ALTER TABLE ONLY entitlement
    ADD CONSTRAINT entitlement_pkey PRIMARY KEY (id);


ALTER TABLE ONLY faq
    ADD CONSTRAINT faq_pkey PRIMARY KEY (id);


ALTER TABLE ONLY featureflag
    ADD CONSTRAINT feature_flag_pkey PRIMARY KEY (scope, flag);


ALTER TABLE ONLY featureflag
    ADD CONSTRAINT feature_flag_unique_priority_per_flag UNIQUE (flag, priority);


ALTER TABLE ONLY featuredproject
    ADD CONSTRAINT featuredproject_pkey PRIMARY KEY (id);


ALTER TABLE ONLY featureflagchangelogentry
    ADD CONSTRAINT featureflagchangelogentry_pkey PRIMARY KEY (id);


ALTER TABLE ONLY flatpackagesetinclusion
    ADD CONSTRAINT flatpackagesetinclusion__parent__child__key UNIQUE (parent, child);


ALTER TABLE ONLY flatpackagesetinclusion
    ADD CONSTRAINT flatpackagesetinclusion_pkey PRIMARY KEY (id);


ALTER TABLE ONLY fticache
    ADD CONSTRAINT fticache_pkey PRIMARY KEY (id);


ALTER TABLE ONLY fticache
    ADD CONSTRAINT fticache_tablename_key UNIQUE (tablename);


ALTER TABLE ONLY gpgkey
    ADD CONSTRAINT gpgkey_fingerprint_key UNIQUE (fingerprint);


ALTER TABLE ONLY gpgkey
    ADD CONSTRAINT gpgkey_owner_key UNIQUE (owner, id);


ALTER TABLE ONLY gpgkey
    ADD CONSTRAINT gpgkey_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwdevice
    ADD CONSTRAINT hwdevice__bus_vendor_id__bus_product_id__variant__key UNIQUE (bus_vendor_id, bus_product_id, variant);


ALTER TABLE ONLY hwdevice
    ADD CONSTRAINT hwdevice_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwdeviceclass
    ADD CONSTRAINT hwdeviceclass_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwdevicedriverlink
    ADD CONSTRAINT hwdevicedriverlink_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwdevicenamevariant
    ADD CONSTRAINT hwdevicenamevariant__vendor_name__product_name__device__key UNIQUE (vendor_name, product_name, device);


ALTER TABLE ONLY hwdevicenamevariant
    ADD CONSTRAINT hwdevicenamevariant_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwdmihandle
    ADD CONSTRAINT hwdmihandle_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwdmivalue
    ADD CONSTRAINT hwdmivalue_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwdriver
    ADD CONSTRAINT hwdriver__package_name__name__key UNIQUE (package_name, name);


ALTER TABLE ONLY hwdriver
    ADD CONSTRAINT hwdriver_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwsubmission
    ADD CONSTRAINT hwsubmission__submission_key__key UNIQUE (submission_key);


ALTER TABLE ONLY hwsubmission
    ADD CONSTRAINT hwsubmission_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwsubmissionbug
    ADD CONSTRAINT hwsubmissionbug__submission__bug__key UNIQUE (submission, bug);


ALTER TABLE ONLY hwsubmissionbug
    ADD CONSTRAINT hwsubmissionbug_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwsubmissiondevice
    ADD CONSTRAINT hwsubmissiondevice_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwsystemfingerprint
    ADD CONSTRAINT hwsystemfingerprint__fingerprint__key UNIQUE (fingerprint);


ALTER TABLE ONLY hwsystemfingerprint
    ADD CONSTRAINT hwsystemfingerprint_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwtest
    ADD CONSTRAINT hwtest_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwtestanswer
    ADD CONSTRAINT hwtestanswer_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwtestanswerchoice
    ADD CONSTRAINT hwtestanswerchoice__choice__test__key UNIQUE (choice, test);


ALTER TABLE ONLY hwtestanswerchoice
    ADD CONSTRAINT hwtestanswerchoice__test__id__key UNIQUE (test, id);


ALTER TABLE ONLY hwtestanswerchoice
    ADD CONSTRAINT hwtestanswerchoice_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwtestanswercount
    ADD CONSTRAINT hwtestanswercount_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwtestanswercountdevice
    ADD CONSTRAINT hwtestanswercountdevice__answer__device_driver__key UNIQUE (answer, device_driver);


ALTER TABLE ONLY hwtestanswercountdevice
    ADD CONSTRAINT hwtestanswercountdevice_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwtestanswerdevice
    ADD CONSTRAINT hwtestanswerdevice__answer__device_driver__key UNIQUE (answer, device_driver);


ALTER TABLE ONLY hwtestanswerdevice
    ADD CONSTRAINT hwtestanswerdevice_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwvendorid
    ADD CONSTRAINT hwvendorid__bus_vendor_id__vendor_name__key UNIQUE (bus, vendor_id_for_bus, vendor_name);


ALTER TABLE ONLY hwvendorid
    ADD CONSTRAINT hwvendorid_pkey PRIMARY KEY (id);


ALTER TABLE ONLY hwvendorname
    ADD CONSTRAINT hwvendorname_pkey PRIMARY KEY (id);


ALTER TABLE ONLY incrementaldiff
    ADD CONSTRAINT incrementaldiff_pkey PRIMARY KEY (id);


ALTER TABLE ONLY ircid
    ADD CONSTRAINT ircid_pkey PRIMARY KEY (id);


ALTER TABLE ONLY jabberid
    ADD CONSTRAINT jabberid_jabberid_key UNIQUE (jabberid);


ALTER TABLE ONLY jabberid
    ADD CONSTRAINT jabberid_pkey PRIMARY KEY (id);


ALTER TABLE ONLY job
    ADD CONSTRAINT job__status__id__key UNIQUE (status, id);


ALTER TABLE ONLY job
    ADD CONSTRAINT job_pkey PRIMARY KEY (id);

ALTER TABLE job CLUSTER ON job_pkey;


ALTER TABLE ONLY karma
    ADD CONSTRAINT karma_pkey PRIMARY KEY (id);


ALTER TABLE ONLY karmaaction
    ADD CONSTRAINT karmaaction_name_uniq UNIQUE (name);


ALTER TABLE ONLY karmaaction
    ADD CONSTRAINT karmaaction_pkey PRIMARY KEY (id);


ALTER TABLE ONLY karmacache
    ADD CONSTRAINT karmacache_pkey PRIMARY KEY (id);


ALTER TABLE ONLY karmacategory
    ADD CONSTRAINT karmacategory_pkey PRIMARY KEY (id);


ALTER TABLE ONLY karmatotalcache
    ADD CONSTRAINT karmatotalcache_person_key UNIQUE (person);


ALTER TABLE ONLY karmatotalcache
    ADD CONSTRAINT karmatotalcache_pkey PRIMARY KEY (id);


ALTER TABLE ONLY language
    ADD CONSTRAINT language_code_key UNIQUE (code);


ALTER TABLE ONLY language
    ADD CONSTRAINT language_pkey PRIMARY KEY (id);


ALTER TABLE ONLY languagepack
    ADD CONSTRAINT languagepack_pkey PRIMARY KEY (id);


ALTER TABLE ONLY launchpaddatabaserevision
    ADD CONSTRAINT launchpaddatabaserevision_pkey PRIMARY KEY (major, minor, patch);


ALTER TABLE ONLY launchpaddatabaseupdatelog
    ADD CONSTRAINT launchpaddatabaseupdatelog_pkey PRIMARY KEY (id);


ALTER TABLE ONLY launchpadstatistic
    ADD CONSTRAINT launchpadstatistic_pkey PRIMARY KEY (id);


ALTER TABLE ONLY launchpadstatistic
    ADD CONSTRAINT launchpadstatistics_uniq_name UNIQUE (name);


ALTER TABLE ONLY libraryfilealias
    ADD CONSTRAINT libraryfilealias_pkey PRIMARY KEY (id);

ALTER TABLE libraryfilealias CLUSTER ON libraryfilealias_pkey;


ALTER TABLE ONLY libraryfilecontent
    ADD CONSTRAINT libraryfilecontent_pkey PRIMARY KEY (id);

ALTER TABLE libraryfilecontent CLUSTER ON libraryfilecontent_pkey;


ALTER TABLE ONLY libraryfiledownloadcount
    ADD CONSTRAINT libraryfiledownloadcount__libraryfilealias__day__country__key UNIQUE (libraryfilealias, day, country);


ALTER TABLE ONLY libraryfiledownloadcount
    ADD CONSTRAINT libraryfiledownloadcount_pkey PRIMARY KEY (id);


ALTER TABLE ONLY logintoken
    ADD CONSTRAINT logintoken_pkey PRIMARY KEY (id);


ALTER TABLE ONLY logintoken
    ADD CONSTRAINT logintoken_token_key UNIQUE (token);


ALTER TABLE ONLY lp_account
    ADD CONSTRAINT lp_account__openid_identifier__key UNIQUE (openid_identifier);


ALTER TABLE ONLY lp_account
    ADD CONSTRAINT lp_account_pkey PRIMARY KEY (id);


ALTER TABLE ONLY lp_openididentifier
    ADD CONSTRAINT lp_openididentifier_pkey PRIMARY KEY (identifier);


ALTER TABLE ONLY lp_person
    ADD CONSTRAINT lp_person__account__key UNIQUE (account);


ALTER TABLE ONLY lp_person
    ADD CONSTRAINT lp_person__name__key UNIQUE (name);


ALTER TABLE ONLY lp_person
    ADD CONSTRAINT lp_person_pkey PRIMARY KEY (id);


ALTER TABLE ONLY lp_personlocation
    ADD CONSTRAINT lp_personlocation__person__key UNIQUE (person);


ALTER TABLE ONLY lp_personlocation
    ADD CONSTRAINT lp_personlocation_pkey PRIMARY KEY (id);


ALTER TABLE ONLY lp_teamparticipation
    ADD CONSTRAINT lp_teamparticipation_pkey PRIMARY KEY (id);


ALTER TABLE ONLY lp_teamparticipation
    ADD CONSTRAINT lp_teamperticipation__team__person__key UNIQUE (team, person);


ALTER TABLE ONLY mailinglist
    ADD CONSTRAINT mailinglist_pkey PRIMARY KEY (id);


ALTER TABLE ONLY mailinglist
    ADD CONSTRAINT mailinglist_team_key UNIQUE (team);


ALTER TABLE ONLY mailinglistsubscription
    ADD CONSTRAINT mailinglistsubscription_pkey PRIMARY KEY (id);


ALTER TABLE ONLY teammembership
    ADD CONSTRAINT membership_person_key UNIQUE (person, team);


ALTER TABLE ONLY teammembership
    ADD CONSTRAINT membership_pkey PRIMARY KEY (id);


ALTER TABLE ONLY mergedirectivejob
    ADD CONSTRAINT mergedirectivejob_job_key UNIQUE (job);


ALTER TABLE ONLY mergedirectivejob
    ADD CONSTRAINT mergedirectivejob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY message
    ADD CONSTRAINT message_pkey PRIMARY KEY (id);

ALTER TABLE message CLUSTER ON message_pkey;


ALTER TABLE ONLY messageapproval
    ADD CONSTRAINT messageapproval_pkey PRIMARY KEY (id);


ALTER TABLE ONLY messagechunk
    ADD CONSTRAINT messagechunk_message_idx UNIQUE (message, sequence);


ALTER TABLE ONLY messagechunk
    ADD CONSTRAINT messagechunk_pkey PRIMARY KEY (id);


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone_distribution_id_key UNIQUE (distribution, id);


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone_name_distribution_key UNIQUE (name, distribution);


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone_name_product_key UNIQUE (name, product);


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone_pkey PRIMARY KEY (id);

ALTER TABLE milestone CLUSTER ON milestone_pkey;


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone_product_id_key UNIQUE (product, id);


ALTER TABLE ONLY mirror
    ADD CONSTRAINT mirror_name_key UNIQUE (name);


ALTER TABLE ONLY mirror
    ADD CONSTRAINT mirror_pkey PRIMARY KEY (id);


ALTER TABLE ONLY mirrorcdimagedistroseries
    ADD CONSTRAINT mirrorcdimagedistrorelease_pkey PRIMARY KEY (id);


ALTER TABLE ONLY mirrorcdimagedistroseries
    ADD CONSTRAINT mirrorcdimagedistroseries__unq UNIQUE (distroseries, flavour, distribution_mirror);


ALTER TABLE ONLY mirrorcontent
    ADD CONSTRAINT mirrorcontent_pkey PRIMARY KEY (id);


ALTER TABLE ONLY mirrordistroarchseries
    ADD CONSTRAINT mirrordistroarchrelease_pkey PRIMARY KEY (id);


ALTER TABLE ONLY mirrordistroseriessource
    ADD CONSTRAINT mirrordistroreleasesource_pkey PRIMARY KEY (id);


ALTER TABLE ONLY mirrorproberecord
    ADD CONSTRAINT mirrorproberecord_pkey PRIMARY KEY (id);


ALTER TABLE ONLY mirrorsourcecontent
    ADD CONSTRAINT mirrorsourcecontent_pkey PRIMARY KEY (id);


ALTER TABLE ONLY nameblacklist
    ADD CONSTRAINT nameblacklist__regexp__key UNIQUE (regexp);


ALTER TABLE ONLY nameblacklist
    ADD CONSTRAINT nameblacklist_pkey PRIMARY KEY (id);


ALTER TABLE ONLY oauthaccesstoken
    ADD CONSTRAINT oauthaccesstoken_key_key UNIQUE (key);


ALTER TABLE ONLY oauthaccesstoken
    ADD CONSTRAINT oauthaccesstoken_pkey PRIMARY KEY (id);


ALTER TABLE ONLY oauthconsumer
    ADD CONSTRAINT oauthconsumer_key_key UNIQUE (key);


ALTER TABLE ONLY oauthconsumer
    ADD CONSTRAINT oauthconsumer_pkey PRIMARY KEY (id);


ALTER TABLE ONLY oauthnonce
    ADD CONSTRAINT oauthnonce_pkey PRIMARY KEY (access_token, request_timestamp, nonce);


ALTER TABLE ONLY oauthrequesttoken
    ADD CONSTRAINT oauthrequesttoken_key_key UNIQUE (key);


ALTER TABLE ONLY oauthrequesttoken
    ADD CONSTRAINT oauthrequesttoken_pkey PRIMARY KEY (id);


ALTER TABLE ONLY officialbugtag
    ADD CONSTRAINT officialbugtag_pkey PRIMARY KEY (id);


ALTER TABLE ONLY openidconsumerassociation
    ADD CONSTRAINT openidconsumerassociation_pkey PRIMARY KEY (server_url, handle);


ALTER TABLE ONLY openidconsumernonce
    ADD CONSTRAINT openidconsumernonce_pkey PRIMARY KEY (server_url, "timestamp", salt);


ALTER TABLE ONLY openididentifier
    ADD CONSTRAINT openididentifier_pkey PRIMARY KEY (identifier);


ALTER TABLE ONLY branchmergequeue
    ADD CONSTRAINT owner_name UNIQUE (owner, name);


ALTER TABLE ONLY packagebuild
    ADD CONSTRAINT packagebuild_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packagecopyjob
    ADD CONSTRAINT packagecopyjob__job__key UNIQUE (job);


ALTER TABLE ONLY packagecopyjob
    ADD CONSTRAINT packagecopyjob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packagecopyrequest
    ADD CONSTRAINT packagecopyrequest_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packagediff
    ADD CONSTRAINT packagediff_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packagesetinclusion
    ADD CONSTRAINT packagepayerinclusion__parent__child__key UNIQUE (parent, child);


ALTER TABLE ONLY binarypackagepublishinghistory
    ADD CONSTRAINT packagepublishinghistory_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packageset
    ADD CONSTRAINT packageset__name__distroseries__key UNIQUE (name, distroseries);


ALTER TABLE ONLY packageset
    ADD CONSTRAINT packageset_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packagesetgroup
    ADD CONSTRAINT packagesetgroup_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packagesetinclusion
    ADD CONSTRAINT packagesetinclusion_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packagesetsources
    ADD CONSTRAINT packagesetsources__packageset__sourcepackagename__key UNIQUE (packageset, sourcepackagename);


ALTER TABLE ONLY packagesetsources
    ADD CONSTRAINT packagesetsources_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packageuploadsource
    ADD CONSTRAINT packageuploadsource__packageupload__key UNIQUE (packageupload);


ALTER TABLE ONLY packaging
    ADD CONSTRAINT packaging__distroseries__sourcepackagename__key UNIQUE (distroseries, sourcepackagename);


ALTER TABLE ONLY packaging
    ADD CONSTRAINT packaging_pkey PRIMARY KEY (id);


ALTER TABLE ONLY packagingjob
    ADD CONSTRAINT packagingjob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY parsedapachelog
    ADD CONSTRAINT parsedapachelog_pkey PRIMARY KEY (id);


ALTER TABLE ONLY person
    ADD CONSTRAINT person__account__key UNIQUE (account);


ALTER TABLE ONLY person
    ADD CONSTRAINT person__name__key UNIQUE (name);


ALTER TABLE ONLY person
    ADD CONSTRAINT person_pkey PRIMARY KEY (id);

ALTER TABLE person CLUSTER ON person_pkey;


ALTER TABLE ONLY personlanguage
    ADD CONSTRAINT personlanguage_person_key UNIQUE (person, language);


ALTER TABLE ONLY personlanguage
    ADD CONSTRAINT personlanguage_pkey PRIMARY KEY (id);


ALTER TABLE ONLY personlocation
    ADD CONSTRAINT personlocation_person_key UNIQUE (person);


ALTER TABLE ONLY personlocation
    ADD CONSTRAINT personlocation_pkey PRIMARY KEY (id);


ALTER TABLE ONLY personnotification
    ADD CONSTRAINT personnotification_pkey PRIMARY KEY (id);


ALTER TABLE ONLY personsettings
    ADD CONSTRAINT personsettings_pkey PRIMARY KEY (person);


ALTER TABLE ONLY persontransferjob
    ADD CONSTRAINT persontransferjob_job_key UNIQUE (job);


ALTER TABLE ONLY persontransferjob
    ADD CONSTRAINT persontransferjob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY pillarname
    ADD CONSTRAINT pillarname_name_key UNIQUE (name);


ALTER TABLE ONLY pillarname
    ADD CONSTRAINT pillarname_pkey PRIMARY KEY (id);

ALTER TABLE pillarname CLUSTER ON pillarname_pkey;


ALTER TABLE ONLY pocketchroot
    ADD CONSTRAINT pocketchroot_distroarchrelease_key UNIQUE (distroarchseries, pocket);


ALTER TABLE ONLY pocketchroot
    ADD CONSTRAINT pocketchroot_pkey PRIMARY KEY (id);


ALTER TABLE ONLY poexportrequest
    ADD CONSTRAINT poexportrequest_pkey PRIMARY KEY (id);


ALTER TABLE ONLY pofile
    ADD CONSTRAINT pofile_pkey PRIMARY KEY (id);


ALTER TABLE ONLY pofilestatsjob
    ADD CONSTRAINT pofilestatsjob_pkey PRIMARY KEY (job);


ALTER TABLE ONLY pofiletranslator
    ADD CONSTRAINT pofiletranslator__person__pofile__key UNIQUE (person, pofile);

ALTER TABLE pofiletranslator CLUSTER ON pofiletranslator__person__pofile__key;


ALTER TABLE ONLY pofiletranslator
    ADD CONSTRAINT pofiletranslator_pkey PRIMARY KEY (id);


ALTER TABLE ONLY poll
    ADD CONSTRAINT poll_pkey PRIMARY KEY (id);


ALTER TABLE ONLY poll
    ADD CONSTRAINT poll_team_key UNIQUE (team, name);


ALTER TABLE ONLY polloption
    ADD CONSTRAINT polloption_name_key UNIQUE (name, poll);


ALTER TABLE ONLY polloption
    ADD CONSTRAINT polloption_pkey PRIMARY KEY (id);


ALTER TABLE ONLY polloption
    ADD CONSTRAINT polloption_poll_key UNIQUE (poll, id);


ALTER TABLE ONLY pomsgid
    ADD CONSTRAINT pomsgid_pkey PRIMARY KEY (id);


ALTER TABLE ONLY potemplate
    ADD CONSTRAINT potemplate_pkey PRIMARY KEY (id);


ALTER TABLE ONLY potmsgset
    ADD CONSTRAINT potmsgset_pkey PRIMARY KEY (id);


ALTER TABLE ONLY potranslation
    ADD CONSTRAINT potranslation_pkey PRIMARY KEY (id);


ALTER TABLE ONLY previewdiff
    ADD CONSTRAINT previewdiff_pkey PRIMARY KEY (id);


ALTER TABLE ONLY processor
    ADD CONSTRAINT processor_name_key UNIQUE (name);


ALTER TABLE ONLY processor
    ADD CONSTRAINT processor_pkey PRIMARY KEY (id);


ALTER TABLE ONLY processorfamily
    ADD CONSTRAINT processorfamily_name_key UNIQUE (name);


ALTER TABLE ONLY processorfamily
    ADD CONSTRAINT processorfamily_pkey PRIMARY KEY (id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product_name_key UNIQUE (name);

ALTER TABLE product CLUSTER ON product_name_key;


ALTER TABLE ONLY product
    ADD CONSTRAINT product_pkey PRIMARY KEY (id);


ALTER TABLE ONLY productlicense
    ADD CONSTRAINT productlicense__product__license__key UNIQUE (product, license);


ALTER TABLE ONLY productlicense
    ADD CONSTRAINT productlicense_pkey PRIMARY KEY (id);


ALTER TABLE ONLY productrelease
    ADD CONSTRAINT productrelease_milestone_key UNIQUE (milestone);


ALTER TABLE ONLY productrelease
    ADD CONSTRAINT productrelease_pkey PRIMARY KEY (id);

ALTER TABLE productrelease CLUSTER ON productrelease_pkey;


ALTER TABLE ONLY productreleasefile
    ADD CONSTRAINT productreleasefile_pkey PRIMARY KEY (id);


ALTER TABLE ONLY productseries
    ADD CONSTRAINT productseries__product__name__key UNIQUE (product, name);

ALTER TABLE productseries CLUSTER ON productseries__product__name__key;


ALTER TABLE ONLY productseries
    ADD CONSTRAINT productseries_pkey PRIMARY KEY (id);


ALTER TABLE ONLY productseries
    ADD CONSTRAINT productseries_product_series_uniq UNIQUE (product, id);


ALTER TABLE ONLY project
    ADD CONSTRAINT project_name_key UNIQUE (name);


ALTER TABLE ONLY project
    ADD CONSTRAINT project_pkey PRIMARY KEY (id);

ALTER TABLE project CLUSTER ON project_pkey;


ALTER TABLE ONLY publisherconfig
    ADD CONSTRAINT publisherconfig_pkey PRIMARY KEY (id);


ALTER TABLE ONLY questionjob
    ADD CONSTRAINT questionjob_job_key UNIQUE (job);


ALTER TABLE ONLY questionjob
    ADD CONSTRAINT questionjob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY revision
    ADD CONSTRAINT revision__id__revision_date__key UNIQUE (id, revision_date);


ALTER TABLE ONLY revision
    ADD CONSTRAINT revision_revision_id_unique UNIQUE (revision_id);


ALTER TABLE ONLY revisioncache
    ADD CONSTRAINT revisioncache_pkey PRIMARY KEY (id);


ALTER TABLE ONLY branchrevision
    ADD CONSTRAINT revisionnumber_branch_sequence_unique UNIQUE (branch, sequence);


ALTER TABLE ONLY branchrevision
    ADD CONSTRAINT revisionnumber_pkey PRIMARY KEY (revision, branch);


ALTER TABLE ONLY revisionparent
    ADD CONSTRAINT revisionparent_pkey PRIMARY KEY (id);


ALTER TABLE ONLY revisionparent
    ADD CONSTRAINT revisionparent_unique UNIQUE (revision, parent_id);


ALTER TABLE ONLY revisionproperty
    ADD CONSTRAINT revisionproperty__revision__name__key UNIQUE (revision, name);


ALTER TABLE ONLY revisionproperty
    ADD CONSTRAINT revisionproperty_pkey PRIMARY KEY (id);


ALTER TABLE ONLY scriptactivity
    ADD CONSTRAINT scriptactivity_pkey PRIMARY KEY (id);


ALTER TABLE ONLY section
    ADD CONSTRAINT section_name_key UNIQUE (name);


ALTER TABLE ONLY section
    ADD CONSTRAINT section_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sectionselection
    ADD CONSTRAINT sectionselection_pkey PRIMARY KEY (id);


ALTER TABLE ONLY seriessourcepackagebranch
    ADD CONSTRAINT seriessourcepackagebranch__ds__spn__pocket__key UNIQUE (distroseries, sourcepackagename, pocket);


ALTER TABLE ONLY seriessourcepackagebranch
    ADD CONSTRAINT seriessourcepackagebranch_pkey PRIMARY KEY (id);


ALTER TABLE ONLY signedcodeofconduct
    ADD CONSTRAINT signedcodeofconduct_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackageformatselection
    ADD CONSTRAINT sourceformatselection__distroseries__format__key UNIQUE (distroseries, format);


ALTER TABLE ONLY sourcepackageformatselection
    ADD CONSTRAINT sourcepackageformatselection_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackagename
    ADD CONSTRAINT sourcepackagename_name_key UNIQUE (name);


ALTER TABLE ONLY sourcepackagename
    ADD CONSTRAINT sourcepackagename_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT sourcepackagepublishinghistory_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackagerecipe
    ADD CONSTRAINT sourcepackagerecipe__owner__name__key UNIQUE (owner, name);


ALTER TABLE ONLY sourcepackagerecipedistroseries
    ADD CONSTRAINT sourcepackagerecipe_distroseries_unique UNIQUE (sourcepackagerecipe, distroseries);


ALTER TABLE ONLY sourcepackagerecipe
    ADD CONSTRAINT sourcepackagerecipe_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackagerecipebuild
    ADD CONSTRAINT sourcepackagerecipebuild_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackagerecipebuildjob
    ADD CONSTRAINT sourcepackagerecipebuildjob__job__key UNIQUE (job);


ALTER TABLE ONLY sourcepackagerecipebuildjob
    ADD CONSTRAINT sourcepackagerecipebuildjob__sourcepackage_recipe_build__key UNIQUE (sourcepackage_recipe_build);


ALTER TABLE ONLY sourcepackagerecipebuildjob
    ADD CONSTRAINT sourcepackagerecipebuildjob_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackagerecipedata
    ADD CONSTRAINT sourcepackagerecipedata_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackagerecipedatainstruction
    ADD CONSTRAINT sourcepackagerecipedatainstruction__name__recipe_data__key UNIQUE (name, recipe_data);


ALTER TABLE ONLY sourcepackagerecipedatainstruction
    ADD CONSTRAINT sourcepackagerecipedatainstruction__recipe_data__line_number__k UNIQUE (recipe_data, line_number);


ALTER TABLE ONLY sourcepackagerecipedatainstruction
    ADD CONSTRAINT sourcepackagerecipedatainstruction_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackagerecipedistroseries
    ADD CONSTRAINT sourcepackagerecipedistroseries_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sourcepackagereleasefile
    ADD CONSTRAINT sourcepackagereleasefile_pkey PRIMARY KEY (id);


ALTER TABLE ONLY specificationbug
    ADD CONSTRAINT specification_bug_uniq UNIQUE (specification, bug);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_distribution_name_uniq UNIQUE (distribution, name);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_pkey PRIMARY KEY (id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_product_name_uniq UNIQUE (name, product);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_specurl_uniq UNIQUE (specurl);


ALTER TABLE ONLY specificationbranch
    ADD CONSTRAINT specificationbranch__spec_branch_unique UNIQUE (branch, specification);


ALTER TABLE ONLY specificationbranch
    ADD CONSTRAINT specificationbranch_pkey PRIMARY KEY (id);


ALTER TABLE ONLY specificationbug
    ADD CONSTRAINT specificationbug_pkey PRIMARY KEY (id);


ALTER TABLE ONLY specificationdependency
    ADD CONSTRAINT specificationdependency_pkey PRIMARY KEY (id);


ALTER TABLE ONLY specificationdependency
    ADD CONSTRAINT specificationdependency_uniq UNIQUE (specification, dependency);


ALTER TABLE ONLY specificationfeedback
    ADD CONSTRAINT specificationfeedback_pkey PRIMARY KEY (id);


ALTER TABLE ONLY specificationmessage
    ADD CONSTRAINT specificationmessage__specification__message__key UNIQUE (specification, message);


ALTER TABLE ONLY specificationmessage
    ADD CONSTRAINT specificationmessage_pkey PRIMARY KEY (id);


ALTER TABLE ONLY specificationsubscription
    ADD CONSTRAINT specificationsubscription_pkey PRIMARY KEY (id);


ALTER TABLE ONLY specificationsubscription
    ADD CONSTRAINT specificationsubscription_spec_person_uniq UNIQUE (specification, person);


ALTER TABLE ONLY spokenin
    ADD CONSTRAINT spokenin__country__language__key UNIQUE (language, country);


ALTER TABLE ONLY spokenin
    ADD CONSTRAINT spokenin_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sprint
    ADD CONSTRAINT sprint_name_uniq UNIQUE (name);


ALTER TABLE ONLY sprint
    ADD CONSTRAINT sprint_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sprintattendance
    ADD CONSTRAINT sprintattendance_attendance_uniq UNIQUE (attendee, sprint);


ALTER TABLE ONLY sprintattendance
    ADD CONSTRAINT sprintattendance_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sprintspecification
    ADD CONSTRAINT sprintspec_uniq UNIQUE (specification, sprint);


ALTER TABLE ONLY sprintspecification
    ADD CONSTRAINT sprintspecification_pkey PRIMARY KEY (id);


ALTER TABLE ONLY sshkey
    ADD CONSTRAINT sshkey_pkey PRIMARY KEY (id);


ALTER TABLE ONLY structuralsubscription
    ADD CONSTRAINT structuralsubscription_pkey PRIMARY KEY (id);


ALTER TABLE ONLY subunitstream
    ADD CONSTRAINT subunitstream_pkey PRIMARY KEY (id);


ALTER TABLE ONLY suggestivepotemplate
    ADD CONSTRAINT suggestivepotemplate_pkey PRIMARY KEY (potemplate);


ALTER TABLE ONLY answercontact
    ADD CONSTRAINT supportcontact__distribution__sourcepackagename__person__key UNIQUE (distribution, sourcepackagename, person);


ALTER TABLE ONLY answercontact
    ADD CONSTRAINT supportcontact__product__person__key UNIQUE (product, person);


ALTER TABLE ONLY answercontact
    ADD CONSTRAINT supportcontact_pkey PRIMARY KEY (id);


ALTER TABLE ONLY teamparticipation
    ADD CONSTRAINT teamparticipation_pkey PRIMARY KEY (id);


ALTER TABLE ONLY teamparticipation
    ADD CONSTRAINT teamparticipation_team_key UNIQUE (team, person);


ALTER TABLE ONLY temporaryblobstorage
    ADD CONSTRAINT temporaryblobstorage_file_alias_key UNIQUE (file_alias);


ALTER TABLE ONLY temporaryblobstorage
    ADD CONSTRAINT temporaryblobstorage_pkey PRIMARY KEY (id);

ALTER TABLE temporaryblobstorage CLUSTER ON temporaryblobstorage_pkey;


ALTER TABLE ONLY temporaryblobstorage
    ADD CONSTRAINT temporaryblobstorage_uuid_key UNIQUE (uuid);


ALTER TABLE ONLY question
    ADD CONSTRAINT ticket_pkey PRIMARY KEY (id);


ALTER TABLE ONLY questionbug
    ADD CONSTRAINT ticketbug_bug_ticket_uniq UNIQUE (bug, question);


ALTER TABLE ONLY questionbug
    ADD CONSTRAINT ticketbug_pkey PRIMARY KEY (id);


ALTER TABLE ONLY questionmessage
    ADD CONSTRAINT ticketmessage_message_ticket_uniq UNIQUE (message, question);


ALTER TABLE ONLY questionmessage
    ADD CONSTRAINT ticketmessage_pkey PRIMARY KEY (id);


ALTER TABLE ONLY questionreopening
    ADD CONSTRAINT ticketreopening_pkey PRIMARY KEY (id);


ALTER TABLE ONLY questionsubscription
    ADD CONSTRAINT ticketsubscription_pkey PRIMARY KEY (id);


ALTER TABLE ONLY questionsubscription
    ADD CONSTRAINT ticketsubscription_ticket_person_uniq UNIQUE (question, person);


ALTER TABLE ONLY translator
    ADD CONSTRAINT translation_translationgroup_key UNIQUE (translationgroup, language);


ALTER TABLE ONLY translationgroup
    ADD CONSTRAINT translationgroup_name_key UNIQUE (name);


ALTER TABLE ONLY translationgroup
    ADD CONSTRAINT translationgroup_pkey PRIMARY KEY (id);


ALTER TABLE ONLY translationimportqueueentry
    ADD CONSTRAINT translationimportqueueentry_pkey PRIMARY KEY (id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage_pkey PRIMARY KEY (id);


ALTER TABLE ONLY translationrelicensingagreement
    ADD CONSTRAINT translationrelicensingagreement__person__key UNIQUE (person);


ALTER TABLE ONLY translationrelicensingagreement
    ADD CONSTRAINT translationrelicensingagreement_pkey PRIMARY KEY (id);


ALTER TABLE ONLY translationtemplateitem
    ADD CONSTRAINT translationtemplateitem_pkey PRIMARY KEY (id);


ALTER TABLE ONLY translationtemplatesbuild
    ADD CONSTRAINT translationtemplatesbuild_pkey PRIMARY KEY (id);


ALTER TABLE ONLY translator
    ADD CONSTRAINT translator_pkey PRIMARY KEY (id);


ALTER TABLE ONLY specificationfeedback
    ADD CONSTRAINT unique_spec_requestor_provider UNIQUE (specification, requester, reviewer);


ALTER TABLE ONLY usertouseremail
    ADD CONSTRAINT usertouseremail_pkey PRIMARY KEY (id);


ALTER TABLE ONLY vote
    ADD CONSTRAINT vote_pkey PRIMARY KEY (id);


ALTER TABLE ONLY votecast
    ADD CONSTRAINT votecast_person_key UNIQUE (person, poll);


ALTER TABLE ONLY votecast
    ADD CONSTRAINT votecast_pkey PRIMARY KEY (id);


ALTER TABLE ONLY wikiname
    ADD CONSTRAINT wikiname_pkey PRIMARY KEY (id);


ALTER TABLE ONLY wikiname
    ADD CONSTRAINT wikiname_wikiname_key UNIQUE (wikiname, wiki);


CREATE UNIQUE INDEX accessartifactgrant__artifact__grantee__key ON accesspolicygrant USING btree (artifact, grantee) WHERE (artifact IS NOT NULL);


CREATE UNIQUE INDEX accesspolicy__distribution__type__key ON accesspolicy USING btree (distribution, type) WHERE (distribution IS NOT NULL);


CREATE UNIQUE INDEX accesspolicy__product__type__key ON accesspolicy USING btree (product, type) WHERE (product IS NOT NULL);


CREATE UNIQUE INDEX accesspolicyartifact__branch__key ON accesspolicyartifact USING btree (branch) WHERE (branch IS NOT NULL);


CREATE UNIQUE INDEX accesspolicyartifact__bug__key ON accesspolicyartifact USING btree (bug) WHERE (bug IS NOT NULL);


CREATE INDEX accesspolicyartifact__policy__key ON accesspolicyartifact USING btree (policy);


CREATE INDEX accesspolicygrant__grantee__idx ON accesspolicygrant USING btree (grantee);


CREATE INDEX accesspolicygrant__grantor__idx ON accesspolicygrant USING btree (grantor);


CREATE UNIQUE INDEX accesspolicygrant__policy__grantee__key ON accesspolicygrant USING btree (policy, grantee) WHERE (policy IS NOT NULL);


CREATE INDEX announcement__distribution__active__idx ON announcement USING btree (distribution, active) WHERE (distribution IS NOT NULL);


CREATE INDEX announcement__product__active__idx ON announcement USING btree (product, active) WHERE (product IS NOT NULL);


CREATE INDEX announcement__project__active__idx ON announcement USING btree (project, active) WHERE (project IS NOT NULL);


CREATE INDEX announcement__registrant__idx ON announcement USING btree (registrant);


CREATE UNIQUE INDEX answercontact__distribution__person__key ON answercontact USING btree (distribution, person) WHERE (sourcepackagename IS NULL);


CREATE INDEX answercontact__person__idx ON answercontact USING btree (person);


CREATE INDEX apportjob__blob__idx ON apportjob USING btree (blob);


CREATE UNIQUE INDEX archive__distribution__purpose__key ON archive USING btree (distribution, purpose) WHERE (purpose = ANY (ARRAY[1, 4]));


CREATE INDEX archive__owner__idx ON archive USING btree (owner);


CREATE UNIQUE INDEX archive__owner__key ON archive USING btree (owner, distribution, name);


CREATE INDEX archive__require_virtualized__idx ON archive USING btree (require_virtualized);


CREATE INDEX archive__signing_key__idx ON archive USING btree (signing_key) WHERE (signing_key IS NOT NULL);


CREATE INDEX archive__status__idx ON archive USING btree (status);


CREATE INDEX archive_fti ON archive USING gist (fti);


CREATE INDEX archiveauthtoken__archive__idx ON archiveauthtoken USING btree (archive);


CREATE INDEX archiveauthtoken__date_created__idx ON archiveauthtoken USING btree (date_created);


CREATE INDEX archiveauthtoken__person__idx ON archiveauthtoken USING btree (person);


CREATE INDEX archivedependency__archive__idx ON archivedependency USING btree (archive);


CREATE INDEX archivedependency__component__idx ON archivedependency USING btree (component);


CREATE INDEX archivedependency__dependency__idx ON archivedependency USING btree (dependency);


CREATE INDEX archivejob__archive__job_type__idx ON archivejob USING btree (archive, job_type);


CREATE INDEX archivepermission__archive__component__permission__idx ON archivepermission USING btree (archive, component, permission);


CREATE INDEX archivepermission__archive__sourcepackagename__permission__idx ON archivepermission USING btree (archive, sourcepackagename, permission);


CREATE INDEX archivepermission__packageset__idx ON archivepermission USING btree (packageset) WHERE (packageset IS NOT NULL);


CREATE INDEX archivepermission__person__archive__idx ON archivepermission USING btree (person, archive);


CREATE INDEX archivesubscriber__archive__idx ON archivesubscriber USING btree (archive);


CREATE INDEX archivesubscriber__cancelled_by__idx ON archivesubscriber USING btree (cancelled_by) WHERE (cancelled_by IS NOT NULL);


CREATE INDEX archivesubscriber__date_created__idx ON archivesubscriber USING btree (date_created);


CREATE INDEX archivesubscriber__date_expires__idx ON archivesubscriber USING btree (date_expires) WHERE (date_expires IS NOT NULL);


CREATE INDEX archivesubscriber__registrant__idx ON archivesubscriber USING btree (registrant);


CREATE INDEX archivesubscriber__subscriber__idx ON archivesubscriber USING btree (subscriber);


CREATE INDEX binarypackagebuild__distro_arch_series__idx ON binarypackagebuild USING btree (distro_arch_series);


CREATE UNIQUE INDEX binarypackagebuild__package_build__idx ON binarypackagebuild USING btree (package_build);


CREATE INDEX binarypackagebuild__source_package_release_idx ON binarypackagebuild USING btree (source_package_release);


CREATE INDEX binarypackagefile_binarypackage_idx ON binarypackagefile USING btree (binarypackagerelease);


CREATE INDEX binarypackagefile_libraryfile_idx ON binarypackagefile USING btree (libraryfile);


CREATE INDEX binarypackagepublishinghistory__binarypackagename__idx ON binarypackagepublishinghistory USING btree (binarypackagename);


CREATE UNIQUE INDEX binarypackagerelease__debug_package__key ON binarypackagerelease USING btree (debug_package);


CREATE INDEX binarypackagerelease__version__idx ON binarypackagerelease USING btree (version);


CREATE INDEX binarypackagerelease_build_idx ON binarypackagerelease USING btree (build);


CREATE INDEX binarypackagerelease_fti ON binarypackagerelease USING gist (fti);


CREATE INDEX branch__access_policy__idx ON branch USING btree (access_policy);


CREATE INDEX branch__date_created__idx ON branch USING btree (date_created);


CREATE UNIQUE INDEX branch__ds__spn__owner__name__key ON branch USING btree (distroseries, sourcepackagename, owner, name) WHERE (distroseries IS NOT NULL);


CREATE INDEX branch__last_scanned__owner__idx ON branch USING btree (last_scanned, owner) WHERE (last_scanned IS NOT NULL);


CREATE INDEX branch__merge_queue__idx ON branch USING btree (merge_queue);


CREATE INDEX branch__next_mirror_time__idx ON branch USING btree (next_mirror_time) WHERE (next_mirror_time IS NOT NULL);


CREATE UNIQUE INDEX branch__owner__name__key ON branch USING btree (owner, name) WHERE ((product IS NULL) AND (distroseries IS NULL));


CREATE INDEX branch__owner_name__idx ON branch USING btree (owner_name);


CREATE INDEX branch__private__idx ON branch USING btree (private);


CREATE INDEX branch__product__id__idx ON branch USING btree (product, id);

ALTER TABLE branch CLUSTER ON branch__product__id__idx;


CREATE UNIQUE INDEX branch__product__owner__name__key ON branch USING btree (product, owner, name) WHERE (product IS NOT NULL);


CREATE INDEX branch__registrant__idx ON branch USING btree (registrant);


CREATE INDEX branch__reviewer__idx ON branch USING btree (reviewer);


CREATE INDEX branch__stacked_on__idx ON branch USING btree (stacked_on) WHERE (stacked_on IS NOT NULL);


CREATE INDEX branch__target_suffix__idx ON branch USING btree (target_suffix);


CREATE INDEX branch__transitively_private__idx ON branch USING btree (transitively_private);


CREATE INDEX branch_author_idx ON branch USING btree (author);


CREATE INDEX branch_owner_idx ON branch USING btree (owner);


CREATE INDEX branchjob__branch__idx ON branchjob USING btree (branch);


CREATE INDEX branchmergeproposal__dependent_branch__idx ON branchmergeproposal USING btree (dependent_branch);


CREATE INDEX branchmergeproposal__merge_diff__idx ON branchmergeproposal USING btree (merge_diff);


CREATE INDEX branchmergeproposal__merge_log_file__idx ON branchmergeproposal USING btree (merge_log_file);


CREATE INDEX branchmergeproposal__merge_reporter__idx ON branchmergeproposal USING btree (merge_reporter) WHERE (merge_reporter IS NOT NULL);


CREATE INDEX branchmergeproposal__merger__idx ON branchmergeproposal USING btree (merger);


CREATE INDEX branchmergeproposal__queuer__idx ON branchmergeproposal USING btree (queuer);


CREATE INDEX branchmergeproposal__registrant__idx ON branchmergeproposal USING btree (registrant);


CREATE INDEX branchmergeproposal__reviewer__idx ON branchmergeproposal USING btree (reviewer);


CREATE INDEX branchmergeproposal__source_branch__idx ON branchmergeproposal USING btree (source_branch);


CREATE INDEX branchmergeproposal__superseded_by__idx ON branchmergeproposal USING btree (superseded_by) WHERE (superseded_by IS NOT NULL);


CREATE INDEX branchmergeproposal__target_branch__idx ON branchmergeproposal USING btree (target_branch);


CREATE INDEX branchmergeproposaljob__branch_merge_proposal__idx ON branchmergeproposaljob USING btree (branch_merge_proposal);


CREATE INDEX branchmergequeue__registrant__idx ON branchmergequeue USING btree (registrant);


CREATE INDEX branchsubscription__branch__idx ON branchsubscription USING btree (branch);


CREATE INDEX branchsubscription__subscribed_by__idx ON branchsubscription USING btree (subscribed_by);


CREATE INDEX branchvisibilitypolicy__product__idx ON branchvisibilitypolicy USING btree (product) WHERE (product IS NOT NULL);


CREATE INDEX branchvisibilitypolicy__project__idx ON branchvisibilitypolicy USING btree (project) WHERE (project IS NOT NULL);


CREATE INDEX branchvisibilitypolicy__team__idx ON branchvisibilitypolicy USING btree (team) WHERE (team IS NOT NULL);


CREATE UNIQUE INDEX branchvisibilitypolicy__unq ON branchvisibilitypolicy USING btree ((COALESCE(product, (-1))), (COALESCE(project, (-1))), (COALESCE(team, (-1))));


CREATE INDEX bug__access_policy__idx ON bug USING btree (access_policy);


CREATE INDEX bug__date_last_message__idx ON bug USING btree (date_last_message);


CREATE INDEX bug__date_last_updated__idx ON bug USING btree (date_last_updated);

ALTER TABLE bug CLUSTER ON bug__date_last_updated__idx;


CREATE INDEX bug__datecreated__idx ON bug USING btree (datecreated);


CREATE INDEX bug__heat__idx ON bug USING btree (heat);


CREATE INDEX bug__heat_last_updated__idx ON bug USING btree (heat_last_updated);


CREATE INDEX bug__latest_patch_uploaded__idx ON bug USING btree (latest_patch_uploaded);


CREATE UNIQUE INDEX bug__name__key ON bug USING btree (name) WHERE (name IS NOT NULL);


CREATE INDEX bug__new_patches__idx ON bug USING btree (id) WHERE ((latest_patch_uploaded IS NOT NULL) AND (duplicateof IS NULL));


CREATE INDEX bug__users_affected_count__idx ON bug USING btree (users_affected_count);


CREATE INDEX bug__users_unaffected_count__idx ON bug USING btree (users_unaffected_count);


CREATE INDEX bug__who_made_private__idx ON bug USING btree (who_made_private) WHERE (who_made_private IS NOT NULL);


CREATE INDEX bug_duplicateof_idx ON bug USING btree (duplicateof);


CREATE INDEX bug_fti ON bug USING gist (fti);


CREATE INDEX bug_owner_idx ON bug USING btree (owner);


CREATE INDEX bugactivity_bug_datechanged_idx ON bugactivity USING btree (bug, datechanged);


CREATE INDEX bugactivity_datechanged_idx ON bugactivity USING btree (datechanged);


CREATE INDEX bugactivity_person_datechanged_idx ON bugactivity USING btree (person, datechanged);


CREATE INDEX bugaffectsperson__person__idx ON bugaffectsperson USING btree (person);


CREATE INDEX bugattachment__bug__idx ON bugattachment USING btree (bug);


CREATE INDEX bugattachment_libraryfile_idx ON bugattachment USING btree (libraryfile);


CREATE INDEX bugattachment_message_idx ON bugattachment USING btree (message);


CREATE INDEX bugbranch__registrant__idx ON bugbranch USING btree (registrant);


CREATE INDEX bugcve_cve_index ON bugcve USING btree (cve);


CREATE INDEX bugjob__bug__job_type__idx ON bugjob USING btree (bug, job_type);


CREATE INDEX bugmessage__owner__index__idx ON bugmessage USING btree (owner, index);


CREATE INDEX bugmessage_message_idx ON bugmessage USING btree (message);


CREATE INDEX bugmute__bug__idx ON bugmute USING btree (bug);


CREATE INDEX bugnomination__bug__idx ON bugnomination USING btree (bug);


CREATE INDEX bugnomination__decider__idx ON bugnomination USING btree (decider) WHERE (decider IS NOT NULL);


CREATE UNIQUE INDEX bugnomination__distroseries__bug__key ON bugnomination USING btree (distroseries, bug) WHERE (distroseries IS NOT NULL);


CREATE INDEX bugnomination__owner__idx ON bugnomination USING btree (owner);


CREATE UNIQUE INDEX bugnomination__productseries__bug__key ON bugnomination USING btree (productseries, bug) WHERE (productseries IS NOT NULL);


CREATE INDEX bugnotification__date_emailed__idx ON bugnotification USING btree (date_emailed);

ALTER TABLE bugnotification CLUSTER ON bugnotification__date_emailed__idx;


CREATE INDEX bugnotificationattachment__bug_notification__idx ON bugnotificationattachment USING btree (bug_notification);


CREATE INDEX bugnotificationattachment__message__idx ON bugnotificationattachment USING btree (message);


CREATE INDEX bugnotificationfilter__bug_subscription_filter__idx ON bugnotificationfilter USING btree (bug_subscription_filter);


CREATE INDEX bugnotificationrecipient__person__idx ON bugnotificationrecipient USING btree (person);


CREATE INDEX bugnotificationrecipientarchive__bug_notification__idx ON bugnotificationrecipientarchive USING btree (bug_notification);


CREATE INDEX bugnotificationrecipientarchive__person__idx ON bugnotificationrecipientarchive USING btree (person);


CREATE INDEX bugsubscription__subscribed_by__idx ON bugsubscription USING btree (subscribed_by);


CREATE INDEX bugsubscription_bug_idx ON bugsubscription USING btree (bug);

ALTER TABLE bugsubscription CLUSTER ON bugsubscription_bug_idx;


CREATE INDEX bugsubscription_person_idx ON bugsubscription USING btree (person);


CREATE INDEX bugsubscriptionfilter__bug_notification_level__idx ON bugsubscriptionfilter USING btree (bug_notification_level);


CREATE INDEX bugsubscriptionfilter__structuralsubscription ON bugsubscriptionfilter USING btree (structuralsubscription);


CREATE INDEX bugsubscriptionfilterimportance__filter__importance__idx ON bugsubscriptionfilterimportance USING btree (filter, importance);


CREATE INDEX bugsubscriptionfiltermute__filter__idx ON bugsubscriptionfiltermute USING btree (filter);


CREATE INDEX bugsubscriptionfilterstatus__filter__status__idx ON bugsubscriptionfilterstatus USING btree (filter, status);


CREATE INDEX bugsubscriptionfiltertag__filter__tag__idx ON bugsubscriptionfiltertag USING btree (filter, tag);


CREATE INDEX bugsummary__distribution__idx ON bugsummary USING btree (distribution) WHERE (distribution IS NOT NULL);


CREATE UNIQUE INDEX bugsummary__distribution__unique ON bugsummary USING btree (distribution, status, importance, has_patch, fixed_upstream, (COALESCE(sourcepackagename, (-1))), (COALESCE(tag, ''::text)), (COALESCE(milestone, (-1))), (COALESCE(viewed_by, (-1)))) WHERE (distribution IS NOT NULL);


CREATE INDEX bugsummary__distribution_count__idx ON bugsummary USING btree (distribution) WHERE ((sourcepackagename IS NULL) AND (tag IS NULL));


CREATE INDEX bugsummary__distribution_tag_count__idx ON bugsummary USING btree (distribution) WHERE ((sourcepackagename IS NULL) AND (tag IS NOT NULL));


CREATE INDEX bugsummary__distroseries__idx ON bugsummary USING btree (distroseries) WHERE (distroseries IS NOT NULL);


CREATE UNIQUE INDEX bugsummary__distroseries__unique ON bugsummary USING btree (distroseries, status, importance, has_patch, fixed_upstream, (COALESCE(sourcepackagename, (-1))), (COALESCE(tag, ''::text)), (COALESCE(milestone, (-1))), (COALESCE(viewed_by, (-1)))) WHERE (distroseries IS NOT NULL);


CREATE INDEX bugsummary__full__idx ON bugsummary USING btree (tag, status, product, productseries, distribution, distroseries, sourcepackagename, viewed_by, milestone, importance, has_patch, fixed_upstream);


CREATE INDEX bugsummary__milestone__idx ON bugsummary USING btree (milestone) WHERE (milestone IS NOT NULL);


CREATE INDEX bugsummary__nocount__idx ON bugsummary USING btree (count) WHERE (count = 0);


CREATE INDEX bugsummary__product__idx ON bugsummary USING btree (product) WHERE (product IS NOT NULL);


CREATE UNIQUE INDEX bugsummary__product__unique ON bugsummary USING btree (product, status, importance, has_patch, fixed_upstream, (COALESCE(tag, ''::text)), (COALESCE(milestone, (-1))), (COALESCE(viewed_by, (-1)))) WHERE (product IS NOT NULL);


CREATE INDEX bugsummary__productseries__idx ON bugsummary USING btree (productseries) WHERE (productseries IS NOT NULL);


CREATE UNIQUE INDEX bugsummary__productseries__unique ON bugsummary USING btree (productseries, status, importance, has_patch, fixed_upstream, (COALESCE(tag, ''::text)), (COALESCE(milestone, (-1))), (COALESCE(viewed_by, (-1)))) WHERE (productseries IS NOT NULL);


CREATE INDEX bugsummary__status_count__idx ON bugsummary USING btree (status) WHERE ((sourcepackagename IS NULL) AND (tag IS NULL));


CREATE INDEX bugsummary__tag_count__idx ON bugsummary USING btree (status) WHERE ((sourcepackagename IS NULL) AND (tag IS NOT NULL));


CREATE INDEX bugsummary__viewed_by__idx ON bugsummary USING btree (viewed_by) WHERE (viewed_by IS NOT NULL);


CREATE INDEX bugsummaryjournal__full__idx ON bugsummaryjournal USING btree (status, product, productseries, distribution, distroseries, sourcepackagename, viewed_by, milestone, tag);


CREATE INDEX bugsummaryjournal__milestone__idx ON bugsummaryjournal USING btree (milestone) WHERE (milestone IS NOT NULL);


CREATE INDEX bugsummaryjournal__viewed_by__idx ON bugsummaryjournal USING btree (viewed_by) WHERE (viewed_by IS NOT NULL);


CREATE INDEX bugtag__bug__idx ON bugtag USING btree (bug);


CREATE INDEX bugtask__assignee__idx ON bugtask USING btree (assignee);


CREATE INDEX bugtask__binarypackagename__idx ON bugtask USING btree (binarypackagename) WHERE (binarypackagename IS NOT NULL);


CREATE INDEX bugtask__bug__idx ON bugtask USING btree (bug);


CREATE INDEX bugtask__bugwatch__idx ON bugtask USING btree (bugwatch) WHERE (bugwatch IS NOT NULL);


CREATE INDEX bugtask__date_closed__id__idx2 ON bugtask USING btree (date_closed, id DESC);


CREATE INDEX bugtask__date_incomplete__idx ON bugtask USING btree (date_incomplete) WHERE (date_incomplete IS NOT NULL);


CREATE INDEX bugtask__datecreated__idx ON bugtask USING btree (datecreated);


CREATE INDEX bugtask__distribution__heat__id__idx ON bugtask USING btree (distribution, heat DESC, id) WHERE (distribution IS NOT NULL);


CREATE INDEX bugtask__distribution__sourcepackagename__idx ON bugtask USING btree (distribution, sourcepackagename);

ALTER TABLE bugtask CLUSTER ON bugtask__distribution__sourcepackagename__idx;


CREATE INDEX bugtask__distribution_sourcepackage__heat__idx ON bugtask USING btree (distribution, sourcepackagename, heat) WHERE (distribution IS NOT NULL);


CREATE INDEX bugtask__distroseries__sourcepackagename__idx ON bugtask USING btree (distroseries, sourcepackagename);


CREATE INDEX bugtask__distroseries_sourcepackage__heat__idx ON bugtask USING btree (distroseries, sourcepackagename, heat) WHERE (distroseries IS NOT NULL);


CREATE INDEX bugtask__milestone__idx ON bugtask USING btree (milestone);


CREATE INDEX bugtask__owner__idx ON bugtask USING btree (owner);


CREATE UNIQUE INDEX bugtask__product__bug__key ON bugtask USING btree (product, bug) WHERE (product IS NOT NULL);


CREATE INDEX bugtask__product__heat__id__idx ON bugtask USING btree (product, heat DESC, id) WHERE (product IS NOT NULL);


CREATE UNIQUE INDEX bugtask__productseries__bug__key ON bugtask USING btree (productseries, bug) WHERE (productseries IS NOT NULL);


CREATE INDEX bugtask__productseries__heat__idx ON bugtask USING btree (productseries, heat) WHERE (productseries IS NOT NULL);


CREATE INDEX bugtask__sourcepackagename__idx ON bugtask USING btree (sourcepackagename) WHERE (sourcepackagename IS NOT NULL);


CREATE INDEX bugtask__status__idx ON bugtask USING btree (status);


CREATE UNIQUE INDEX bugtask_distinct_sourcepackage_assignment ON bugtask USING btree (bug, (COALESCE(sourcepackagename, (-1))), (COALESCE(distroseries, (-1))), (COALESCE(distribution, (-1)))) WHERE ((product IS NULL) AND (productseries IS NULL));


CREATE INDEX bugtask_fti ON bugtask USING gist (fti);


CREATE INDEX bugtask_importance_idx ON bugtask USING btree (importance, id DESC);


CREATE UNIQUE INDEX bugtracker_name_key ON bugtracker USING btree (name);


CREATE INDEX bugtracker_owner_idx ON bugtracker USING btree (owner);


CREATE INDEX bugtrackeralias__bugtracker__idx ON bugtrackeralias USING btree (bugtracker);


CREATE INDEX bugtrackerperson__person__idx ON bugtrackerperson USING btree (person);


CREATE INDEX bugwatch__lastchecked__idx ON bugwatch USING btree (lastchecked);


CREATE INDEX bugwatch__next_check__idx ON bugwatch USING btree (next_check);


CREATE INDEX bugwatch__remote_lp_bug_id__idx ON bugwatch USING btree (remote_lp_bug_id) WHERE (remote_lp_bug_id IS NOT NULL);


CREATE INDEX bugwatch__remotebug__idx ON bugwatch USING btree (remotebug);


CREATE INDEX bugwatch_bug_idx ON bugwatch USING btree (bug);


CREATE INDEX bugwatch_bugtracker_idx ON bugwatch USING btree (bugtracker);


CREATE INDEX bugwatch_datecreated_idx ON bugwatch USING btree (datecreated);


CREATE INDEX bugwatch_owner_idx ON bugwatch USING btree (owner);


CREATE INDEX bugwatchactivity__bug_watch__idx ON bugwatchactivity USING btree (bug_watch);

ALTER TABLE bugwatchactivity CLUSTER ON bugwatchactivity__bug_watch__idx;


CREATE INDEX builder__owner__idx ON builder USING btree (owner);


CREATE INDEX buildfarmjob__builder_and_status__idx ON buildfarmjob USING btree (builder, status);


CREATE INDEX buildfarmjob__date_created__idx ON buildfarmjob USING btree (date_created);


CREATE INDEX buildfarmjob__date_finished__idx ON buildfarmjob USING btree (date_finished);


CREATE INDEX buildfarmjob__date_started__idx ON buildfarmjob USING btree (date_started);


CREATE INDEX buildfarmjob__log__idx ON buildfarmjob USING btree (log) WHERE (log IS NOT NULL);


CREATE INDEX buildfarmjob__status__idx ON buildfarmjob USING btree (status);


CREATE UNIQUE INDEX buildqueue__builder__id__idx ON buildqueue USING btree (builder, id);

ALTER TABLE buildqueue CLUSTER ON buildqueue__builder__id__idx;


CREATE UNIQUE INDEX buildqueue__builder__unq ON buildqueue USING btree (builder) WHERE (builder IS NOT NULL);


CREATE INDEX buildqueue__job_type__idx ON buildqueue USING btree (job_type);


CREATE INDEX buildqueue__processor__virtualized__idx ON buildqueue USING btree (processor, virtualized) WHERE (processor IS NOT NULL);


CREATE INDEX changeset_datecreated_idx ON revision USING btree (date_created);


CREATE INDEX codeimport__assignee__idx ON codeimport USING btree (assignee);


CREATE UNIQUE INDEX codeimport__cvs_root__cvs_module__key ON codeimport USING btree (cvs_root, cvs_module) WHERE (cvs_root IS NOT NULL);


CREATE INDEX codeimport__owner__idx ON codeimport USING btree (owner);


CREATE INDEX codeimport__registrant__idx ON codeimport USING btree (registrant);


CREATE UNIQUE INDEX codeimport__url__idx ON codeimport USING btree (url) WHERE (url IS NOT NULL);


CREATE INDEX codeimportevent__code_import__date_created__id__idx ON codeimportevent USING btree (code_import, date_created, id);


CREATE INDEX codeimportevent__date_created__id__idx ON codeimportevent USING btree (date_created, id);


CREATE INDEX codeimportevent__message__date_created__idx ON codeimportevent USING btree (machine, date_created) WHERE (machine IS NOT NULL);


CREATE INDEX codeimportevent__person__idx ON codeimportevent USING btree (person) WHERE (person IS NOT NULL);


CREATE INDEX codeimportjob__code_import__date_created__idx ON codeimportjob USING btree (code_import, date_created);


CREATE INDEX codeimportjob__machine__date_created__idx ON codeimportjob USING btree (machine, date_created);


CREATE INDEX codeimportjob__requesting_user__idx ON codeimportjob USING btree (requesting_user);


CREATE INDEX codeimportresult__code_import__date_created__idx ON codeimportresult USING btree (code_import, date_created);


CREATE INDEX codeimportresult__log_file__idx ON codeimportresult USING btree (log_file);


CREATE INDEX codeimportresult__machine__date_created__idx ON codeimportresult USING btree (machine, date_created);


CREATE INDEX codeimportresult__requesting_user__idx ON codeimportresult USING btree (requesting_user);


CREATE INDEX codereviewvote__branch_merge_proposal__idx ON codereviewvote USING btree (branch_merge_proposal);


CREATE INDEX codereviewvote__registrant__idx ON codereviewvote USING btree (registrant);


CREATE INDEX codereviewvote__reviewer__idx ON codereviewvote USING btree (reviewer);


CREATE INDEX codereviewvote__vote_message__idx ON codereviewvote USING btree (vote_message);


CREATE INDEX commercialsubscription__product__idx ON commercialsubscription USING btree (product);


CREATE INDEX commercialsubscription__purchaser__idx ON commercialsubscription USING btree (purchaser);


CREATE INDEX commercialsubscription__registrant__idx ON commercialsubscription USING btree (registrant);


CREATE INDEX commercialsubscription__sales_system_id__idx ON commercialsubscription USING btree (sales_system_id);


CREATE UNIQUE INDEX customlanguagecode__distribution__sourcepackagename__code__key ON customlanguagecode USING btree (distribution, sourcepackagename, language_code) WHERE (distribution IS NOT NULL);


CREATE UNIQUE INDEX customlanguagecode__product__code__key ON customlanguagecode USING btree (product, language_code) WHERE (product IS NOT NULL);


CREATE INDEX cve_datecreated_idx ON cve USING btree (datecreated);


CREATE INDEX cve_datemodified_idx ON cve USING btree (datemodified);


CREATE INDEX cve_fti ON cve USING gist (fti);


CREATE INDEX cvereference_cve_idx ON cvereference USING btree (cve);


CREATE INDEX diff__diff_text__idx ON diff USING btree (diff_text);


CREATE INDEX distribution__bug_supervisor__idx ON distribution USING btree (bug_supervisor) WHERE (bug_supervisor IS NOT NULL);


CREATE INDEX distribution__driver__idx ON distribution USING btree (driver);


CREATE INDEX distribution__icon__idx ON distribution USING btree (icon) WHERE (icon IS NOT NULL);


CREATE INDEX distribution__language_pack_admin__idx ON distribution USING btree (language_pack_admin);


CREATE INDEX distribution__logo__idx ON distribution USING btree (logo) WHERE (logo IS NOT NULL);


CREATE INDEX distribution__members__idx ON distribution USING btree (members);


CREATE INDEX distribution__mirror_admin__idx ON distribution USING btree (mirror_admin);


CREATE INDEX distribution__mugshot__idx ON distribution USING btree (mugshot) WHERE (mugshot IS NOT NULL);


CREATE INDEX distribution__owner__idx ON distribution USING btree (owner);


CREATE INDEX distribution__registrant__idx ON distribution USING btree (registrant);


CREATE INDEX distribution__security_contact__idx ON distribution USING btree (security_contact);


CREATE INDEX distribution__upload_admin__idx ON distribution USING btree (upload_admin);


CREATE INDEX distribution_fti ON distribution USING gist (fti);


CREATE UNIQUE INDEX distribution_job__initialize_series__distroseries ON distributionjob USING btree (distroseries) WHERE (job_type = 1);


CREATE INDEX distribution_translationgroup_idx ON distribution USING btree (translationgroup);


CREATE UNIQUE INDEX distributionmirror__archive__distribution__country__key ON distributionmirror USING btree (distribution, country, content) WHERE ((country_dns_mirror IS TRUE) AND (content = 1));


CREATE INDEX distributionmirror__country__status__idx ON distributionmirror USING btree (country, status);


CREATE INDEX distributionmirror__owner__idx ON distributionmirror USING btree (owner);


CREATE UNIQUE INDEX distributionmirror__releases__distribution__country__key ON distributionmirror USING btree (distribution, country, content) WHERE ((country_dns_mirror IS TRUE) AND (content = 2));


CREATE INDEX distributionmirror__reviewer__idx ON distributionmirror USING btree (reviewer);


CREATE INDEX distributionmirror__status__idx ON distributionmirror USING btree (status);


CREATE INDEX distributionsourcepackagecache__archive__idx ON distributionsourcepackagecache USING btree (archive);


CREATE INDEX distributionsourcepackagecache_fti ON distributionsourcepackagecache USING gist (fti);


CREATE INDEX distroarchseries__distroseries__idx ON distroarchseries USING btree (distroseries);


CREATE INDEX distroarchseries__owner__idx ON distroarchseries USING btree (owner);


CREATE INDEX distroseries__driver__idx ON distroseries USING btree (driver) WHERE (driver IS NOT NULL);


CREATE INDEX distroseries__registrant__idx ON distroseries USING btree (registrant);


CREATE INDEX distroseriesdifference__base_version__idx ON distroseriesdifference USING btree (base_version);


CREATE INDEX distroseriesdifference__difference_type__idx ON distroseriesdifference USING btree (difference_type);


CREATE INDEX distroseriesdifference__package_diff__idx ON distroseriesdifference USING btree (package_diff);


CREATE INDEX distroseriesdifference__parent_package_diff__idx ON distroseriesdifference USING btree (parent_package_diff);


CREATE INDEX distroseriesdifference__parent_series__idx ON distroseriesdifference USING btree (parent_series);


CREATE INDEX distroseriesdifference__parent_source_version__idx ON distroseriesdifference USING btree (parent_source_version);


CREATE INDEX distroseriesdifference__source_package_name__idx ON distroseriesdifference USING btree (source_package_name);


CREATE INDEX distroseriesdifference__source_version__idx ON distroseriesdifference USING btree (source_version);


CREATE INDEX distroseriesdifference__status__idx ON distroseriesdifference USING btree (status);


CREATE INDEX distroseriesdifferencemessage__distroseriesdifference__idx ON distroseriesdifferencemessage USING btree (distro_series_difference);


CREATE INDEX distroseriespackagecache__archive__idx ON distroseriespackagecache USING btree (archive);


CREATE INDEX distroseriespackagecache__distroseries__idx ON distroseriespackagecache USING btree (distroseries);


CREATE INDEX distroseriespackagecache_fti ON distroseriespackagecache USING gist (fti);


CREATE INDEX distroseriesparent__derived_series__ordering__idx ON distroseriesparent USING btree (derived_series, ordering);


CREATE INDEX distroseriesparent__parentseries__idx ON distroseriesparent USING btree (parent_series);


CREATE UNIQUE INDEX emailaddress__account__key ON emailaddress USING btree (account) WHERE ((status = 4) AND (account IS NOT NULL));


COMMENT ON INDEX emailaddress__account__key IS 'Ensures that an Account only has one preferred email address';


CREATE INDEX emailaddress__account__status__idx ON emailaddress USING btree (account, status);


CREATE UNIQUE INDEX emailaddress__lower_email__key ON emailaddress USING btree (lower(email));


CREATE UNIQUE INDEX emailaddress__person__key ON emailaddress USING btree (person) WHERE ((status = 4) AND (person IS NOT NULL));


COMMENT ON INDEX emailaddress__person__key IS 'Ensures that a Person only has one preferred email address';


CREATE INDEX emailaddress__person__status__idx ON emailaddress USING btree (person, status);


CREATE INDEX entitlement__approved_by__idx ON entitlement USING btree (approved_by) WHERE (approved_by IS NOT NULL);


CREATE INDEX entitlement__distribution__idx ON entitlement USING btree (distribution) WHERE (distribution IS NOT NULL);


CREATE INDEX entitlement__person__idx ON entitlement USING btree (person);


CREATE INDEX entitlement__product__idx ON entitlement USING btree (product) WHERE (product IS NOT NULL);


CREATE INDEX entitlement__project__idx ON entitlement USING btree (project) WHERE (project IS NOT NULL);


CREATE INDEX entitlement__registrant__idx ON entitlement USING btree (registrant) WHERE (registrant IS NOT NULL);


CREATE INDEX entitlement_lookup_idx ON entitlement USING btree (entitlement_type, date_starts, date_expires, person, state);


CREATE INDEX faq__distribution__idx ON faq USING btree (distribution) WHERE (distribution IS NOT NULL);


CREATE INDEX faq__last_updated_by__idx ON faq USING btree (last_updated_by);


CREATE INDEX faq__owner__idx ON faq USING btree (owner);


CREATE INDEX faq__product__idx ON faq USING btree (product) WHERE (product IS NOT NULL);


CREATE INDEX faq_fti ON faq USING gist (fti);


CREATE INDEX featuredproject__pillar_name__idx ON featuredproject USING btree (pillar_name);


CREATE INDEX featureflagchangelogentry__person__idx ON featureflagchangelogentry USING btree (person);


CREATE INDEX flatpackagesetinclusion__child__idx ON flatpackagesetinclusion USING btree (child);


CREATE INDEX hwdevice__bus_product_id__idx ON hwdevice USING btree (bus_product_id);


CREATE UNIQUE INDEX hwdevice__bus_vendor_id__bus_product_id__key ON hwdevice USING btree (bus_vendor_id, bus_product_id) WHERE (variant IS NULL);


CREATE INDEX hwdevice__name__idx ON hwdevice USING btree (name);


CREATE UNIQUE INDEX hwdeviceclass__device__main_class__key ON hwdeviceclass USING btree (device, main_class) WHERE (sub_class IS NULL);


CREATE UNIQUE INDEX hwdeviceclass__device__main_class__sub_class__key ON hwdeviceclass USING btree (device, main_class, sub_class) WHERE (sub_class IS NOT NULL);


CREATE INDEX hwdeviceclass__main_class__idx ON hwdeviceclass USING btree (main_class);


CREATE INDEX hwdeviceclass__sub_class__idx ON hwdeviceclass USING btree (sub_class);


CREATE UNIQUE INDEX hwdevicedriverlink__device__driver__key ON hwdevicedriverlink USING btree (device, driver) WHERE (driver IS NOT NULL);


CREATE INDEX hwdevicedriverlink__device__idx ON hwdevicedriverlink USING btree (device);


CREATE UNIQUE INDEX hwdevicedriverlink__device__key ON hwdevicedriverlink USING btree (device) WHERE (driver IS NULL);


CREATE INDEX hwdevicedriverlink__driver__idx ON hwdevicedriverlink USING btree (driver);


CREATE INDEX hwdevicenamevariant__device__idx ON hwdevicenamevariant USING btree (device);


CREATE INDEX hwdevicenamevariant__product_name__idx ON hwdevicenamevariant USING btree (product_name);


CREATE INDEX hwdmihandle__submission__idx ON hwdmihandle USING btree (submission);


CREATE INDEX hwdmivalue__hanlde__idx ON hwdmivalue USING btree (handle);


CREATE INDEX hwdriver__name__idx ON hwdriver USING btree (name);


CREATE UNIQUE INDEX hwdriver__name__key ON hwdriver USING btree (name) WHERE (package_name IS NULL);


CREATE INDEX hwsubmission__date_created__idx ON hwsubmission USING btree (date_created);


CREATE INDEX hwsubmission__date_submitted__idx ON hwsubmission USING btree (date_submitted);


CREATE INDEX hwsubmission__lower_raw_emailaddress__idx ON hwsubmission USING btree (lower(raw_emailaddress));


CREATE INDEX hwsubmission__owner__idx ON hwsubmission USING btree (owner);


CREATE INDEX hwsubmission__raw_emailaddress__idx ON hwsubmission USING btree (raw_emailaddress);


CREATE INDEX hwsubmission__raw_submission__idx ON hwsubmission USING btree (raw_submission);


CREATE INDEX hwsubmission__status__idx ON hwsubmission USING btree (status);


CREATE INDEX hwsubmission__system_fingerprint__idx ON hwsubmission USING btree (system_fingerprint);


CREATE INDEX hwsubmissionbug__bug ON hwsubmissionbug USING btree (bug);


CREATE INDEX hwsubmissiondevice__device_driver_link__idx ON hwsubmissiondevice USING btree (device_driver_link);


CREATE INDEX hwsubmissiondevice__parent__idx ON hwsubmissiondevice USING btree (parent);


CREATE INDEX hwsubmissiondevice__submission__idx ON hwsubmissiondevice USING btree (submission);


CREATE UNIQUE INDEX hwtest__name__version__key ON hwtest USING btree (name, version) WHERE (namespace IS NULL);


CREATE UNIQUE INDEX hwtest__namespace__name__version__key ON hwtest USING btree (namespace, name, version) WHERE (namespace IS NOT NULL);


CREATE INDEX hwtestanswer__choice__idx ON hwtestanswer USING btree (choice);


CREATE INDEX hwtestanswer__submission__idx ON hwtestanswer USING btree (submission);


CREATE INDEX hwtestanswer__test__idx ON hwtestanswer USING btree (test);


CREATE INDEX hwtestanswerchoice__test__idx ON hwtestanswerchoice USING btree (test);


CREATE INDEX hwtestanswercount__choice__idx ON hwtestanswercount USING btree (choice);


CREATE INDEX hwtestanswercount__distroarchrelease__idx ON hwtestanswercount USING btree (distroarchseries) WHERE (distroarchseries IS NOT NULL);


CREATE INDEX hwtestanswercount__test__idx ON hwtestanswercount USING btree (test);


CREATE INDEX hwtestanswercountdevice__device_driver__idx ON hwtestanswercountdevice USING btree (device_driver);


CREATE INDEX hwtestanswerdevice__device_driver__idx ON hwtestanswerdevice USING btree (device_driver);


CREATE INDEX hwvendorid__vendor_id_for_bus__idx ON hwvendorid USING btree (vendor_id_for_bus);


CREATE INDEX hwvendorid__vendorname__idx ON hwvendorid USING btree (vendor_name);


CREATE UNIQUE INDEX hwvendorname__lc_vendor_name__idx ON hwvendorname USING btree (ulower(name));


CREATE INDEX incrementaldiff__branch_merge_proposal__idx ON incrementaldiff USING btree (branch_merge_proposal);


CREATE INDEX incrementaldiff__diff__idx ON incrementaldiff USING btree (diff);


CREATE INDEX incrementaldiff__new_revision__idx ON incrementaldiff USING btree (new_revision);


CREATE INDEX incrementaldiff__old_revision__idx ON incrementaldiff USING btree (old_revision);


CREATE INDEX ircid_person_idx ON ircid USING btree (person);


CREATE INDEX jabberid_person_idx ON jabberid USING btree (person);


CREATE INDEX job__date_finished__idx ON job USING btree (date_finished) WHERE (date_finished IS NOT NULL);


CREATE INDEX job__lease_expires__idx ON job USING btree (lease_expires);


CREATE INDEX job__requester__key ON job USING btree (requester) WHERE (requester IS NOT NULL);


CREATE INDEX job__scheduled_start__idx ON job USING btree (scheduled_start);


CREATE INDEX karma_person_datecreated_idx ON karma USING btree (person, datecreated);

ALTER TABLE karma CLUSTER ON karma_person_datecreated_idx;


CREATE INDEX karmacache__category__karmavalue__idx ON karmacache USING btree (category, karmavalue) WHERE ((((category IS NOT NULL) AND (product IS NULL)) AND (project IS NULL)) AND (distribution IS NULL));


CREATE INDEX karmacache__distribution__category__karmavalue__idx ON karmacache USING btree (distribution, category, karmavalue) WHERE (((category IS NOT NULL) AND (distribution IS NOT NULL)) AND (sourcepackagename IS NULL));


CREATE INDEX karmacache__distribution__karmavalue__idx ON karmacache USING btree (distribution, karmavalue) WHERE (((category IS NULL) AND (distribution IS NOT NULL)) AND (sourcepackagename IS NULL));


CREATE INDEX karmacache__karmavalue__idx ON karmacache USING btree (karmavalue) WHERE ((((category IS NULL) AND (product IS NULL)) AND (project IS NULL)) AND (distribution IS NULL));


CREATE INDEX karmacache__person__category__idx ON karmacache USING btree (person, category);


CREATE INDEX karmacache__product__category__karmavalue__idx ON karmacache USING btree (product, category, karmavalue) WHERE ((category IS NOT NULL) AND (product IS NOT NULL));


CREATE INDEX karmacache__product__karmavalue__idx ON karmacache USING btree (product, karmavalue) WHERE ((category IS NULL) AND (product IS NOT NULL));


CREATE INDEX karmacache__project__category__karmavalue__idx ON karmacache USING btree (project, category, karmavalue) WHERE (project IS NOT NULL);


CREATE INDEX karmacache__project__karmavalue__idx ON karmacache USING btree (project, karmavalue) WHERE ((category IS NULL) AND (project IS NOT NULL));


CREATE INDEX karmacache__sourcepackagename__category__karmavalue__idx ON karmacache USING btree (sourcepackagename, distribution, category, karmavalue) WHERE ((category IS NOT NULL) AND (sourcepackagename IS NOT NULL));


CREATE INDEX karmacache__sourcepackagename__distribution__karmavalue__idx ON karmacache USING btree (sourcepackagename, distribution, karmavalue) WHERE (sourcepackagename IS NOT NULL);


CREATE INDEX karmacache__sourcepackagename__karmavalue__idx ON karmacache USING btree (sourcepackagename, distribution, karmavalue) WHERE ((category IS NULL) AND (sourcepackagename IS NOT NULL));


CREATE UNIQUE INDEX karmacache__unq ON karmacache USING btree (person, (COALESCE(product, (-1))), (COALESCE(sourcepackagename, (-1))), (COALESCE(project, (-1))), (COALESCE(category, (-1))), (COALESCE(distribution, (-1))));


CREATE INDEX karmacache_person_idx ON karmacache USING btree (person);


CREATE INDEX karmacache_top_in_category_idx ON karmacache USING btree (person, category, karmavalue) WHERE ((((product IS NULL) AND (project IS NULL)) AND (sourcepackagename IS NULL)) AND (distribution IS NULL));


CREATE UNIQUE INDEX karmatotalcache_karma_total_person_idx ON karmatotalcache USING btree (karma_total, person);


CREATE INDEX languagepack__file__idx ON languagepack USING btree (file);


CREATE INDEX libraryfilealias__expires__idx ON libraryfilealias USING btree (expires);


CREATE INDEX libraryfilealias__expires_content_not_null_idx ON libraryfilealias USING btree (expires) WHERE (content IS NOT NULL);


CREATE INDEX libraryfilealias__filename__idx ON libraryfilealias USING btree (filename);


CREATE INDEX libraryfilealias_content_idx ON libraryfilealias USING btree (content);


CREATE INDEX libraryfilecontent__md5__idx ON libraryfilecontent USING btree (md5);


CREATE INDEX libraryfilecontent__sha256__idx ON libraryfilecontent USING btree (sha256);


CREATE INDEX libraryfilecontent_sha1_filesize_idx ON libraryfilecontent USING btree (sha1, filesize);


CREATE INDEX logintoken_requester_idx ON logintoken USING btree (requester);


CREATE INDEX lp_openididentifier__account__idx ON lp_openididentifier USING btree (account);


CREATE INDEX lp_teamparticipation__person__idx ON lp_teamparticipation USING btree (person);


CREATE INDEX mailinglist__date_registered__idx ON mailinglist USING btree (status, date_registered);


CREATE INDEX mailinglist__registrant__idx ON mailinglist USING btree (registrant);


CREATE INDEX mailinglist__reviewer__idx ON mailinglist USING btree (reviewer);


CREATE UNIQUE INDEX mailinglist__team__status__key ON mailinglist USING btree (team, status);


CREATE INDEX mailinglistsubscription__email_address__idx ON mailinglistsubscription USING btree (email_address) WHERE (email_address IS NOT NULL);


CREATE INDEX mailinglistsubscription__mailing_list__idx ON mailinglistsubscription USING btree (mailing_list);


CREATE UNIQUE INDEX mailinglistsubscription__person__mailing_list__key ON mailinglistsubscription USING btree (person, mailing_list);


CREATE INDEX mergedirectivejob__merge_directive__idx ON mergedirectivejob USING btree (merge_directive);


CREATE INDEX message__datecreated__idx ON message USING btree (datecreated);


CREATE INDEX message_fti ON message USING gist (fti);


CREATE INDEX message_owner_idx ON message USING btree (owner);


CREATE INDEX message_parent_idx ON message USING btree (parent);


CREATE INDEX message_raw_idx ON message USING btree (raw) WHERE (raw IS NOT NULL);


CREATE INDEX message_rfc822msgid_idx ON message USING btree (rfc822msgid);


CREATE INDEX messageapproval__disposed_by__idx ON messageapproval USING btree (disposed_by) WHERE (disposed_by IS NOT NULL);


CREATE INDEX messageapproval__mailing_list__status__posted_date__idx ON messageapproval USING btree (mailing_list, status, posted_date);


CREATE INDEX messageapproval__message__idx ON messageapproval USING btree (message);


CREATE INDEX messageapproval__posted_by__idx ON messageapproval USING btree (posted_by);


CREATE INDEX messageapproval__posted_message__idx ON messageapproval USING btree (posted_message);


CREATE INDEX messagechunk_blob_idx ON messagechunk USING btree (blob) WHERE (blob IS NOT NULL);


CREATE INDEX messagechunk_fti ON messagechunk USING gist (fti);


CREATE INDEX milestone_dateexpected_name_sort ON milestone USING btree (milestone_sort_key(dateexpected, name));


CREATE INDEX mirror__owner__idx ON mirror USING btree (owner);


CREATE UNIQUE INDEX mirrordistroarchseries_uniq ON mirrordistroarchseries USING btree (distribution_mirror, distroarchseries, component, pocket);


CREATE UNIQUE INDEX mirrordistroseriessource_uniq ON mirrordistroseriessource USING btree (distribution_mirror, distroseries, component, pocket);


CREATE INDEX mirrorproberecord__date_created__idx ON mirrorproberecord USING btree (date_created);


CREATE INDEX mirrorproberecord__distribution_mirror__date_created__idx ON mirrorproberecord USING btree (distribution_mirror, date_created);


CREATE INDEX mirrorproberecord__log_file__idx ON mirrorproberecord USING btree (log_file) WHERE (log_file IS NOT NULL);


CREATE INDEX oauthaccesstoken__consumer__idx ON oauthaccesstoken USING btree (consumer);


CREATE INDEX oauthaccesstoken__date_expires__idx ON oauthaccesstoken USING btree (date_expires) WHERE (date_expires IS NOT NULL);


CREATE INDEX oauthaccesstoken__distribution__sourcepackagename__idx ON oauthaccesstoken USING btree (distribution, sourcepackagename) WHERE (distribution IS NOT NULL);


CREATE INDEX oauthaccesstoken__person__idx ON oauthaccesstoken USING btree (person);


CREATE INDEX oauthaccesstoken__product__idx ON oauthaccesstoken USING btree (product) WHERE (product IS NOT NULL);


CREATE INDEX oauthaccesstoken__project__idx ON oauthaccesstoken USING btree (project) WHERE (project IS NOT NULL);


CREATE INDEX oauthnonce__access_token__idx ON oauthnonce USING btree (access_token);


CREATE INDEX oauthnonce__request_timestamp__idx ON oauthnonce USING btree (request_timestamp);


CREATE INDEX oauthrequesttoken__consumer__idx ON oauthrequesttoken USING btree (consumer);


CREATE INDEX oauthrequesttoken__date_created__idx ON oauthrequesttoken USING btree (date_created);


CREATE INDEX oauthrequesttoken__distribution__sourcepackagename__idx ON oauthrequesttoken USING btree (distribution, sourcepackagename) WHERE (distribution IS NOT NULL);


CREATE INDEX oauthrequesttoken__person__idx ON oauthrequesttoken USING btree (person) WHERE (person IS NOT NULL);


CREATE INDEX oauthrequesttoken__product__idx ON oauthrequesttoken USING btree (product) WHERE (product IS NOT NULL);


CREATE INDEX oauthrequesttoken__project__idx ON oauthrequesttoken USING btree (project) WHERE (project IS NOT NULL);


CREATE UNIQUE INDEX officialbugtag__distribution__tag__key ON officialbugtag USING btree (distribution, tag) WHERE (distribution IS NOT NULL);


CREATE UNIQUE INDEX officialbugtag__product__tag__key ON officialbugtag USING btree (product, tag) WHERE (product IS NOT NULL);


CREATE UNIQUE INDEX officialbugtag__project__tag__key ON officialbugtag USING btree (project, tag) WHERE (product IS NOT NULL);


CREATE INDEX openididentifier__account__idx ON openididentifier USING btree (account);


CREATE INDEX packagebuild__archive__idx ON packagebuild USING btree (archive);


CREATE UNIQUE INDEX packagebuild__build_farm_job__idx ON packagebuild USING btree (build_farm_job);


CREATE INDEX packagebuild__upload_log__idx ON packagebuild USING btree (upload_log) WHERE (upload_log IS NOT NULL);


CREATE UNIQUE INDEX packagecopyjob__job_type__target_ds__id__key ON packagecopyjob USING btree (job_type, target_distroseries, id);


CREATE INDEX packagecopyjob__source ON packagecopyjob USING btree (source_archive);


CREATE INDEX packagecopyjob__target ON packagecopyjob USING btree (target_archive, target_distroseries);


CREATE INDEX packagecopyrequest__datecreated__idx ON packagecopyrequest USING btree (date_created);


CREATE INDEX packagecopyrequest__requester__idx ON packagecopyrequest USING btree (requester);


CREATE INDEX packagecopyrequest__targetarchive__idx ON packagecopyrequest USING btree (target_archive);


CREATE INDEX packagecopyrequest__targetdistroseries__idx ON packagecopyrequest USING btree (target_distroseries) WHERE (target_distroseries IS NOT NULL);


CREATE INDEX packagediff__diff_content__idx ON packagediff USING btree (diff_content);


CREATE INDEX packagediff__from_source__idx ON packagediff USING btree (from_source);


CREATE INDEX packagediff__requester__idx ON packagediff USING btree (requester);


CREATE INDEX packagediff__status__idx ON packagediff USING btree (status);


CREATE INDEX packagediff__to_source__idx ON packagediff USING btree (to_source);


CREATE INDEX packageset__distroseries__idx ON packageset USING btree (distroseries);


CREATE INDEX packageset__owner__idx ON packageset USING btree (owner);


CREATE INDEX packageset__packagesetgroup__idx ON packageset USING btree (packagesetgroup);


CREATE INDEX packagesetgroup__owner__idx ON packagesetgroup USING btree (owner);


CREATE INDEX packagesetinclusion__child__idx ON packagesetinclusion USING btree (child);


CREATE INDEX packagesetsources__sourcepackagename__idx ON packagesetsources USING btree (sourcepackagename);


CREATE INDEX packageupload__archive__distroseries__status__idx ON packageupload USING btree (archive, distroseries, status);


CREATE INDEX packageupload__changesfile__idx ON packageupload USING btree (changesfile);


CREATE INDEX packageupload__distroseries__key ON packageupload USING btree (distroseries);


CREATE INDEX packageupload__distroseries__status__idx ON packageupload USING btree (distroseries, status);


CREATE INDEX packageupload__package_copy_job__idx ON packageupload USING btree (package_copy_job) WHERE (package_copy_job IS NOT NULL);


CREATE INDEX packageupload__signing_key__idx ON packageupload USING btree (signing_key);


CREATE INDEX packageuploadbuild__build__idx ON packageuploadbuild USING btree (build);


CREATE INDEX packageuploadcustom__libraryfilealias__idx ON packageuploadcustom USING btree (libraryfilealias);


CREATE INDEX packageuploadcustom__packageupload__idx ON packageuploadcustom USING btree (packageupload);


CREATE INDEX packageuploadsource__sourcepackagerelease__idx ON packageuploadsource USING btree (sourcepackagerelease);


CREATE INDEX packaging__owner__idx ON packaging USING btree (owner);


CREATE INDEX packaging_sourcepackagename_idx ON packaging USING btree (sourcepackagename);


CREATE INDEX packagingjob__job__idx ON packagingjob USING btree (job);


CREATE INDEX packagingjob__potemplate__idx ON packagingjob USING btree (potemplate);


CREATE INDEX parsedapachelog__first_line__idx ON parsedapachelog USING btree (first_line);


CREATE INDEX person__displayname__idx ON person USING btree (lower(displayname));


CREATE INDEX person__icon__idx ON person USING btree (icon) WHERE (icon IS NOT NULL);


CREATE INDEX person__logo__idx ON person USING btree (logo) WHERE (logo IS NOT NULL);


CREATE INDEX person__merged__idx ON person USING btree (merged) WHERE (merged IS NOT NULL);


CREATE INDEX person__mugshot__idx ON person USING btree (mugshot) WHERE (mugshot IS NOT NULL);


CREATE INDEX person__registrant__idx ON person USING btree (registrant);


CREATE INDEX person__teamowner__idx ON person USING btree (teamowner) WHERE (teamowner IS NOT NULL);


CREATE INDEX person_datecreated_idx ON person USING btree (datecreated);


CREATE INDEX person_fti ON person USING gist (fti);


CREATE INDEX person_sorting_idx ON person USING btree (person_sort_key(displayname, name));


CREATE INDEX personlocation__last_modified_by__idx ON personlocation USING btree (last_modified_by);


CREATE INDEX personnotification__date_emailed__idx ON personnotification USING btree (date_emailed);


CREATE INDEX personnotification__person__idx ON personnotification USING btree (person);


CREATE INDEX persontransferjob__major_person__idx ON persontransferjob USING btree (major_person);


CREATE INDEX persontransferjob__minor_person__idx ON persontransferjob USING btree (minor_person);


CREATE INDEX pillarname__alias_for__idx ON pillarname USING btree (alias_for) WHERE (alias_for IS NOT NULL);


CREATE UNIQUE INDEX pillarname__distribution__key ON pillarname USING btree (distribution) WHERE (distribution IS NOT NULL);


CREATE UNIQUE INDEX pillarname__product__key ON pillarname USING btree (product) WHERE (product IS NOT NULL);


CREATE UNIQUE INDEX pillarname__project__key ON pillarname USING btree (project) WHERE (project IS NOT NULL);


CREATE INDEX pocketchroot__chroot__idx ON pocketchroot USING btree (chroot);


CREATE INDEX poexportrequest__person__idx ON poexportrequest USING btree (person);


CREATE UNIQUE INDEX poexportrequest_duplicate_key ON poexportrequest USING btree (potemplate, person, format, (COALESCE(pofile, (-1))));


CREATE INDEX pofile__from_sourcepackagename__idx ON pofile USING btree (from_sourcepackagename) WHERE (from_sourcepackagename IS NOT NULL);


CREATE UNIQUE INDEX pofile__potemplate__language__idx ON pofile USING btree (potemplate, language);


CREATE UNIQUE INDEX pofile__potemplate__path__key ON pofile USING btree (potemplate, path);


CREATE UNIQUE INDEX pofile__unreviewed_count__id__key ON pofile USING btree (unreviewed_count, id);


CREATE INDEX pofile_datecreated_idx ON pofile USING btree (datecreated);


CREATE INDEX pofile_language_idx ON pofile USING btree (language);


CREATE INDEX pofile_lasttranslator_idx ON pofile USING btree (lasttranslator);


CREATE INDEX pofile_owner_idx ON pofile USING btree (owner);


CREATE INDEX pofiletranslator__date_last_touched__idx ON pofiletranslator USING btree (date_last_touched);


CREATE INDEX pofiletranslator__latest_message__idx ON pofiletranslator USING btree (latest_message);


CREATE INDEX pofiletranslator__pofile__idx ON pofiletranslator USING btree (pofile);


CREATE INDEX polloption_poll_idx ON polloption USING btree (poll);


CREATE UNIQUE INDEX pomsgid_msgid_key ON pomsgid USING btree (sha1(msgid));


CREATE INDEX potemplate__date_last_updated__idx ON potemplate USING btree (date_last_updated);


CREATE UNIQUE INDEX potemplate__distroseries__sourcepackagename__name__key ON potemplate USING btree (distroseries, sourcepackagename, name);


CREATE INDEX potemplate__name__idx ON potemplate USING btree (name);


CREATE UNIQUE INDEX potemplate__productseries__name__key ON potemplate USING btree (productseries, name);


CREATE INDEX potemplate__source_file__idx ON potemplate USING btree (source_file) WHERE (source_file IS NOT NULL);


CREATE INDEX potemplate_languagepack_idx ON potemplate USING btree (languagepack);


CREATE INDEX potemplate_owner_idx ON potemplate USING btree (owner);


CREATE INDEX potmsgset__context__msgid_singular__msgid_plural__idx ON potmsgset USING btree (context, msgid_singular, msgid_plural) WHERE ((context IS NOT NULL) AND (msgid_plural IS NOT NULL));


CREATE INDEX potmsgset__context__msgid_singular__no_msgid_plural__idx ON potmsgset USING btree (context, msgid_singular) WHERE ((context IS NOT NULL) AND (msgid_plural IS NULL));


CREATE INDEX potmsgset__no_context__msgid_singular__msgid_plural__idx ON potmsgset USING btree (msgid_singular, msgid_plural) WHERE ((context IS NULL) AND (msgid_plural IS NOT NULL));


CREATE INDEX potmsgset__no_context__msgid_singular__no_msgid_plural__idx ON potmsgset USING btree (msgid_singular) WHERE ((context IS NULL) AND (msgid_plural IS NULL));


CREATE INDEX potmsgset__potemplate__idx ON potmsgset USING btree (potemplate) WHERE (potemplate IS NOT NULL);


CREATE INDEX potmsgset_primemsgid_idx ON potmsgset USING btree (msgid_singular);


CREATE UNIQUE INDEX potranslation_translation_key ON potranslation USING btree (sha1(translation));


CREATE INDEX previewdiff__diff__idx ON previewdiff USING btree (diff);


CREATE INDEX product__bug_supervisor__idx ON product USING btree (bug_supervisor) WHERE (bug_supervisor IS NOT NULL);


CREATE INDEX product__driver__idx ON product USING btree (driver) WHERE (driver IS NOT NULL);


CREATE INDEX product__icon__idx ON product USING btree (icon) WHERE (icon IS NOT NULL);


CREATE INDEX product__logo__idx ON product USING btree (logo) WHERE (logo IS NOT NULL);


CREATE INDEX product__mugshot__idx ON product USING btree (mugshot) WHERE (mugshot IS NOT NULL);


CREATE INDEX product__registrant__idx ON product USING btree (registrant);


CREATE INDEX product__security_contact__idx ON product USING btree (security_contact) WHERE (security_contact IS NOT NULL);


CREATE INDEX product_active_idx ON product USING btree (active);


CREATE INDEX product_fti ON product USING gist (fti);


CREATE INDEX product_owner_idx ON product USING btree (owner);


CREATE INDEX product_project_idx ON product USING btree (project);


CREATE INDEX product_translationgroup_idx ON product USING btree (translationgroup);


CREATE INDEX productlicense__license__idx ON productlicense USING btree (license);


CREATE INDEX productrelease_datecreated_idx ON productrelease USING btree (datecreated);


CREATE INDEX productrelease_owner_idx ON productrelease USING btree (owner);


CREATE INDEX productreleasefile__libraryfile__idx ON productreleasefile USING btree (libraryfile);


CREATE INDEX productreleasefile__signature__idx ON productreleasefile USING btree (signature) WHERE (signature IS NOT NULL);


CREATE INDEX productreleasefile__uploader__idx ON productreleasefile USING btree (uploader);


CREATE INDEX productreleasefile_fti ON productreleasefile USING gist (fti);


CREATE INDEX productseries__branch__idx ON productseries USING btree (branch) WHERE (branch IS NOT NULL);


CREATE INDEX productseries__driver__idx ON productseries USING btree (driver);


CREATE INDEX productseries__owner__idx ON productseries USING btree (owner);


CREATE INDEX productseries__translations_branch__idx ON productseries USING btree (translations_branch);


CREATE INDEX productseries_datecreated_idx ON productseries USING btree (datecreated);


CREATE INDEX productseries_name_sort ON productseries USING btree (version_sort_key(name));


CREATE INDEX project__driver__idx ON project USING btree (driver);


CREATE INDEX project__icon__idx ON project USING btree (icon) WHERE (icon IS NOT NULL);


CREATE INDEX project__logo__idx ON project USING btree (logo) WHERE (logo IS NOT NULL);


CREATE INDEX project__mugshot__idx ON project USING btree (mugshot) WHERE (mugshot IS NOT NULL);


CREATE INDEX project__registrant__idx ON project USING btree (registrant);


CREATE INDEX project_fti ON project USING gist (fti);


CREATE INDEX project_owner_idx ON project USING btree (owner);


CREATE INDEX project_translationgroup_idx ON project USING btree (translationgroup);


CREATE UNIQUE INDEX publisherconfig__distribution__idx ON publisherconfig USING btree (distribution);


CREATE INDEX question__answerer__idx ON question USING btree (answerer);


CREATE INDEX question__assignee__idx ON question USING btree (assignee);


CREATE INDEX question__distribution__sourcepackagename__idx ON question USING btree (distribution, sourcepackagename);


CREATE INDEX question__distro__datecreated__idx ON question USING btree (distribution, datecreated);


CREATE INDEX question__faq__idx ON question USING btree (faq) WHERE (faq IS NOT NULL);


CREATE INDEX question__owner__idx ON question USING btree (owner);


CREATE INDEX question__product__datecreated__idx ON question USING btree (product, datecreated);


CREATE INDEX question__product__idx ON question USING btree (product);


CREATE INDEX question__status__datecreated__idx ON question USING btree (status, datecreated);


CREATE INDEX question_fti ON question USING gist (fti);


CREATE INDEX questionbug__question__idx ON questionbug USING btree (question);


CREATE INDEX questionjob__question__idx ON questionjob USING btree (question);


CREATE INDEX questionmessage__owner__idx ON questionmessage USING btree (owner);


CREATE INDEX questionmessage__question__idx ON questionmessage USING btree (question);


CREATE INDEX questionreopening__answerer__idx ON questionreopening USING btree (answerer);


CREATE INDEX questionreopening__datecreated__idx ON questionreopening USING btree (datecreated);


CREATE INDEX questionreopening__question__idx ON questionreopening USING btree (question);


CREATE INDEX questionreopening__reopener__idx ON questionreopening USING btree (reopener);


CREATE INDEX questionsubscription__subscriber__idx ON questionsubscription USING btree (person);


CREATE INDEX revision__gpgkey__idx ON revision USING btree (gpgkey) WHERE (gpgkey IS NOT NULL);


CREATE INDEX revision__karma_allocated__idx ON revision USING btree (karma_allocated) WHERE (karma_allocated IS FALSE);


CREATE INDEX revision__revision_author__idx ON revision USING btree (revision_author);


CREATE INDEX revision__revision_date__idx ON revision USING btree (revision_date);


CREATE INDEX revisionauthor__email__idx ON revisionauthor USING btree (email);


CREATE INDEX revisionauthor__lower_email__idx ON revisionauthor USING btree (lower(email));


CREATE INDEX revisionauthor__person__idx ON revisionauthor USING btree (person);


CREATE UNIQUE INDEX revisioncache__distroseries__sourcepackagename__revision__priva ON revisioncache USING btree (distroseries, sourcepackagename, revision, private) WHERE (distroseries IS NOT NULL);


CREATE UNIQUE INDEX revisioncache__product__revision__private__key ON revisioncache USING btree (product, revision, private) WHERE (product IS NOT NULL);


CREATE INDEX revisioncache__revision__idx ON revisioncache USING btree (revision);


CREATE INDEX revisioncache__revision_author__idx ON revisioncache USING btree (revision_author);


CREATE INDEX revisioncache__revision_date__idx ON revisioncache USING btree (revision_date);


CREATE INDEX sbpph__dateremoved__idx ON binarypackagepublishinghistory USING btree (dateremoved) WHERE (dateremoved IS NOT NULL);


CREATE INDEX scriptactivity__name__date_started__idx ON scriptactivity USING btree (name, date_started);


CREATE INDEX securebinarypackagepublishinghistory__archive__status__idx ON binarypackagepublishinghistory USING btree (archive, status);


CREATE INDEX securebinarypackagepublishinghistory__distroarchseries__idx ON binarypackagepublishinghistory USING btree (distroarchseries);


CREATE INDEX securebinarypackagepublishinghistory__removed_by__idx ON binarypackagepublishinghistory USING btree (removed_by) WHERE (removed_by IS NOT NULL);


CREATE INDEX securebinarypackagepublishinghistory__supersededby__idx ON binarypackagepublishinghistory USING btree (supersededby);


CREATE INDEX securebinarypackagepublishinghistory_binarypackagerelease_idx ON binarypackagepublishinghistory USING btree (binarypackagerelease);


CREATE INDEX securebinarypackagepublishinghistory_component_idx ON binarypackagepublishinghistory USING btree (component);


CREATE INDEX securebinarypackagepublishinghistory_pocket_idx ON binarypackagepublishinghistory USING btree (pocket);


CREATE INDEX securebinarypackagepublishinghistory_section_idx ON binarypackagepublishinghistory USING btree (section);


CREATE INDEX securebinarypackagepublishinghistory_status_idx ON binarypackagepublishinghistory USING btree (status);


CREATE INDEX securesourcepackagepublishinghistory__archive__status__idx ON sourcepackagepublishinghistory USING btree (archive, status);


CREATE INDEX securesourcepackagepublishinghistory__distroseries__idx ON sourcepackagepublishinghistory USING btree (distroseries);


CREATE INDEX securesourcepackagepublishinghistory__removed_by__idx ON sourcepackagepublishinghistory USING btree (removed_by) WHERE (removed_by IS NOT NULL);


CREATE INDEX securesourcepackagepublishinghistory_component_idx ON sourcepackagepublishinghistory USING btree (component);


CREATE INDEX securesourcepackagepublishinghistory_pocket_idx ON sourcepackagepublishinghistory USING btree (pocket);


CREATE INDEX securesourcepackagepublishinghistory_section_idx ON sourcepackagepublishinghistory USING btree (section);


CREATE INDEX securesourcepackagepublishinghistory_sourcepackagerelease_idx ON sourcepackagepublishinghistory USING btree (sourcepackagerelease);


CREATE INDEX securesourcepackagepublishinghistory_status_idx ON sourcepackagepublishinghistory USING btree (status);


CREATE INDEX seriessourcepackagebranch__branch__idx ON seriessourcepackagebranch USING btree (branch);


CREATE INDEX seriessourcepackagebranch__registrant__key ON seriessourcepackagebranch USING btree (registrant);


CREATE INDEX signedcodeofconduct_owner_idx ON signedcodeofconduct USING btree (owner);


CREATE INDEX sourcepackagepublishinghistory__ancestor__idx ON sourcepackagepublishinghistory USING btree (ancestor);


CREATE INDEX sourcepackagepublishinghistory__creator__idx ON sourcepackagepublishinghistory USING btree (creator) WHERE (creator IS NOT NULL);


CREATE INDEX sourcepackagepublishinghistory__sourcepackagename__idx ON sourcepackagepublishinghistory USING btree (sourcepackagename);


CREATE INDEX sourcepackagerecipe__daily_build_archive__idx ON sourcepackagerecipe USING btree (daily_build_archive);


CREATE INDEX sourcepackagerecipe__is_stale__build_daily__idx ON sourcepackagerecipe USING btree (is_stale, build_daily);


CREATE INDEX sourcepackagerecipe__registrant__idx ON sourcepackagerecipe USING btree (registrant);


CREATE INDEX sourcepackagerecipebuild__distroseries__idx ON sourcepackagerecipebuild USING btree (distroseries);


CREATE INDEX sourcepackagerecipebuild__manifest__idx ON sourcepackagerecipebuild USING btree (manifest);


CREATE INDEX sourcepackagerecipebuild__recipe__idx ON sourcepackagerecipebuild USING btree (recipe);


CREATE INDEX sourcepackagerecipebuild__requester__idx ON sourcepackagerecipebuild USING btree (requester);


CREATE INDEX sourcepackagerecipedata__base_branch__idx ON sourcepackagerecipedata USING btree (base_branch);


CREATE UNIQUE INDEX sourcepackagerecipedata__sourcepackage_recipe__key ON sourcepackagerecipedata USING btree (sourcepackage_recipe) WHERE (sourcepackage_recipe IS NOT NULL);


CREATE UNIQUE INDEX sourcepackagerecipedata__sourcepackage_recipe_build__key ON sourcepackagerecipedata USING btree (sourcepackage_recipe_build) WHERE (sourcepackage_recipe_build IS NOT NULL);


CREATE INDEX sourcepackagerecipedatainstruction__branch__idx ON sourcepackagerecipedatainstruction USING btree (branch);


CREATE INDEX sourcepackagerelease__changelog__idx ON sourcepackagerelease USING btree (changelog);


CREATE INDEX sourcepackagerelease__sourcepackage_recipe_build__idx ON sourcepackagerelease USING btree (sourcepackage_recipe_build);


CREATE INDEX sourcepackagerelease__upload_archive__idx ON sourcepackagerelease USING btree (upload_archive);


CREATE INDEX sourcepackagerelease__version__idx ON sourcepackagerelease USING btree (version);


CREATE INDEX sourcepackagerelease_creator_idx ON sourcepackagerelease USING btree (creator);


CREATE INDEX sourcepackagerelease_maintainer_idx ON sourcepackagerelease USING btree (maintainer);


CREATE INDEX sourcepackagerelease_sourcepackagename_idx ON sourcepackagerelease USING btree (sourcepackagename);


CREATE INDEX sourcepackagereleasefile_libraryfile_idx ON sourcepackagereleasefile USING btree (libraryfile);


CREATE INDEX sourcepackagereleasefile_sourcepackagerelease_idx ON sourcepackagereleasefile USING btree (sourcepackagerelease);


CREATE INDEX specification__completer__idx ON specification USING btree (completer);


CREATE INDEX specification__goal_decider__idx ON specification USING btree (goal_decider);


CREATE INDEX specification__goal_proposer__idx ON specification USING btree (goal_proposer);


CREATE INDEX specification__starter__idx ON specification USING btree (starter);


CREATE INDEX specification_approver_idx ON specification USING btree (approver);


CREATE INDEX specification_assignee_idx ON specification USING btree (assignee);


CREATE INDEX specification_datecreated_idx ON specification USING btree (datecreated);


CREATE INDEX specification_drafter_idx ON specification USING btree (drafter);


CREATE INDEX specification_fti ON specification USING gist (fti);


CREATE INDEX specification_owner_idx ON specification USING btree (owner);


CREATE INDEX specificationbranch__registrant__idx ON specificationbranch USING btree (registrant);


CREATE INDEX specificationbranch__specification__idx ON specificationbranch USING btree (specification);


CREATE INDEX specificationbug_bug_idx ON specificationbug USING btree (bug);


CREATE INDEX specificationbug_specification_idx ON specificationbug USING btree (specification);


CREATE INDEX specificationdependency_dependency_idx ON specificationdependency USING btree (dependency);


CREATE INDEX specificationdependency_specification_idx ON specificationdependency USING btree (specification);


CREATE INDEX specificationfeedback_requester_idx ON specificationfeedback USING btree (requester);


CREATE INDEX specificationfeedback_reviewer_idx ON specificationfeedback USING btree (reviewer);


CREATE INDEX specificationsubscription_specification_idx ON specificationsubscription USING btree (specification);


CREATE INDEX specificationsubscription_subscriber_idx ON specificationsubscription USING btree (person);


CREATE INDEX sprint__driver__idx ON sprint USING btree (driver);


CREATE INDEX sprint__icon__idx ON sprint USING btree (icon) WHERE (icon IS NOT NULL);


CREATE INDEX sprint__logo__idx ON sprint USING btree (logo) WHERE (logo IS NOT NULL);


CREATE INDEX sprint__mugshot__idx ON sprint USING btree (mugshot) WHERE (mugshot IS NOT NULL);


CREATE INDEX sprint__owner__idx ON sprint USING btree (owner);


CREATE INDEX sprint_datecreated_idx ON sprint USING btree (datecreated);


CREATE INDEX sprintattendance_sprint_idx ON sprintattendance USING btree (sprint);


CREATE INDEX sprintspec_sprint_idx ON sprintspecification USING btree (sprint);


CREATE INDEX sprintspecification__decider__idx ON sprintspecification USING btree (decider);


CREATE INDEX sprintspecification__registrant__idx ON sprintspecification USING btree (registrant);


CREATE INDEX sshkey_person_key ON sshkey USING btree (person);


CREATE UNIQUE INDEX structuralsubscription__distribution__sourcepackagename__subscr ON structuralsubscription USING btree (distribution, sourcepackagename, subscriber) WHERE ((distribution IS NOT NULL) AND (sourcepackagename IS NOT NULL));


CREATE UNIQUE INDEX structuralsubscription__distribution__subscriber__key ON structuralsubscription USING btree (distribution, subscriber) WHERE ((distribution IS NOT NULL) AND (sourcepackagename IS NULL));


CREATE UNIQUE INDEX structuralsubscription__distroseries__subscriber__key ON structuralsubscription USING btree (distroseries, subscriber) WHERE (distroseries IS NOT NULL);


CREATE UNIQUE INDEX structuralsubscription__milestone__subscriber__key ON structuralsubscription USING btree (milestone, subscriber) WHERE (milestone IS NOT NULL);


CREATE UNIQUE INDEX structuralsubscription__product__subscriber__key ON structuralsubscription USING btree (product, subscriber) WHERE (product IS NOT NULL);


CREATE UNIQUE INDEX structuralsubscription__productseries__subscriber__key ON structuralsubscription USING btree (productseries, subscriber) WHERE (productseries IS NOT NULL);


CREATE UNIQUE INDEX structuralsubscription__project__subscriber__key ON structuralsubscription USING btree (project, subscriber) WHERE (project IS NOT NULL);


CREATE INDEX structuralsubscription__subscribed_by__idx ON structuralsubscription USING btree (subscribed_by);


CREATE INDEX structuralsubscription__subscriber__idx ON structuralsubscription USING btree (subscriber);


CREATE INDEX subunitstream__branch_created__idx ON subunitstream USING btree (branch, date_created);


CREATE INDEX subunitstream__stream__idx ON subunitstream USING btree (stream);


CREATE INDEX subunitstream__uploader_created__idx ON subunitstream USING btree (uploader, date_created);


CREATE INDEX teammembership__acknowledged_by__idx ON teammembership USING btree (acknowledged_by) WHERE (acknowledged_by IS NOT NULL);


CREATE INDEX teammembership__last_changed_by__idx ON teammembership USING btree (last_changed_by) WHERE (last_changed_by IS NOT NULL);


CREATE INDEX teammembership__proposed_by__idx ON teammembership USING btree (proposed_by) WHERE (proposed_by IS NOT NULL);


CREATE INDEX teammembership__reviewed_by__idx ON teammembership USING btree (reviewed_by) WHERE (reviewed_by IS NOT NULL);


CREATE INDEX teammembership__team__idx ON teammembership USING btree (team);


CREATE INDEX teamparticipation_person_idx ON teamparticipation USING btree (person);

ALTER TABLE teamparticipation CLUSTER ON teamparticipation_person_idx;


CREATE INDEX tm__potmsgset__language__not_used__idx ON translationmessage USING btree (potmsgset, language) WHERE (NOT ((is_current_ubuntu IS TRUE) AND (is_current_upstream IS TRUE)));


CREATE UNIQUE INDEX tm__potmsgset__language__shared__ubuntu__key ON translationmessage USING btree (potmsgset, language) WHERE ((is_current_ubuntu IS TRUE) AND (potemplate IS NULL));


CREATE UNIQUE INDEX tm__potmsgset__language__shared__upstream__key ON translationmessage USING btree (potmsgset, language) WHERE ((is_current_upstream IS TRUE) AND (potemplate IS NULL));


CREATE UNIQUE INDEX tm__potmsgset__template__language__diverged__ubuntu__key ON translationmessage USING btree (potmsgset, potemplate, language) WHERE ((is_current_ubuntu IS TRUE) AND (potemplate IS NOT NULL));


CREATE UNIQUE INDEX tm__potmsgset__template__language__diverged__upstream__key ON translationmessage USING btree (potmsgset, potemplate, language) WHERE ((is_current_upstream IS TRUE) AND (potemplate IS NOT NULL));


CREATE INDEX translationgroup__owner__idx ON translationgroup USING btree (owner);


CREATE INDEX translationimportqueueentry__content__idx ON translationimportqueueentry USING btree (content) WHERE (content IS NOT NULL);


CREATE INDEX translationimportqueueentry__context__path__idx ON translationimportqueueentry USING btree (distroseries, sourcepackagename, productseries, path);


CREATE UNIQUE INDEX translationimportqueueentry__entry_per_importer__unq ON translationimportqueueentry USING btree (importer, path, (COALESCE(potemplate, (-1))), (COALESCE(distroseries, (-1))), (COALESCE(sourcepackagename, (-1))), (COALESCE(productseries, (-1))));


CREATE INDEX translationimportqueueentry__path__idx ON translationimportqueueentry USING btree (path);


CREATE INDEX translationimportqueueentry__pofile__idx ON translationimportqueueentry USING btree (pofile) WHERE (pofile IS NOT NULL);


CREATE INDEX translationimportqueueentry__potemplate__idx ON translationimportqueueentry USING btree (potemplate) WHERE (potemplate IS NOT NULL);


CREATE INDEX translationimportqueueentry__productseries__idx ON translationimportqueueentry USING btree (productseries) WHERE (productseries IS NOT NULL);


CREATE INDEX translationimportqueueentry__sourcepackagename__idx ON translationimportqueueentry USING btree (sourcepackagename) WHERE (sourcepackagename IS NOT NULL);


CREATE UNIQUE INDEX translationimportqueueentry__status__dateimported__id__idx ON translationimportqueueentry USING btree (status, dateimported, id);


CREATE INDEX translationmessage__msgstr0__idx ON translationmessage USING btree (msgstr0);


CREATE INDEX translationmessage__msgstr1__idx ON translationmessage USING btree (msgstr1) WHERE (msgstr1 IS NOT NULL);


CREATE INDEX translationmessage__msgstr2__idx ON translationmessage USING btree (msgstr2) WHERE (msgstr2 IS NOT NULL);


CREATE INDEX translationmessage__msgstr3__idx ON translationmessage USING btree (msgstr3) WHERE (msgstr3 IS NOT NULL);


CREATE INDEX translationmessage__msgstr4__idx ON translationmessage USING btree (msgstr4) WHERE (msgstr4 IS NOT NULL);


CREATE INDEX translationmessage__msgstr5__idx ON translationmessage USING btree (msgstr5) WHERE (msgstr5 IS NOT NULL);


CREATE INDEX translationmessage__potemplate__idx ON translationmessage USING btree (potemplate) WHERE (potemplate IS NOT NULL);


CREATE INDEX translationmessage__potmsgset__idx ON translationmessage USING btree (potmsgset);


CREATE INDEX translationmessage__potmsgset__language__idx ON translationmessage USING btree (potmsgset, language);


CREATE INDEX translationmessage__reviewer__idx ON translationmessage USING btree (reviewer);


CREATE INDEX translationmessage__submitter__idx ON translationmessage USING btree (submitter);


CREATE UNIQUE INDEX translationtemplateitem__potemplate__potmsgset__key ON translationtemplateitem USING btree (potemplate, potmsgset);


CREATE INDEX translationtemplateitem__potemplate__sequence__idx ON translationtemplateitem USING btree (potemplate, sequence);


CREATE UNIQUE INDEX translationtemplateitem__potemplate__sequence__key ON translationtemplateitem USING btree (potemplate, sequence) WHERE (sequence > 0);


CREATE INDEX translationtemplateitem__potmsgset__idx ON translationtemplateitem USING btree (potmsgset);


CREATE INDEX translationtemplatesbuild__branch__idx ON translationtemplatesbuild USING btree (branch);


CREATE INDEX translationtemplatesbuild__build_farm_job__idx ON translationtemplatesbuild USING btree (build_farm_job);


CREATE INDEX translator__translator__idx ON translator USING btree (translator);


CREATE INDEX usertouseremail__recipient__idx ON usertouseremail USING btree (recipient);


CREATE INDEX usertouseremail__sender__date_sent__idx ON usertouseremail USING btree (sender, date_sent);


CREATE INDEX vote__person__idx ON vote USING btree (person);


CREATE INDEX votecast_poll_idx ON votecast USING btree (poll);


CREATE INDEX wikiname_person_idx ON wikiname USING btree (person);


CREATE TRIGGER bug_latest_patch_uploaded_on_delete_t
    AFTER DELETE ON bugattachment
    FOR EACH ROW
    EXECUTE PROCEDURE bug_update_latest_patch_uploaded_on_delete();


CREATE TRIGGER bug_latest_patch_uploaded_on_insert_update_t
    AFTER INSERT OR UPDATE ON bugattachment
    FOR EACH ROW
    EXECUTE PROCEDURE bug_update_latest_patch_uploaded_on_insert_update();


CREATE TRIGGER bug_maintain_bug_summary_trigger
    AFTER DELETE OR UPDATE ON bug
    FOR EACH ROW
    EXECUTE PROCEDURE bug_maintain_bug_summary();


CREATE TRIGGER bug_to_bugtask_heat
    AFTER UPDATE ON bug
    FOR EACH ROW
    EXECUTE PROCEDURE bug_update_heat_copy_to_bugtask();


CREATE TRIGGER bugmessage__owner__mirror
    AFTER INSERT OR UPDATE ON bugmessage
    FOR EACH ROW
    EXECUTE PROCEDURE bugmessage_copy_owner_from_message();


CREATE TRIGGER bugsubscription_maintain_bug_summary_after_trigger
    AFTER INSERT OR DELETE OR UPDATE ON bugsubscription
    FOR EACH ROW
    EXECUTE PROCEDURE bugsubscription_maintain_bug_summary();


CREATE TRIGGER bugsubscription_maintain_bug_summary_before_trigger
    BEFORE INSERT OR DELETE OR UPDATE ON bugsubscription
    FOR EACH ROW
    EXECUTE PROCEDURE bugsubscription_maintain_bug_summary();


CREATE TRIGGER bugtag_maintain_bug_summary_after_trigger
    AFTER INSERT OR DELETE OR UPDATE ON bugtag
    FOR EACH ROW
    EXECUTE PROCEDURE bugtag_maintain_bug_summary();


CREATE TRIGGER bugtag_maintain_bug_summary_before_trigger
    BEFORE INSERT OR DELETE OR UPDATE ON bugtag
    FOR EACH ROW
    EXECUTE PROCEDURE bugtag_maintain_bug_summary();


CREATE TRIGGER bugtask_maintain_bug_summary_after_trigger
    AFTER INSERT OR DELETE OR UPDATE ON bugtask
    FOR EACH ROW
    EXECUTE PROCEDURE bugtask_maintain_bug_summary();


CREATE TRIGGER bugtask_maintain_bug_summary_before_trigger
    BEFORE INSERT OR DELETE OR UPDATE ON bugtask
    FOR EACH ROW
    EXECUTE PROCEDURE bugtask_maintain_bug_summary();


CREATE TRIGGER lp_mirror_openididentifier_del_t
    AFTER DELETE ON openididentifier
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_openididentifier_del();


CREATE TRIGGER lp_mirror_openididentifier_ins_t
    AFTER INSERT ON openididentifier
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_openididentifier_ins();


CREATE TRIGGER lp_mirror_openididentifier_upd_t
    AFTER UPDATE ON openididentifier
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_openididentifier_upd();


CREATE TRIGGER lp_mirror_person_del_t
    AFTER DELETE ON person
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_del();


CREATE TRIGGER lp_mirror_person_ins_t
    AFTER INSERT ON person
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_person_ins();


CREATE TRIGGER lp_mirror_person_upd_t
    AFTER UPDATE ON person
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_person_upd();


CREATE TRIGGER lp_mirror_personlocation_del_t
    AFTER DELETE ON teamparticipation
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_del();


CREATE TRIGGER lp_mirror_personlocation_ins_t
    AFTER INSERT ON personlocation
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_personlocation_ins();


CREATE TRIGGER lp_mirror_personlocation_upd_t
    AFTER UPDATE ON personlocation
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_personlocation_upd();


CREATE TRIGGER lp_mirror_teamparticipation_del_t
    AFTER DELETE ON teamparticipation
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_del();


CREATE TRIGGER lp_mirror_teamparticipation_ins_t
    AFTER INSERT ON teamparticipation
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_teamparticipation_ins();


CREATE TRIGGER lp_mirror_teamparticipation_upd_t
    AFTER UPDATE ON teamparticipation
    FOR EACH ROW
    EXECUTE PROCEDURE lp_mirror_teamparticipation_upd();


CREATE TRIGGER maintain_branch_transitive_privacy_t
    AFTER INSERT OR UPDATE ON branch
    FOR EACH ROW
    EXECUTE PROCEDURE maintain_transitively_private();


CREATE TRIGGER message__owner__mirror
    AFTER UPDATE ON message
    FOR EACH ROW
    EXECUTE PROCEDURE message_copy_owner_to_bugmessage();


CREATE TRIGGER message__owner__mirror__questionmessage
    AFTER UPDATE ON message
    FOR EACH ROW
    EXECUTE PROCEDURE message_copy_owner_to_questionmessage();


CREATE TRIGGER mv_branch_distribution_update_t
    AFTER UPDATE ON distribution
    FOR EACH ROW
    EXECUTE PROCEDURE mv_branch_distribution_update();


CREATE TRIGGER mv_branch_distroseries_update_t
    AFTER UPDATE ON distroseries
    FOR EACH ROW
    EXECUTE PROCEDURE mv_branch_distroseries_update();


CREATE TRIGGER mv_branch_person_update_t
    AFTER UPDATE ON person
    FOR EACH ROW
    EXECUTE PROCEDURE mv_branch_person_update();


CREATE TRIGGER mv_branch_product_update_t
    AFTER UPDATE ON product
    FOR EACH ROW
    EXECUTE PROCEDURE mv_branch_product_update();


CREATE TRIGGER mv_pillarname_distribution_t
    AFTER INSERT OR UPDATE ON distribution
    FOR EACH ROW
    EXECUTE PROCEDURE mv_pillarname_distribution();


CREATE TRIGGER mv_pillarname_product_t
    AFTER INSERT OR UPDATE ON product
    FOR EACH ROW
    EXECUTE PROCEDURE mv_pillarname_product();


CREATE TRIGGER mv_pillarname_project_t
    AFTER INSERT OR UPDATE ON project
    FOR EACH ROW
    EXECUTE PROCEDURE mv_pillarname_project();


CREATE TRIGGER mv_pofiletranslator_translationmessage
    AFTER INSERT OR DELETE OR UPDATE ON translationmessage
    FOR EACH ROW
    EXECUTE PROCEDURE mv_pofiletranslator_translationmessage();


CREATE TRIGGER packageset_deleted_trig
    BEFORE DELETE ON packageset
    FOR EACH ROW
    EXECUTE PROCEDURE packageset_deleted_trig();


CREATE TRIGGER packageset_inserted_trig
    AFTER INSERT ON packageset
    FOR EACH ROW
    EXECUTE PROCEDURE packageset_inserted_trig();


CREATE TRIGGER packagesetinclusion_deleted_trig
    BEFORE DELETE ON packagesetinclusion
    FOR EACH ROW
    EXECUTE PROCEDURE packagesetinclusion_deleted_trig();


CREATE TRIGGER packagesetinclusion_inserted_trig
    AFTER INSERT ON packagesetinclusion
    FOR EACH ROW
    EXECUTE PROCEDURE packagesetinclusion_inserted_trig();


CREATE TRIGGER questionmessage__owner__mirror
    AFTER INSERT OR UPDATE ON questionmessage
    FOR EACH ROW
    EXECUTE PROCEDURE questionmessage_copy_owner_from_message();


CREATE TRIGGER set_bug_message_count_t
    AFTER INSERT OR DELETE OR UPDATE ON bugmessage
    FOR EACH ROW
    EXECUTE PROCEDURE set_bug_message_count();


CREATE TRIGGER set_bug_number_of_duplicates_t
    AFTER INSERT OR DELETE OR UPDATE ON bug
    FOR EACH ROW
    EXECUTE PROCEDURE set_bug_number_of_duplicates();


CREATE TRIGGER set_bug_users_affected_count_t
    AFTER INSERT OR DELETE OR UPDATE ON bugaffectsperson
    FOR EACH ROW
    EXECUTE PROCEDURE set_bug_users_affected_count();


CREATE TRIGGER set_bugtask_date_milestone_set_t
    AFTER INSERT OR UPDATE ON bugtask
    FOR EACH ROW
    EXECUTE PROCEDURE set_bugtask_date_milestone_set();


CREATE TRIGGER set_date_last_message_t
    AFTER INSERT OR DELETE OR UPDATE ON bugmessage
    FOR EACH ROW
    EXECUTE PROCEDURE set_bug_date_last_message();


CREATE TRIGGER set_date_status_set_t
    BEFORE UPDATE ON account
    FOR EACH ROW
    EXECUTE PROCEDURE set_date_status_set();


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON binarypackagerelease
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('summary', 'b', 'description', 'c');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON cve
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('sequence', 'a', 'description', 'b');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON distroseriespackagecache
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('name', 'a', 'summaries', 'b', 'descriptions', 'c');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON message
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('subject', 'b');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON messagechunk
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('content', 'c');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON product
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('name', 'a', 'displayname', 'a', 'title', 'b', 'summary', 'c', 'description', 'd');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON project
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('name', 'a', 'displayname', 'a', 'title', 'b', 'summary', 'c', 'description', 'd');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON question
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('title', 'a', 'description', 'b', 'whiteboard', 'b');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON bug
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('name', 'a', 'title', 'b', 'description', 'd');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON person
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('name', 'a', 'displayname', 'a');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON specification
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('name', 'a', 'title', 'a', 'summary', 'b', 'whiteboard', 'd');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON distribution
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('name', 'a', 'displayname', 'a', 'title', 'b', 'summary', 'c', 'description', 'd');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON distributionsourcepackagecache
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('name', 'a', 'binpkgnames', 'b', 'binpkgsummaries', 'c', 'binpkgdescriptions', 'd', 'changelog', 'd');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON productreleasefile
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('description', 'd');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON faq
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('title', 'a', 'tags', 'b', 'content', 'd');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON archive
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('description', 'a', 'package_description_cache', 'b');


CREATE TRIGGER tsvectorupdate
    BEFORE INSERT OR UPDATE ON bugtask
    FOR EACH ROW
    EXECUTE PROCEDURE ts2.ftiupdate('targetnamecache', 'b');


CREATE TRIGGER update_branch_name_cache_t
    BEFORE INSERT OR UPDATE ON branch
    FOR EACH ROW
    EXECUTE PROCEDURE update_branch_name_cache();


CREATE TRIGGER you_are_your_own_member
    AFTER INSERT ON person
    FOR EACH ROW
    EXECUTE PROCEDURE you_are_your_own_member();


ALTER TABLE ONLY processor
    ADD CONSTRAINT "$1" FOREIGN KEY (family) REFERENCES processorfamily(id);


ALTER TABLE ONLY builder
    ADD CONSTRAINT "$1" FOREIGN KEY (processor) REFERENCES processor(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT "$1" FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY libraryfilealias
    ADD CONSTRAINT "$1" FOREIGN KEY (content) REFERENCES libraryfilecontent(id);


ALTER TABLE ONLY productreleasefile
    ADD CONSTRAINT "$1" FOREIGN KEY (productrelease) REFERENCES productrelease(id);


ALTER TABLE ONLY spokenin
    ADD CONSTRAINT "$1" FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY bugsubscription
    ADD CONSTRAINT "$1" FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY bugactivity
    ADD CONSTRAINT "$1" FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY sshkey
    ADD CONSTRAINT "$1" FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY polloption
    ADD CONSTRAINT "$1" FOREIGN KEY (poll) REFERENCES poll(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT "$1" FOREIGN KEY (bug_supervisor) REFERENCES person(id);


ALTER TABLE ONLY country
    ADD CONSTRAINT "$1" FOREIGN KEY (continent) REFERENCES continent(id);


ALTER TABLE ONLY sourcepackagereleasefile
    ADD CONSTRAINT "$1" FOREIGN KEY (sourcepackagerelease) REFERENCES sourcepackagerelease(id) ON DELETE CASCADE;


ALTER TABLE ONLY builder
    ADD CONSTRAINT "$2" FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY productreleasefile
    ADD CONSTRAINT "$2" FOREIGN KEY (libraryfile) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY sourcepackagereleasefile
    ADD CONSTRAINT "$2" FOREIGN KEY (libraryfile) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY spokenin
    ADD CONSTRAINT "$2" FOREIGN KEY (country) REFERENCES country(id);


ALTER TABLE ONLY bugsubscription
    ADD CONSTRAINT "$2" FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY buildqueue
    ADD CONSTRAINT "$2" FOREIGN KEY (builder) REFERENCES builder(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT "$2" FOREIGN KEY (members) REFERENCES person(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT "$3" FOREIGN KEY (bug_supervisor) REFERENCES person(id);


ALTER TABLE ONLY pofile
    ADD CONSTRAINT "$3" FOREIGN KEY (from_sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY accesspolicy
    ADD CONSTRAINT accesspolicy_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY accesspolicy
    ADD CONSTRAINT accesspolicy_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY accesspolicyartifact
    ADD CONSTRAINT accesspolicyartifact_branch_fkey FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY accesspolicyartifact
    ADD CONSTRAINT accesspolicyartifact_bug_fkey FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY accesspolicyartifact
    ADD CONSTRAINT accesspolicyartifact_policy_fkey FOREIGN KEY (policy) REFERENCES accesspolicy(id);


ALTER TABLE ONLY accesspolicygrant
    ADD CONSTRAINT accesspolicygrant_artifact_fkey FOREIGN KEY (artifact) REFERENCES accesspolicyartifact(id);


ALTER TABLE ONLY accesspolicygrant
    ADD CONSTRAINT accesspolicygrant_grantee_fkey FOREIGN KEY (grantee) REFERENCES person(id);


ALTER TABLE ONLY accesspolicygrant
    ADD CONSTRAINT accesspolicygrant_grantor_fkey FOREIGN KEY (grantor) REFERENCES person(id);


ALTER TABLE ONLY accesspolicygrant
    ADD CONSTRAINT accesspolicygrant_policy_fkey FOREIGN KEY (policy) REFERENCES accesspolicy(id);


ALTER TABLE ONLY accountpassword
    ADD CONSTRAINT accountpassword_account_fkey FOREIGN KEY (account) REFERENCES account(id) ON DELETE CASCADE;


ALTER TABLE ONLY karma
    ADD CONSTRAINT action_fkey FOREIGN KEY (action) REFERENCES karmaaction(id);


ALTER TABLE ONLY announcement
    ADD CONSTRAINT announcement_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY announcement
    ADD CONSTRAINT announcement_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY announcement
    ADD CONSTRAINT announcement_project_fkey FOREIGN KEY (project) REFERENCES project(id);


ALTER TABLE ONLY announcement
    ADD CONSTRAINT announcement_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY answercontact
    ADD CONSTRAINT answercontact__distribution__fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY answercontact
    ADD CONSTRAINT answercontact__person__fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY answercontact
    ADD CONSTRAINT answercontact__product__fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY answercontact
    ADD CONSTRAINT answercontact__sourcepackagename__fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY apportjob
    ADD CONSTRAINT apportjob_blob_fkey FOREIGN KEY (blob) REFERENCES temporaryblobstorage(id);


ALTER TABLE ONLY apportjob
    ADD CONSTRAINT apportjob_job_fkey FOREIGN KEY (job) REFERENCES job(id);


ALTER TABLE ONLY archive
    ADD CONSTRAINT archive__distribution__fk FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY archive
    ADD CONSTRAINT archive__owner__fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY archive
    ADD CONSTRAINT archive_signing_key_fkey FOREIGN KEY (signing_key) REFERENCES gpgkey(id);


ALTER TABLE ONLY archivearch
    ADD CONSTRAINT archivearch__archive__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY archivearch
    ADD CONSTRAINT archivearch__processorfamily__fk FOREIGN KEY (processorfamily) REFERENCES processorfamily(id);


ALTER TABLE ONLY archiveauthtoken
    ADD CONSTRAINT archiveauthtoken__archive__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY archiveauthtoken
    ADD CONSTRAINT archiveauthtoken_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY archivedependency
    ADD CONSTRAINT archivedependency__archive__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY archivedependency
    ADD CONSTRAINT archivedependency__dependency__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY archivedependency
    ADD CONSTRAINT archivedependency_component_fkey FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY archivejob
    ADD CONSTRAINT archivejob__archive__fk FOREIGN KEY (archive) REFERENCES archive(id);


ALTER TABLE ONLY archivejob
    ADD CONSTRAINT archivejob__job__fk FOREIGN KEY (job) REFERENCES job(id) ON DELETE CASCADE;


ALTER TABLE ONLY archivepermission
    ADD CONSTRAINT archivepermission__archive__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY archivepermission
    ADD CONSTRAINT archivepermission__component__fk FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY archivepermission
    ADD CONSTRAINT archivepermission__packageset__fk FOREIGN KEY (packageset) REFERENCES packageset(id);


ALTER TABLE ONLY archivepermission
    ADD CONSTRAINT archivepermission__person__fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY archivepermission
    ADD CONSTRAINT archivepermission__sourcepackagename__fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY archivesubscriber
    ADD CONSTRAINT archivesubscriber__archive__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY archivesubscriber
    ADD CONSTRAINT archivesubscriber_cancelled_by_fkey FOREIGN KEY (cancelled_by) REFERENCES person(id);


ALTER TABLE ONLY archivesubscriber
    ADD CONSTRAINT archivesubscriber_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY archivesubscriber
    ADD CONSTRAINT archivesubscriber_subscriber_fkey FOREIGN KEY (subscriber) REFERENCES person(id);


ALTER TABLE ONLY binarypackagebuild
    ADD CONSTRAINT binarypackagebuild__distro_arch_series__fk FOREIGN KEY (distro_arch_series) REFERENCES distroarchseries(id);


ALTER TABLE ONLY binarypackagebuild
    ADD CONSTRAINT binarypackagebuild__package_build__fk FOREIGN KEY (package_build) REFERENCES packagebuild(id);


ALTER TABLE ONLY binarypackagebuild
    ADD CONSTRAINT binarypackagebuild__source_package_release__fk FOREIGN KEY (source_package_release) REFERENCES sourcepackagerelease(id);


ALTER TABLE ONLY binarypackagefile
    ADD CONSTRAINT binarypackagefile_binarypackagerelease_fk FOREIGN KEY (binarypackagerelease) REFERENCES binarypackagerelease(id) ON DELETE CASCADE;


ALTER TABLE ONLY binarypackagefile
    ADD CONSTRAINT binarypackagefile_libraryfile_fk FOREIGN KEY (libraryfile) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY binarypackagepublishinghistory
    ADD CONSTRAINT binarypackagepublishinghistory_binarypackagename_fkey FOREIGN KEY (binarypackagename) REFERENCES binarypackagename(id);


ALTER TABLE ONLY binarypackagepublishinghistory
    ADD CONSTRAINT binarypackagepublishinghistory_supersededby_fk FOREIGN KEY (supersededby) REFERENCES binarypackagebuild(id);


ALTER TABLE ONLY binarypackagerelease
    ADD CONSTRAINT binarypackagerelease_binarypackagename_fk FOREIGN KEY (binarypackagename) REFERENCES binarypackagename(id);


ALTER TABLE ONLY binarypackagerelease
    ADD CONSTRAINT binarypackagerelease_build_fk FOREIGN KEY (build) REFERENCES binarypackagebuild(id) ON DELETE CASCADE;


ALTER TABLE ONLY binarypackagerelease
    ADD CONSTRAINT binarypackagerelease_component_fk FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY binarypackagerelease
    ADD CONSTRAINT binarypackagerelease_debug_package_fkey FOREIGN KEY (debug_package) REFERENCES binarypackagerelease(id);


ALTER TABLE ONLY binarypackagerelease
    ADD CONSTRAINT binarypackagerelease_section_fk FOREIGN KEY (section) REFERENCES section(id);


ALTER TABLE ONLY binarypackagereleasecontents
    ADD CONSTRAINT binarypackagereleasecontents_binarypackagepath_fkey FOREIGN KEY (binarypackagepath) REFERENCES binarypackagepath(id);


ALTER TABLE ONLY binarypackagereleasecontents
    ADD CONSTRAINT binarypackagereleasecontents_binarypackagerelease_fkey FOREIGN KEY (binarypackagerelease) REFERENCES binarypackagerelease(id);


ALTER TABLE ONLY binarypackagereleasedownloadcount
    ADD CONSTRAINT binarypackagereleasedownloadcount_archive_fkey FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY binarypackagereleasedownloadcount
    ADD CONSTRAINT binarypackagereleasedownloadcount_binary_package_release_fkey FOREIGN KEY (binary_package_release) REFERENCES binarypackagerelease(id);


ALTER TABLE ONLY binarypackagereleasedownloadcount
    ADD CONSTRAINT binarypackagereleasedownloadcount_country_fkey FOREIGN KEY (country) REFERENCES country(id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_access_policy_fkey FOREIGN KEY (access_policy) REFERENCES accesspolicy(id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_author_fk FOREIGN KEY (author) REFERENCES person(id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_distroseries_fkey FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY incrementaldiff
    ADD CONSTRAINT branch_merge_proposal_fk FOREIGN KEY (branch_merge_proposal) REFERENCES branchmergeproposal(id) ON DELETE CASCADE;


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_merge_queue_fkey FOREIGN KEY (merge_queue) REFERENCES branchmergequeue(id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_product_fk FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_reviewer_fkey FOREIGN KEY (reviewer) REFERENCES person(id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY branch
    ADD CONSTRAINT branch_stacked_on_fkey FOREIGN KEY (stacked_on) REFERENCES branch(id);


ALTER TABLE ONLY branchjob
    ADD CONSTRAINT branchjob_branch_fkey FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY branchjob
    ADD CONSTRAINT branchjob_job_fkey FOREIGN KEY (job) REFERENCES job(id) ON DELETE CASCADE;


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_dependent_branch_fkey FOREIGN KEY (dependent_branch) REFERENCES branch(id);


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_merge_diff_fkey FOREIGN KEY (merge_diff) REFERENCES previewdiff(id);


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_merge_log_file_fkey FOREIGN KEY (merge_log_file) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_merge_reporter_fkey FOREIGN KEY (merge_reporter) REFERENCES person(id);


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_merger_fkey FOREIGN KEY (merger) REFERENCES person(id);


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_queuer_fkey FOREIGN KEY (queuer) REFERENCES person(id);


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_reviewer_fkey FOREIGN KEY (reviewer) REFERENCES person(id);


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_source_branch_fkey FOREIGN KEY (source_branch) REFERENCES branch(id);


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_superseded_by_fkey FOREIGN KEY (superseded_by) REFERENCES branchmergeproposal(id);


ALTER TABLE ONLY branchmergeproposal
    ADD CONSTRAINT branchmergeproposal_target_branch_fkey FOREIGN KEY (target_branch) REFERENCES branch(id);


ALTER TABLE ONLY branchmergeproposaljob
    ADD CONSTRAINT branchmergeproposaljob_branch_merge_proposal_fkey FOREIGN KEY (branch_merge_proposal) REFERENCES branchmergeproposal(id);


ALTER TABLE ONLY branchmergeproposaljob
    ADD CONSTRAINT branchmergeproposaljob_job_fkey FOREIGN KEY (job) REFERENCES job(id) ON DELETE CASCADE;


ALTER TABLE ONLY branchmergequeue
    ADD CONSTRAINT branchmergequeue_owner_fkey FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY branchmergequeue
    ADD CONSTRAINT branchmergequeue_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY branchrevision
    ADD CONSTRAINT branchrevision__branch__fk FOREIGN KEY (branch) REFERENCES branch(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;


ALTER TABLE ONLY branchrevision
    ADD CONSTRAINT branchrevision__revision__fk FOREIGN KEY (revision) REFERENCES revision(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;


ALTER TABLE ONLY branchsubscription
    ADD CONSTRAINT branchsubscription_branch_fk FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY branchsubscription
    ADD CONSTRAINT branchsubscription_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY branchsubscription
    ADD CONSTRAINT branchsubscription_subscribed_by_fkey FOREIGN KEY (subscribed_by) REFERENCES person(id);


ALTER TABLE ONLY branchvisibilitypolicy
    ADD CONSTRAINT branchvisibilitypolicy_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY branchvisibilitypolicy
    ADD CONSTRAINT branchvisibilitypolicy_project_fkey FOREIGN KEY (project) REFERENCES project(id);


ALTER TABLE ONLY branchvisibilitypolicy
    ADD CONSTRAINT branchvisibilitypolicy_team_fkey FOREIGN KEY (team) REFERENCES person(id);


ALTER TABLE ONLY bug
    ADD CONSTRAINT bug__who_made_private__fk FOREIGN KEY (who_made_private) REFERENCES person(id);


ALTER TABLE ONLY bug
    ADD CONSTRAINT bug_access_policy_fkey FOREIGN KEY (access_policy) REFERENCES accesspolicy(id);


ALTER TABLE ONLY bug
    ADD CONSTRAINT bug_duplicateof_fk FOREIGN KEY (duplicateof) REFERENCES bug(id);


ALTER TABLE ONLY bug
    ADD CONSTRAINT bug_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY bugactivity
    ADD CONSTRAINT bugactivity__person__fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY bugaffectsperson
    ADD CONSTRAINT bugaffectsperson_bug_fkey FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugaffectsperson
    ADD CONSTRAINT bugaffectsperson_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY bugattachment
    ADD CONSTRAINT bugattachment_bug_fk FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugattachment
    ADD CONSTRAINT bugattachment_libraryfile_fk FOREIGN KEY (libraryfile) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY bugattachment
    ADD CONSTRAINT bugattachment_message_fk FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY bugbranch
    ADD CONSTRAINT bugbranch_branch_fkey FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY bugbranch
    ADD CONSTRAINT bugbranch_bug_fkey FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugbranch
    ADD CONSTRAINT bugbranch_fixed_in_revision_fkey FOREIGN KEY (revision_hint) REFERENCES revision(id);


ALTER TABLE ONLY bugbranch
    ADD CONSTRAINT bugbranch_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY bugcve
    ADD CONSTRAINT bugcve_bug_fk FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugcve
    ADD CONSTRAINT bugcve_cve_fk FOREIGN KEY (cve) REFERENCES cve(id);


ALTER TABLE ONLY bugjob
    ADD CONSTRAINT bugjob_bug_fkey FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugjob
    ADD CONSTRAINT bugjob_job_fkey FOREIGN KEY (job) REFERENCES job(id);


ALTER TABLE ONLY bugmessage
    ADD CONSTRAINT bugmessage__bug__fk FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugmessage
    ADD CONSTRAINT bugmessage_bugwatch_fkey FOREIGN KEY (bugwatch) REFERENCES bugwatch(id);


ALTER TABLE ONLY bugmessage
    ADD CONSTRAINT bugmessage_message_fk FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY bugmute
    ADD CONSTRAINT bugmute_bug_fkey FOREIGN KEY (bug) REFERENCES bug(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugmute
    ADD CONSTRAINT bugmute_person_fkey FOREIGN KEY (person) REFERENCES person(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugnomination
    ADD CONSTRAINT bugnomination__bug__fk FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugnomination
    ADD CONSTRAINT bugnomination__decider__fk FOREIGN KEY (decider) REFERENCES person(id);


ALTER TABLE ONLY bugnomination
    ADD CONSTRAINT bugnomination__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY bugnomination
    ADD CONSTRAINT bugnomination__owner__fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY bugnomination
    ADD CONSTRAINT bugnomination__productseries__fk FOREIGN KEY (productseries) REFERENCES productseries(id);


ALTER TABLE ONLY bugnotification
    ADD CONSTRAINT bugnotification_activity_fkey FOREIGN KEY (activity) REFERENCES bugactivity(id);


ALTER TABLE ONLY bugnotification
    ADD CONSTRAINT bugnotification_bug_fkey FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugnotification
    ADD CONSTRAINT bugnotification_message_fkey FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY bugnotificationarchive
    ADD CONSTRAINT bugnotificationarchive__bug__fk FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugnotificationarchive
    ADD CONSTRAINT bugnotificationarchive__message__fk FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY bugnotificationattachment
    ADD CONSTRAINT bugnotificationattachment__bug_notification__fk FOREIGN KEY (bug_notification) REFERENCES bugnotification(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugnotificationattachment
    ADD CONSTRAINT bugnotificationattachment_message_fkey FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY bugnotificationfilter
    ADD CONSTRAINT bugnotificationfilter_bug_notification_fkey FOREIGN KEY (bug_notification) REFERENCES bugnotification(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugnotificationfilter
    ADD CONSTRAINT bugnotificationfilter_bug_subscription_filter_fkey FOREIGN KEY (bug_subscription_filter) REFERENCES bugsubscriptionfilter(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugnotificationrecipient
    ADD CONSTRAINT bugnotificationrecipient__bug_notification__fk FOREIGN KEY (bug_notification) REFERENCES bugnotification(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugnotificationrecipient
    ADD CONSTRAINT bugnotificationrecipient_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY bugnotificationrecipientarchive
    ADD CONSTRAINT bugnotificationrecipientarchive__bug_notification__fk FOREIGN KEY (bug_notification) REFERENCES bugnotificationarchive(id);


ALTER TABLE ONLY bugnotificationrecipientarchive
    ADD CONSTRAINT bugnotificationrecipientarchive__person__fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY bugsubscription
    ADD CONSTRAINT bugsubscription_subscribed_by_fkey FOREIGN KEY (subscribed_by) REFERENCES person(id);


ALTER TABLE ONLY bugsubscriptionfilter
    ADD CONSTRAINT bugsubscriptionfilter__structuralsubscription__fk FOREIGN KEY (structuralsubscription) REFERENCES structuralsubscription(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsubscriptionfilterimportance
    ADD CONSTRAINT bugsubscriptionfilterimportance_filter_fkey FOREIGN KEY (filter) REFERENCES bugsubscriptionfilter(id);


ALTER TABLE ONLY bugsubscriptionfiltermute
    ADD CONSTRAINT bugsubscriptionfiltermute_filter_fkey FOREIGN KEY (filter) REFERENCES bugsubscriptionfilter(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsubscriptionfiltermute
    ADD CONSTRAINT bugsubscriptionfiltermute_person_fkey FOREIGN KEY (person) REFERENCES person(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsubscriptionfilterstatus
    ADD CONSTRAINT bugsubscriptionfilterstatus_filter_fkey FOREIGN KEY (filter) REFERENCES bugsubscriptionfilter(id);


ALTER TABLE ONLY bugsubscriptionfiltertag
    ADD CONSTRAINT bugsubscriptionfiltertag_filter_fkey FOREIGN KEY (filter) REFERENCES bugsubscriptionfilter(id);


ALTER TABLE ONLY bugsummary
    ADD CONSTRAINT bugsummary_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummary
    ADD CONSTRAINT bugsummary_distroseries_fkey FOREIGN KEY (distroseries) REFERENCES distroseries(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummary
    ADD CONSTRAINT bugsummary_milestone_fkey FOREIGN KEY (milestone) REFERENCES milestone(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummary
    ADD CONSTRAINT bugsummary_product_fkey FOREIGN KEY (product) REFERENCES product(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummary
    ADD CONSTRAINT bugsummary_productseries_fkey FOREIGN KEY (productseries) REFERENCES productseries(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummary
    ADD CONSTRAINT bugsummary_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummaryjournal
    ADD CONSTRAINT bugsummaryjournal_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummaryjournal
    ADD CONSTRAINT bugsummaryjournal_distroseries_fkey FOREIGN KEY (distroseries) REFERENCES distroseries(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummaryjournal
    ADD CONSTRAINT bugsummaryjournal_milestone_fkey FOREIGN KEY (milestone) REFERENCES milestone(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummaryjournal
    ADD CONSTRAINT bugsummaryjournal_product_fkey FOREIGN KEY (product) REFERENCES product(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummaryjournal
    ADD CONSTRAINT bugsummaryjournal_productseries_fkey FOREIGN KEY (productseries) REFERENCES productseries(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummaryjournal
    ADD CONSTRAINT bugsummaryjournal_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugsummary
    ADD CONSTRAINT bugsummaryjournal_viewed_by_fkey FOREIGN KEY (viewed_by) REFERENCES person(id) ON DELETE CASCADE;


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__assignee__fk FOREIGN KEY (assignee) REFERENCES person(id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__binarypackagename__fk FOREIGN KEY (binarypackagename) REFERENCES binarypackagename(id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__bug__fk FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__bugwatch__fk FOREIGN KEY (bugwatch) REFERENCES bugwatch(id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__distribution__fk FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__distribution__milestone__fk FOREIGN KEY (distribution, milestone) REFERENCES milestone(distribution, id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__owner__fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__product__fk FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__product__milestone__fk FOREIGN KEY (product, milestone) REFERENCES milestone(product, id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__productseries__fk FOREIGN KEY (productseries) REFERENCES productseries(id);


ALTER TABLE ONLY bugtask
    ADD CONSTRAINT bugtask__sourcepackagename__fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY bugtracker
    ADD CONSTRAINT bugtracker_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY bugtrackeralias
    ADD CONSTRAINT bugtrackeralias__bugtracker__fk FOREIGN KEY (bugtracker) REFERENCES bugtracker(id);


ALTER TABLE ONLY bugtrackercomponent
    ADD CONSTRAINT bugtrackercomponent_component_group_fkey FOREIGN KEY (component_group) REFERENCES bugtrackercomponentgroup(id);


ALTER TABLE ONLY bugtrackercomponent
    ADD CONSTRAINT bugtrackercomponent_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY bugtrackercomponent
    ADD CONSTRAINT bugtrackercomponent_source_package_name_fkey FOREIGN KEY (source_package_name) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY bugtrackercomponentgroup
    ADD CONSTRAINT bugtrackercomponentgroup_bug_tracker_fkey FOREIGN KEY (bug_tracker) REFERENCES bugtracker(id);


ALTER TABLE ONLY bugtrackerperson
    ADD CONSTRAINT bugtrackerperson_bugtracker_fkey FOREIGN KEY (bugtracker) REFERENCES bugtracker(id);


ALTER TABLE ONLY bugtrackerperson
    ADD CONSTRAINT bugtrackerperson_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY bugwatch
    ADD CONSTRAINT bugwatch_bug_fk FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY bugwatch
    ADD CONSTRAINT bugwatch_bugtracker_fk FOREIGN KEY (bugtracker) REFERENCES bugtracker(id);


ALTER TABLE ONLY bugwatch
    ADD CONSTRAINT bugwatch_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY bugwatchactivity
    ADD CONSTRAINT bugwatchactivity_bug_watch_fkey FOREIGN KEY (bug_watch) REFERENCES bugwatch(id);


ALTER TABLE ONLY buildfarmjob
    ADD CONSTRAINT buildfarmjob__builder__fk FOREIGN KEY (builder) REFERENCES builder(id);


ALTER TABLE ONLY buildfarmjob
    ADD CONSTRAINT buildfarmjob__log__fk FOREIGN KEY (log) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY buildfarmjob
    ADD CONSTRAINT buildfarmjob__processor__fk FOREIGN KEY (processor) REFERENCES processor(id);


ALTER TABLE ONLY buildpackagejob
    ADD CONSTRAINT buildpackagejob__job__fk FOREIGN KEY (job) REFERENCES job(id);


ALTER TABLE ONLY buildpackagejob
    ADD CONSTRAINT buildpackagejob_build_fk FOREIGN KEY (build) REFERENCES binarypackagebuild(id);


ALTER TABLE ONLY buildqueue
    ADD CONSTRAINT buildqueue__job__fk FOREIGN KEY (job) REFERENCES job(id);


ALTER TABLE ONLY buildqueue
    ADD CONSTRAINT buildqueue__processor__fk FOREIGN KEY (processor) REFERENCES processor(id);


ALTER TABLE ONLY codeimport
    ADD CONSTRAINT codeimport_assignee_fkey FOREIGN KEY (assignee) REFERENCES person(id);


ALTER TABLE ONLY codeimport
    ADD CONSTRAINT codeimport_branch_fkey FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY codeimport
    ADD CONSTRAINT codeimport_owner_fkey FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY codeimport
    ADD CONSTRAINT codeimport_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY codeimportevent
    ADD CONSTRAINT codeimportevent__code_import__fk FOREIGN KEY (code_import) REFERENCES codeimport(id) ON DELETE CASCADE;


ALTER TABLE ONLY codeimportevent
    ADD CONSTRAINT codeimportevent__machine__fk FOREIGN KEY (machine) REFERENCES codeimportmachine(id);


ALTER TABLE ONLY codeimportevent
    ADD CONSTRAINT codeimportevent__person__fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY codeimporteventdata
    ADD CONSTRAINT codeimporteventdata__event__fk FOREIGN KEY (event) REFERENCES codeimportevent(id) ON DELETE CASCADE;


ALTER TABLE ONLY codeimportjob
    ADD CONSTRAINT codeimportjob__code_import__fk FOREIGN KEY (code_import) REFERENCES codeimport(id);


ALTER TABLE ONLY codeimportjob
    ADD CONSTRAINT codeimportjob__machine__fk FOREIGN KEY (machine) REFERENCES codeimportmachine(id);


ALTER TABLE ONLY codeimportjob
    ADD CONSTRAINT codeimportjob__requesting_user__fk FOREIGN KEY (requesting_user) REFERENCES person(id);


ALTER TABLE ONLY codeimportresult
    ADD CONSTRAINT codeimportresult__code_import__fk FOREIGN KEY (code_import) REFERENCES codeimport(id) ON DELETE CASCADE;


ALTER TABLE ONLY codeimportresult
    ADD CONSTRAINT codeimportresult__log_file__fk FOREIGN KEY (log_file) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY codeimportresult
    ADD CONSTRAINT codeimportresult__machine__fk FOREIGN KEY (machine) REFERENCES codeimportmachine(id);


ALTER TABLE ONLY codeimportresult
    ADD CONSTRAINT codeimportresult__requesting_user__fk FOREIGN KEY (requesting_user) REFERENCES person(id);


ALTER TABLE ONLY codereviewmessage
    ADD CONSTRAINT codereviewmessage_branch_merge_proposal_fkey FOREIGN KEY (branch_merge_proposal) REFERENCES branchmergeproposal(id);


ALTER TABLE ONLY codereviewmessage
    ADD CONSTRAINT codereviewmessage_message_fkey FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY codereviewvote
    ADD CONSTRAINT codereviewvote_branch_merge_proposal_fkey FOREIGN KEY (branch_merge_proposal) REFERENCES branchmergeproposal(id);


ALTER TABLE ONLY codereviewvote
    ADD CONSTRAINT codereviewvote_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY codereviewvote
    ADD CONSTRAINT codereviewvote_reviewer_fkey FOREIGN KEY (reviewer) REFERENCES person(id);


ALTER TABLE ONLY codereviewvote
    ADD CONSTRAINT codereviewvote_vote_message_fkey FOREIGN KEY (vote_message) REFERENCES codereviewmessage(id);


ALTER TABLE ONLY commercialsubscription
    ADD CONSTRAINT commercialsubscription__product__fk FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY commercialsubscription
    ADD CONSTRAINT commercialsubscription__purchaser__fk FOREIGN KEY (purchaser) REFERENCES person(id);


ALTER TABLE ONLY commercialsubscription
    ADD CONSTRAINT commercialsubscription__registrant__fk FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY componentselection
    ADD CONSTRAINT componentselection__component__fk FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY componentselection
    ADD CONSTRAINT componentselection__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY customlanguagecode
    ADD CONSTRAINT customlanguagecode_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY customlanguagecode
    ADD CONSTRAINT customlanguagecode_language_fkey FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY customlanguagecode
    ADD CONSTRAINT customlanguagecode_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY customlanguagecode
    ADD CONSTRAINT customlanguagecode_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY cvereference
    ADD CONSTRAINT cvereference_cve_fk FOREIGN KEY (cve) REFERENCES cve(id);


ALTER TABLE ONLY diff
    ADD CONSTRAINT diff_diff_text_fkey FOREIGN KEY (diff_text) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY incrementaldiff
    ADD CONSTRAINT diff_fk FOREIGN KEY (diff) REFERENCES diff(id) ON DELETE CASCADE;


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution__icon__fk FOREIGN KEY (icon) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution__logo__fk FOREIGN KEY (logo) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution__mugshot__fk FOREIGN KEY (mugshot) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution_driver_fk FOREIGN KEY (driver) REFERENCES person(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution_language_pack_admin_fkey FOREIGN KEY (language_pack_admin) REFERENCES person(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution_mirror_admin_fkey FOREIGN KEY (mirror_admin) REFERENCES person(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution_security_contact_fkey FOREIGN KEY (security_contact) REFERENCES person(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution_translation_focus_fkey FOREIGN KEY (translation_focus) REFERENCES distroseries(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution_translationgroup_fk FOREIGN KEY (translationgroup) REFERENCES translationgroup(id);


ALTER TABLE ONLY distribution
    ADD CONSTRAINT distribution_upload_admin_fk FOREIGN KEY (upload_admin) REFERENCES person(id);


ALTER TABLE ONLY distributionjob
    ADD CONSTRAINT distributionjob__job__fk FOREIGN KEY (job) REFERENCES job(id);


ALTER TABLE ONLY distributionjob
    ADD CONSTRAINT distributionjob_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY distributionjob
    ADD CONSTRAINT distributionjob_distroseries_fkey FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY distributionmirror
    ADD CONSTRAINT distributionmirror_country_fkey FOREIGN KEY (country) REFERENCES country(id);


ALTER TABLE ONLY distributionmirror
    ADD CONSTRAINT distributionmirror_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY distributionmirror
    ADD CONSTRAINT distributionmirror_owner_fkey FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY distributionmirror
    ADD CONSTRAINT distributionmirror_reviewer_fkey FOREIGN KEY (reviewer) REFERENCES person(id);


ALTER TABLE ONLY distributionsourcepackage
    ADD CONSTRAINT distributionpackage__distribution__fk FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY distributionsourcepackage
    ADD CONSTRAINT distributionpackage__sourcepackagename__fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY distributionsourcepackagecache
    ADD CONSTRAINT distributionsourcepackagecache__archive__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY distributionsourcepackagecache
    ADD CONSTRAINT distributionsourcepackagecache_distribution_fk FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY distributionsourcepackagecache
    ADD CONSTRAINT distributionsourcepackagecache_sourcepackagename_fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY distroarchseries
    ADD CONSTRAINT distroarchseries__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY distroarchseries
    ADD CONSTRAINT distroarchseries__owner__fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY distroarchseries
    ADD CONSTRAINT distroarchseries__processorfamily__fk FOREIGN KEY (processorfamily) REFERENCES processorfamily(id);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distrorelease_parentrelease_fk FOREIGN KEY (parent_series) REFERENCES distroseries(id);


ALTER TABLE ONLY distroserieslanguage
    ADD CONSTRAINT distroreleaselanguage_language_fk FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distroseries__distribution__fk FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distroseries__driver__fk FOREIGN KEY (driver) REFERENCES person(id);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distroseries__language_pack_base__fk FOREIGN KEY (language_pack_base) REFERENCES languagepack(id);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distroseries__language_pack_delta__fk FOREIGN KEY (language_pack_delta) REFERENCES languagepack(id);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distroseries__language_pack_proposed__fk FOREIGN KEY (language_pack_proposed) REFERENCES languagepack(id);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distroseries__nominatedarchindep__fk FOREIGN KEY (nominatedarchindep) REFERENCES distroarchseries(id);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distroseries__parent_series__fk FOREIGN KEY (parent_series) REFERENCES distroseries(id);


ALTER TABLE ONLY distroseries
    ADD CONSTRAINT distroseries__registrant__fk FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY packagingjob
    ADD CONSTRAINT distroseries_fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY distroseriesdifference
    ADD CONSTRAINT distroseriesdifference__derived_series__fk FOREIGN KEY (derived_series) REFERENCES distroseries(id);


ALTER TABLE ONLY distroseriesdifference
    ADD CONSTRAINT distroseriesdifference__package_diff__fk FOREIGN KEY (package_diff) REFERENCES packagediff(id);


ALTER TABLE ONLY distroseriesdifference
    ADD CONSTRAINT distroseriesdifference__parent_package_diff__fk FOREIGN KEY (parent_package_diff) REFERENCES packagediff(id);


ALTER TABLE ONLY distroseriesdifference
    ADD CONSTRAINT distroseriesdifference__parentseries__fk FOREIGN KEY (parent_series) REFERENCES distroseries(id);


ALTER TABLE ONLY distroseriesdifference
    ADD CONSTRAINT distroseriesdifference__source_package_name__fk FOREIGN KEY (source_package_name) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY distroseriesdifferencemessage
    ADD CONSTRAINT distroseriesdifferencemessage__distro_series_difference__fk FOREIGN KEY (distro_series_difference) REFERENCES distroseriesdifference(id);


ALTER TABLE ONLY distroseriesdifferencemessage
    ADD CONSTRAINT distroseriesdifferencemessage__message__fk FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY distroserieslanguage
    ADD CONSTRAINT distroserieslanguage__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY distroserieslanguage
    ADD CONSTRAINT distroserieslanguage__language__fk FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY distroseriespackagecache
    ADD CONSTRAINT distroseriespackagecache__archive__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY distroseriespackagecache
    ADD CONSTRAINT distroseriespackagecache__binarypackagename__fk FOREIGN KEY (binarypackagename) REFERENCES binarypackagename(id);


ALTER TABLE ONLY distroseriespackagecache
    ADD CONSTRAINT distroseriespackagecache__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY distroseriesparent
    ADD CONSTRAINT distroseriesparent__derivedseries__fk FOREIGN KEY (derived_series) REFERENCES distroseries(id);


ALTER TABLE ONLY distroseriesparent
    ADD CONSTRAINT distroseriesparent__parentseries__fk FOREIGN KEY (parent_series) REFERENCES distroseries(id);


ALTER TABLE ONLY distroseriesparent
    ADD CONSTRAINT distroseriesparent_component_fkey FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY emailaddress
    ADD CONSTRAINT emailaddress__account__fk FOREIGN KEY (account) REFERENCES account(id) ON DELETE SET NULL;


ALTER TABLE ONLY emailaddress
    ADD CONSTRAINT emailaddress__person__fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY entitlement
    ADD CONSTRAINT entitlement_approved_by_fkey FOREIGN KEY (approved_by) REFERENCES person(id);


ALTER TABLE ONLY entitlement
    ADD CONSTRAINT entitlement_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY entitlement
    ADD CONSTRAINT entitlement_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY entitlement
    ADD CONSTRAINT entitlement_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY entitlement
    ADD CONSTRAINT entitlement_project_fkey FOREIGN KEY (project) REFERENCES project(id);


ALTER TABLE ONLY entitlement
    ADD CONSTRAINT entitlement_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY faq
    ADD CONSTRAINT faq_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY faq
    ADD CONSTRAINT faq_last_updated_by_fkey FOREIGN KEY (last_updated_by) REFERENCES person(id);


ALTER TABLE ONLY faq
    ADD CONSTRAINT faq_owner_fkey FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY faq
    ADD CONSTRAINT faq_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY featuredproject
    ADD CONSTRAINT featuredproject_pillar_name_fkey FOREIGN KEY (pillar_name) REFERENCES pillarname(id);


ALTER TABLE ONLY featureflagchangelogentry
    ADD CONSTRAINT featureflagchangelogentry_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY flatpackagesetinclusion
    ADD CONSTRAINT flatpackagesetinclusion__child__fk FOREIGN KEY (child) REFERENCES packageset(id);


ALTER TABLE ONLY flatpackagesetinclusion
    ADD CONSTRAINT flatpackagesetinclusion__parent__fk FOREIGN KEY (parent) REFERENCES packageset(id);


ALTER TABLE ONLY gpgkey
    ADD CONSTRAINT gpgkey_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY hwdevice
    ADD CONSTRAINT hwdevice_bus_vendor_id_fkey FOREIGN KEY (bus_vendor_id) REFERENCES hwvendorid(id);


ALTER TABLE ONLY hwdeviceclass
    ADD CONSTRAINT hwdeviceclass_device_fkey FOREIGN KEY (device) REFERENCES hwdevice(id);


ALTER TABLE ONLY hwdevicedriverlink
    ADD CONSTRAINT hwdevicedriverlink_device_fkey FOREIGN KEY (device) REFERENCES hwdevice(id);


ALTER TABLE ONLY hwdevicedriverlink
    ADD CONSTRAINT hwdevicedriverlink_driver_fkey FOREIGN KEY (driver) REFERENCES hwdriver(id);


ALTER TABLE ONLY hwdevicenamevariant
    ADD CONSTRAINT hwdevicenamevariant_device_fkey FOREIGN KEY (device) REFERENCES hwdevice(id);


ALTER TABLE ONLY hwdevicenamevariant
    ADD CONSTRAINT hwdevicenamevariant_vendor_name_fkey FOREIGN KEY (vendor_name) REFERENCES hwvendorname(id);


ALTER TABLE ONLY hwdmihandle
    ADD CONSTRAINT hwdmihandle_submission_fkey FOREIGN KEY (submission) REFERENCES hwsubmission(id);


ALTER TABLE ONLY hwdmivalue
    ADD CONSTRAINT hwdmivalue_handle_fkey FOREIGN KEY (handle) REFERENCES hwdmihandle(id);


ALTER TABLE ONLY hwsubmission
    ADD CONSTRAINT hwsubmission__distroarchseries__fk FOREIGN KEY (distroarchseries) REFERENCES distroarchseries(id);


ALTER TABLE ONLY hwsubmission
    ADD CONSTRAINT hwsubmission__owned__fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY hwsubmission
    ADD CONSTRAINT hwsubmission__raw_submission__fk FOREIGN KEY (raw_submission) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY hwsubmission
    ADD CONSTRAINT hwsubmission__system_fingerprint__fk FOREIGN KEY (system_fingerprint) REFERENCES hwsystemfingerprint(id);


ALTER TABLE ONLY hwsubmissionbug
    ADD CONSTRAINT hwsubmissionbug_bug_fkey FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY hwsubmissionbug
    ADD CONSTRAINT hwsubmissionbug_submission_fkey FOREIGN KEY (submission) REFERENCES hwsubmission(id);


ALTER TABLE ONLY hwsubmissiondevice
    ADD CONSTRAINT hwsubmissiondevice_device_driver_link_fkey FOREIGN KEY (device_driver_link) REFERENCES hwdevicedriverlink(id);


ALTER TABLE ONLY hwsubmissiondevice
    ADD CONSTRAINT hwsubmissiondevice_parent_fkey FOREIGN KEY (parent) REFERENCES hwsubmissiondevice(id);


ALTER TABLE ONLY hwsubmissiondevice
    ADD CONSTRAINT hwsubmissiondevice_submission_fkey FOREIGN KEY (submission) REFERENCES hwsubmission(id);


ALTER TABLE ONLY hwtestanswer
    ADD CONSTRAINT hwtestanswer__choice__test__fk FOREIGN KEY (test, choice) REFERENCES hwtestanswerchoice(test, id);


ALTER TABLE ONLY hwtestanswer
    ADD CONSTRAINT hwtestanswer_choice_fkey FOREIGN KEY (choice) REFERENCES hwtestanswerchoice(id);


ALTER TABLE ONLY hwtestanswer
    ADD CONSTRAINT hwtestanswer_language_fkey FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY hwtestanswer
    ADD CONSTRAINT hwtestanswer_submission_fkey FOREIGN KEY (submission) REFERENCES hwsubmission(id);


ALTER TABLE ONLY hwtestanswer
    ADD CONSTRAINT hwtestanswer_test_fkey FOREIGN KEY (test) REFERENCES hwtest(id);


ALTER TABLE ONLY hwtestanswerchoice
    ADD CONSTRAINT hwtestanswerchoice_test_fkey FOREIGN KEY (test) REFERENCES hwtest(id);


ALTER TABLE ONLY hwtestanswercount
    ADD CONSTRAINT hwtestanswercount_choice_fkey FOREIGN KEY (choice) REFERENCES hwtestanswerchoice(id);


ALTER TABLE ONLY hwtestanswercount
    ADD CONSTRAINT hwtestanswercount_distroarchseries_fkey FOREIGN KEY (distroarchseries) REFERENCES distroarchseries(id);


ALTER TABLE ONLY hwtestanswercount
    ADD CONSTRAINT hwtestanswercount_test_fkey FOREIGN KEY (test) REFERENCES hwtest(id);


ALTER TABLE ONLY hwtestanswercountdevice
    ADD CONSTRAINT hwtestanswercountdevice_answer_fkey FOREIGN KEY (answer) REFERENCES hwtestanswercount(id);


ALTER TABLE ONLY hwtestanswercountdevice
    ADD CONSTRAINT hwtestanswercountdevice_device_driver_fkey FOREIGN KEY (device_driver) REFERENCES hwdevicedriverlink(id);


ALTER TABLE ONLY hwtestanswerdevice
    ADD CONSTRAINT hwtestanswerdevice_answer_fkey FOREIGN KEY (answer) REFERENCES hwtestanswer(id);


ALTER TABLE ONLY hwtestanswerdevice
    ADD CONSTRAINT hwtestanswerdevice_device_driver_fkey FOREIGN KEY (device_driver) REFERENCES hwdevicedriverlink(id);


ALTER TABLE ONLY hwvendorid
    ADD CONSTRAINT hwvendorid_vendor_name_fkey FOREIGN KEY (vendor_name) REFERENCES hwvendorname(id);


ALTER TABLE ONLY ircid
    ADD CONSTRAINT ircid_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY jabberid
    ADD CONSTRAINT jabberid_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY packagingjob
    ADD CONSTRAINT job_fk FOREIGN KEY (job) REFERENCES job(id) ON DELETE CASCADE;


ALTER TABLE ONLY job
    ADD CONSTRAINT job_requester_fkey FOREIGN KEY (requester) REFERENCES person(id);


ALTER TABLE ONLY karma
    ADD CONSTRAINT karma_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY karma
    ADD CONSTRAINT karma_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY karma
    ADD CONSTRAINT karma_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY karma
    ADD CONSTRAINT karma_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY karmaaction
    ADD CONSTRAINT karmaaction_category_fk FOREIGN KEY (category) REFERENCES karmacategory(id);


ALTER TABLE ONLY karmacache
    ADD CONSTRAINT karmacache_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY karmacache
    ADD CONSTRAINT karmacache_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY karmacache
    ADD CONSTRAINT karmacache_project_fkey FOREIGN KEY (project) REFERENCES project(id);


ALTER TABLE ONLY karmacache
    ADD CONSTRAINT karmacache_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY karmatotalcache
    ADD CONSTRAINT karmatotalcache_person_fk FOREIGN KEY (person) REFERENCES person(id) ON DELETE CASCADE;


ALTER TABLE ONLY languagepack
    ADD CONSTRAINT languagepack__file__fk FOREIGN KEY (file) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY languagepack
    ADD CONSTRAINT languagepack__updates__fk FOREIGN KEY (updates) REFERENCES languagepack(id);


ALTER TABLE ONLY languagepack
    ADD CONSTRAINT languagepackage__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY libraryfiledownloadcount
    ADD CONSTRAINT libraryfiledownloadcount__libraryfilealias__fk FOREIGN KEY (libraryfilealias) REFERENCES libraryfilealias(id) ON DELETE CASCADE;


ALTER TABLE ONLY libraryfiledownloadcount
    ADD CONSTRAINT libraryfiledownloadcount_country_fkey FOREIGN KEY (country) REFERENCES country(id);


ALTER TABLE ONLY logintoken
    ADD CONSTRAINT logintoken_requester_fk FOREIGN KEY (requester) REFERENCES person(id);


ALTER TABLE ONLY mailinglist
    ADD CONSTRAINT mailinglist_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY mailinglist
    ADD CONSTRAINT mailinglist_reviewer_fkey FOREIGN KEY (reviewer) REFERENCES person(id);


ALTER TABLE ONLY mailinglist
    ADD CONSTRAINT mailinglist_team_fkey FOREIGN KEY (team) REFERENCES person(id);


ALTER TABLE ONLY mailinglistsubscription
    ADD CONSTRAINT mailinglistsubscription__email_address_fk FOREIGN KEY (email_address) REFERENCES emailaddress(id) ON DELETE CASCADE;


ALTER TABLE ONLY mailinglistsubscription
    ADD CONSTRAINT mailinglistsubscription_mailing_list_fkey FOREIGN KEY (mailing_list) REFERENCES mailinglist(id);


ALTER TABLE ONLY mailinglistsubscription
    ADD CONSTRAINT mailinglistsubscription_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY mergedirectivejob
    ADD CONSTRAINT mergedirectivejob_job_fkey FOREIGN KEY (job) REFERENCES job(id) ON DELETE CASCADE;


ALTER TABLE ONLY mergedirectivejob
    ADD CONSTRAINT mergedirectivejob_merge_directive_fkey FOREIGN KEY (merge_directive) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY message
    ADD CONSTRAINT message_distribution_fk FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY message
    ADD CONSTRAINT message_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY message
    ADD CONSTRAINT message_parent_fk FOREIGN KEY (parent) REFERENCES message(id);


ALTER TABLE ONLY message
    ADD CONSTRAINT message_raw_fk FOREIGN KEY (raw) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY messageapproval
    ADD CONSTRAINT messageapproval_disposed_by_fkey FOREIGN KEY (disposed_by) REFERENCES person(id);


ALTER TABLE ONLY messageapproval
    ADD CONSTRAINT messageapproval_mailing_list_fkey FOREIGN KEY (mailing_list) REFERENCES mailinglist(id);


ALTER TABLE ONLY messageapproval
    ADD CONSTRAINT messageapproval_message_fkey FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY messageapproval
    ADD CONSTRAINT messageapproval_posted_by_fkey FOREIGN KEY (posted_by) REFERENCES person(id);


ALTER TABLE ONLY messageapproval
    ADD CONSTRAINT messageapproval_posted_message_fkey FOREIGN KEY (posted_message) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY messagechunk
    ADD CONSTRAINT messagechunk_blob_fk FOREIGN KEY (blob) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY messagechunk
    ADD CONSTRAINT messagechunk_message_fk FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone__distroseries__distribution__fk FOREIGN KEY (distroseries, distribution) REFERENCES distroseries(id, distribution);


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone_distribution_fk FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone_product_fk FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone_product_series_fk FOREIGN KEY (product, productseries) REFERENCES productseries(product, id);


ALTER TABLE ONLY milestone
    ADD CONSTRAINT milestone_productseries_fk FOREIGN KEY (productseries) REFERENCES productseries(id);


ALTER TABLE ONLY mirror
    ADD CONSTRAINT mirror_country_fk FOREIGN KEY (country) REFERENCES country(id);


ALTER TABLE ONLY mirror
    ADD CONSTRAINT mirror_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY mirrorcdimagedistroseries
    ADD CONSTRAINT mirrorcdimagedistroseries__distribution_mirror__fk FOREIGN KEY (distribution_mirror) REFERENCES distributionmirror(id);


ALTER TABLE ONLY mirrorcdimagedistroseries
    ADD CONSTRAINT mirrorcdimagedistroseries__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY mirrorcontent
    ADD CONSTRAINT mirrorcontent__distroarchseries__fk FOREIGN KEY (distroarchseries) REFERENCES distroarchseries(id);


ALTER TABLE ONLY mirrorcontent
    ADD CONSTRAINT mirrorcontent_component_fk FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY mirrorcontent
    ADD CONSTRAINT mirrorcontent_mirror_fk FOREIGN KEY (mirror) REFERENCES mirror(id);


ALTER TABLE ONLY mirrordistroarchseries
    ADD CONSTRAINT mirrordistroarchseries__component__fk FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY mirrordistroarchseries
    ADD CONSTRAINT mirrordistroarchseries__distribution_mirror__fk FOREIGN KEY (distribution_mirror) REFERENCES distributionmirror(id);


ALTER TABLE ONLY mirrordistroarchseries
    ADD CONSTRAINT mirrordistroarchseries__distroarchseries__fk FOREIGN KEY (distroarchseries) REFERENCES distroarchseries(id);


ALTER TABLE ONLY mirrordistroseriessource
    ADD CONSTRAINT mirrordistroseriessource__component__fk FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY mirrordistroseriessource
    ADD CONSTRAINT mirrordistroseriessource__distribution_mirror__fk FOREIGN KEY (distribution_mirror) REFERENCES distributionmirror(id);


ALTER TABLE ONLY mirrordistroseriessource
    ADD CONSTRAINT mirrordistroseriessource__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY mirrorproberecord
    ADD CONSTRAINT mirrorproberecord_distribution_mirror_fkey FOREIGN KEY (distribution_mirror) REFERENCES distributionmirror(id);


ALTER TABLE ONLY mirrorproberecord
    ADD CONSTRAINT mirrorproberecord_log_file_fkey FOREIGN KEY (log_file) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY mirrorsourcecontent
    ADD CONSTRAINT mirrorsourcecontent__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY mirrorsourcecontent
    ADD CONSTRAINT mirrorsourcecontent_component_fk FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY mirrorsourcecontent
    ADD CONSTRAINT mirrorsourcecontent_mirror_fk FOREIGN KEY (mirror) REFERENCES mirror(id);


ALTER TABLE ONLY nameblacklist
    ADD CONSTRAINT nameblacklist_admin_fk FOREIGN KEY (admin) REFERENCES person(id);


ALTER TABLE ONLY incrementaldiff
    ADD CONSTRAINT new_revision_fk FOREIGN KEY (new_revision) REFERENCES revision(id) ON DELETE CASCADE;


ALTER TABLE ONLY oauthaccesstoken
    ADD CONSTRAINT oauthaccesstoken_consumer_fkey FOREIGN KEY (consumer) REFERENCES oauthconsumer(id);


ALTER TABLE ONLY oauthaccesstoken
    ADD CONSTRAINT oauthaccesstoken_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY oauthaccesstoken
    ADD CONSTRAINT oauthaccesstoken_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY oauthaccesstoken
    ADD CONSTRAINT oauthaccesstoken_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY oauthaccesstoken
    ADD CONSTRAINT oauthaccesstoken_project_fkey FOREIGN KEY (project) REFERENCES project(id);


ALTER TABLE ONLY oauthaccesstoken
    ADD CONSTRAINT oauthaccesstoken_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY oauthnonce
    ADD CONSTRAINT oauthnonce__access_token__fk FOREIGN KEY (access_token) REFERENCES oauthaccesstoken(id) ON DELETE CASCADE;


ALTER TABLE ONLY oauthrequesttoken
    ADD CONSTRAINT oauthrequesttoken_consumer_fkey FOREIGN KEY (consumer) REFERENCES oauthconsumer(id);


ALTER TABLE ONLY oauthrequesttoken
    ADD CONSTRAINT oauthrequesttoken_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY oauthrequesttoken
    ADD CONSTRAINT oauthrequesttoken_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY oauthrequesttoken
    ADD CONSTRAINT oauthrequesttoken_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY oauthrequesttoken
    ADD CONSTRAINT oauthrequesttoken_project_fkey FOREIGN KEY (project) REFERENCES project(id);


ALTER TABLE ONLY oauthrequesttoken
    ADD CONSTRAINT oauthrequesttoken_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY officialbugtag
    ADD CONSTRAINT officialbugtag_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY officialbugtag
    ADD CONSTRAINT officialbugtag_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY officialbugtag
    ADD CONSTRAINT officialbugtag_project_fkey FOREIGN KEY (project) REFERENCES project(id);


ALTER TABLE ONLY incrementaldiff
    ADD CONSTRAINT old_revision_fk FOREIGN KEY (old_revision) REFERENCES revision(id) ON DELETE CASCADE;


ALTER TABLE ONLY openididentifier
    ADD CONSTRAINT openididentifier_account_fkey FOREIGN KEY (account) REFERENCES account(id) ON DELETE CASCADE;


ALTER TABLE ONLY packagebuild
    ADD CONSTRAINT packagebuild__archive__fk FOREIGN KEY (archive) REFERENCES archive(id);


ALTER TABLE ONLY packagebuild
    ADD CONSTRAINT packagebuild__build_farm_job__fk FOREIGN KEY (build_farm_job) REFERENCES buildfarmjob(id);


ALTER TABLE ONLY packagebuild
    ADD CONSTRAINT packagebuild__log__fk FOREIGN KEY (upload_log) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY packagecopyjob
    ADD CONSTRAINT packagecopyjob__job__fk FOREIGN KEY (job) REFERENCES job(id);


ALTER TABLE ONLY packagecopyjob
    ADD CONSTRAINT packagecopyjob_source_archive_fkey FOREIGN KEY (source_archive) REFERENCES archive(id);


ALTER TABLE ONLY packagecopyjob
    ADD CONSTRAINT packagecopyjob_target_archive_fkey FOREIGN KEY (target_archive) REFERENCES archive(id);


ALTER TABLE ONLY packagecopyjob
    ADD CONSTRAINT packagecopyjob_target_distroseries_fkey FOREIGN KEY (target_distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY packagecopyrequest
    ADD CONSTRAINT packagecopyrequest__sourcearchive__fk FOREIGN KEY (source_archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY packagecopyrequest
    ADD CONSTRAINT packagecopyrequest__targetarchive__fk FOREIGN KEY (target_archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY packagecopyrequest
    ADD CONSTRAINT packagecopyrequest_requester_fk FOREIGN KEY (requester) REFERENCES person(id);


ALTER TABLE ONLY packagecopyrequest
    ADD CONSTRAINT packagecopyrequest_sourcecomponent_fk FOREIGN KEY (source_component) REFERENCES component(id);


ALTER TABLE ONLY packagecopyrequest
    ADD CONSTRAINT packagecopyrequest_sourcedistroseries_fk FOREIGN KEY (source_distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY packagecopyrequest
    ADD CONSTRAINT packagecopyrequest_targetcomponent_fk FOREIGN KEY (target_component) REFERENCES component(id);


ALTER TABLE ONLY packagecopyrequest
    ADD CONSTRAINT packagecopyrequest_targetdistroseries_fk FOREIGN KEY (target_distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY packagediff
    ADD CONSTRAINT packagediff_diff_content_fkey FOREIGN KEY (diff_content) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY packagediff
    ADD CONSTRAINT packagediff_from_source_fkey FOREIGN KEY (from_source) REFERENCES sourcepackagerelease(id);


ALTER TABLE ONLY packagediff
    ADD CONSTRAINT packagediff_requester_fkey FOREIGN KEY (requester) REFERENCES person(id);


ALTER TABLE ONLY packagediff
    ADD CONSTRAINT packagediff_to_source_fkey FOREIGN KEY (to_source) REFERENCES sourcepackagerelease(id);


ALTER TABLE ONLY packageset
    ADD CONSTRAINT packageset__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY packageset
    ADD CONSTRAINT packageset__owner__fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY packageset
    ADD CONSTRAINT packageset__packagesetgroup__fk FOREIGN KEY (packagesetgroup) REFERENCES packagesetgroup(id);


ALTER TABLE ONLY packagesetgroup
    ADD CONSTRAINT packagesetgroup__owner__fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY packagesetinclusion
    ADD CONSTRAINT packagesetinclusion__child__fk FOREIGN KEY (child) REFERENCES packageset(id);


ALTER TABLE ONLY packagesetinclusion
    ADD CONSTRAINT packagesetinclusion__parent__fk FOREIGN KEY (parent) REFERENCES packageset(id);


ALTER TABLE ONLY packagesetsources
    ADD CONSTRAINT packagesetsources__packageset__fk FOREIGN KEY (packageset) REFERENCES packageset(id);


ALTER TABLE ONLY packageupload
    ADD CONSTRAINT packageupload__archive__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY packageupload
    ADD CONSTRAINT packageupload__changesfile__fk FOREIGN KEY (changesfile) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY packageupload
    ADD CONSTRAINT packageupload__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY packageupload
    ADD CONSTRAINT packageupload__package_copy_job__fk FOREIGN KEY (package_copy_job) REFERENCES packagecopyjob(id);


ALTER TABLE ONLY packageupload
    ADD CONSTRAINT packageupload__signing_key__fk FOREIGN KEY (signing_key) REFERENCES gpgkey(id);


ALTER TABLE ONLY packageuploadbuild
    ADD CONSTRAINT packageuploadbuild__packageupload__fk FOREIGN KEY (packageupload) REFERENCES packageupload(id) ON DELETE CASCADE;


ALTER TABLE ONLY packageuploadbuild
    ADD CONSTRAINT packageuploadbuild_build_fk FOREIGN KEY (build) REFERENCES binarypackagebuild(id);


ALTER TABLE ONLY packageuploadcustom
    ADD CONSTRAINT packageuploadcustom_libraryfilealias_fk FOREIGN KEY (libraryfilealias) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY packageuploadcustom
    ADD CONSTRAINT packageuploadcustom_packageupload_fk FOREIGN KEY (packageupload) REFERENCES packageupload(id);


ALTER TABLE ONLY packageuploadsource
    ADD CONSTRAINT packageuploadsource__packageupload__fk FOREIGN KEY (packageupload) REFERENCES packageupload(id) ON DELETE CASCADE;


ALTER TABLE ONLY packageuploadsource
    ADD CONSTRAINT packageuploadsource__sourcepackagerelease__fk FOREIGN KEY (sourcepackagerelease) REFERENCES sourcepackagerelease(id);


ALTER TABLE ONLY packaging
    ADD CONSTRAINT packaging__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY packaging
    ADD CONSTRAINT packaging_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY packaging
    ADD CONSTRAINT packaging_productseries_fk FOREIGN KEY (productseries) REFERENCES productseries(id);


ALTER TABLE ONLY packaging
    ADD CONSTRAINT packaging_sourcepackagename_fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY person
    ADD CONSTRAINT person__account__fk FOREIGN KEY (account) REFERENCES account(id);


ALTER TABLE ONLY person
    ADD CONSTRAINT person__icon__fk FOREIGN KEY (icon) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY person
    ADD CONSTRAINT person__logo__fk FOREIGN KEY (logo) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY person
    ADD CONSTRAINT person__mugshot__fk FOREIGN KEY (mugshot) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY karmacache
    ADD CONSTRAINT person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY person
    ADD CONSTRAINT person_language_fk FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY person
    ADD CONSTRAINT person_merged_fk FOREIGN KEY (merged) REFERENCES person(id);


ALTER TABLE ONLY person
    ADD CONSTRAINT person_registrant_fk FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY person
    ADD CONSTRAINT person_teamowner_fk FOREIGN KEY (teamowner) REFERENCES person(id);


ALTER TABLE ONLY personlanguage
    ADD CONSTRAINT personlanguage_language_fk FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY personlanguage
    ADD CONSTRAINT personlanguage_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY personlocation
    ADD CONSTRAINT personlocation_last_modified_by_fkey FOREIGN KEY (last_modified_by) REFERENCES person(id);


ALTER TABLE ONLY personlocation
    ADD CONSTRAINT personlocation_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY personnotification
    ADD CONSTRAINT personnotification_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY personsettings
    ADD CONSTRAINT personsettings_person_fkey FOREIGN KEY (person) REFERENCES person(id) ON DELETE CASCADE;


ALTER TABLE ONLY persontransferjob
    ADD CONSTRAINT persontransferjob_job_fkey FOREIGN KEY (job) REFERENCES job(id);


ALTER TABLE ONLY persontransferjob
    ADD CONSTRAINT persontransferjob_major_person_fkey FOREIGN KEY (major_person) REFERENCES person(id);


ALTER TABLE ONLY persontransferjob
    ADD CONSTRAINT persontransferjob_minor_person_fkey FOREIGN KEY (minor_person) REFERENCES person(id);


ALTER TABLE ONLY pillarname
    ADD CONSTRAINT pillarname__alias_for__fk FOREIGN KEY (alias_for) REFERENCES pillarname(id);


ALTER TABLE ONLY pillarname
    ADD CONSTRAINT pillarname_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id) ON DELETE CASCADE;


ALTER TABLE ONLY pillarname
    ADD CONSTRAINT pillarname_product_fkey FOREIGN KEY (product) REFERENCES product(id) ON DELETE CASCADE;


ALTER TABLE ONLY pillarname
    ADD CONSTRAINT pillarname_project_fkey FOREIGN KEY (project) REFERENCES project(id) ON DELETE CASCADE;


ALTER TABLE ONLY pocketchroot
    ADD CONSTRAINT pocketchroot__distroarchseries__fk FOREIGN KEY (distroarchseries) REFERENCES distroarchseries(id);


ALTER TABLE ONLY pocketchroot
    ADD CONSTRAINT pocketchroot__libraryfilealias__fk FOREIGN KEY (chroot) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY poexportrequest
    ADD CONSTRAINT poeportrequest_potemplate_fk FOREIGN KEY (potemplate) REFERENCES potemplate(id);


ALTER TABLE ONLY poexportrequest
    ADD CONSTRAINT poexportrequest_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY poexportrequest
    ADD CONSTRAINT poexportrequest_pofile_fk FOREIGN KEY (pofile) REFERENCES pofile(id);


ALTER TABLE ONLY pofile
    ADD CONSTRAINT pofile_language_fk FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY pofile
    ADD CONSTRAINT pofile_lasttranslator_fk FOREIGN KEY (lasttranslator) REFERENCES person(id);


ALTER TABLE ONLY pofile
    ADD CONSTRAINT pofile_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY pofile
    ADD CONSTRAINT pofile_potemplate_fk FOREIGN KEY (potemplate) REFERENCES potemplate(id);


ALTER TABLE ONLY pofilestatsjob
    ADD CONSTRAINT pofilestatsjob_job_fkey FOREIGN KEY (job) REFERENCES job(id);


ALTER TABLE ONLY pofilestatsjob
    ADD CONSTRAINT pofilestatsjob_pofile_fkey FOREIGN KEY (pofile) REFERENCES pofile(id);


ALTER TABLE ONLY pofiletranslator
    ADD CONSTRAINT pofiletranslator__latest_message__fk FOREIGN KEY (latest_message) REFERENCES translationmessage(id) DEFERRABLE INITIALLY DEFERRED;


ALTER TABLE ONLY pofiletranslator
    ADD CONSTRAINT pofiletranslator__person__fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY pofiletranslator
    ADD CONSTRAINT pofiletranslator__pofile__fk FOREIGN KEY (pofile) REFERENCES pofile(id);


ALTER TABLE ONLY poll
    ADD CONSTRAINT poll_team_fk FOREIGN KEY (team) REFERENCES person(id);


ALTER TABLE ONLY potemplate
    ADD CONSTRAINT potemplate__distrorelease__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY potemplate
    ADD CONSTRAINT potemplate__from_sourcepackagename__fk FOREIGN KEY (from_sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY potemplate
    ADD CONSTRAINT potemplate__source_file__fk FOREIGN KEY (source_file) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY potemplate
    ADD CONSTRAINT potemplate_binarypackagename_fk FOREIGN KEY (binarypackagename) REFERENCES binarypackagename(id);


ALTER TABLE ONLY packagingjob
    ADD CONSTRAINT potemplate_fk FOREIGN KEY (potemplate) REFERENCES potemplate(id);


ALTER TABLE ONLY potemplate
    ADD CONSTRAINT potemplate_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY potemplate
    ADD CONSTRAINT potemplate_productseries_fk FOREIGN KEY (productseries) REFERENCES productseries(id);


ALTER TABLE ONLY potemplate
    ADD CONSTRAINT potemplate_sourcepackagename_fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY potmsgset
    ADD CONSTRAINT potmsgset__msgid_plural__fk FOREIGN KEY (msgid_plural) REFERENCES pomsgid(id);


ALTER TABLE ONLY potmsgset
    ADD CONSTRAINT potmsgset_potemplate_fk FOREIGN KEY (potemplate) REFERENCES potemplate(id);


ALTER TABLE ONLY potmsgset
    ADD CONSTRAINT potmsgset_primemsgid_fk FOREIGN KEY (msgid_singular) REFERENCES pomsgid(id);


ALTER TABLE ONLY previewdiff
    ADD CONSTRAINT previewdiff_diff_fkey FOREIGN KEY (diff) REFERENCES diff(id) ON DELETE CASCADE;


ALTER TABLE ONLY product
    ADD CONSTRAINT product__development_focus__fk FOREIGN KEY (development_focus) REFERENCES productseries(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product__icon__fk FOREIGN KEY (icon) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product__logo__fk FOREIGN KEY (logo) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product__mugshot__fk FOREIGN KEY (mugshot) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product__translation_focus__fk FOREIGN KEY (translation_focus) REFERENCES productseries(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product_bugtracker_fkey FOREIGN KEY (bugtracker) REFERENCES bugtracker(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product_driver_fk FOREIGN KEY (driver) REFERENCES person(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product_project_fk FOREIGN KEY (project) REFERENCES project(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product_security_contact_fkey FOREIGN KEY (security_contact) REFERENCES person(id);


ALTER TABLE ONLY product
    ADD CONSTRAINT product_translationgroup_fk FOREIGN KEY (translationgroup) REFERENCES translationgroup(id);


ALTER TABLE ONLY productlicense
    ADD CONSTRAINT productlicense_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY productrelease
    ADD CONSTRAINT productrelease_milestone_fkey FOREIGN KEY (milestone) REFERENCES milestone(id);


ALTER TABLE ONLY productrelease
    ADD CONSTRAINT productrelease_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY productreleasefile
    ADD CONSTRAINT productreleasefile__signature__fk FOREIGN KEY (signature) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY productreleasefile
    ADD CONSTRAINT productreleasefile__uploader__fk FOREIGN KEY (uploader) REFERENCES person(id);


ALTER TABLE ONLY productseries
    ADD CONSTRAINT productseries_branch_fkey FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY productseries
    ADD CONSTRAINT productseries_driver_fk FOREIGN KEY (driver) REFERENCES person(id);


ALTER TABLE ONLY packagingjob
    ADD CONSTRAINT productseries_fk FOREIGN KEY (productseries) REFERENCES productseries(id);


ALTER TABLE ONLY productseries
    ADD CONSTRAINT productseries_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY productseries
    ADD CONSTRAINT productseries_product_fk FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY productseries
    ADD CONSTRAINT productseries_translations_branch_fkey FOREIGN KEY (translations_branch) REFERENCES branch(id);


ALTER TABLE ONLY project
    ADD CONSTRAINT project__icon__fk FOREIGN KEY (icon) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY project
    ADD CONSTRAINT project__logo__fk FOREIGN KEY (logo) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY project
    ADD CONSTRAINT project__mugshot__fk FOREIGN KEY (mugshot) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY project
    ADD CONSTRAINT project_bugtracker_fkey FOREIGN KEY (bugtracker) REFERENCES bugtracker(id);


ALTER TABLE ONLY project
    ADD CONSTRAINT project_driver_fk FOREIGN KEY (driver) REFERENCES person(id);


ALTER TABLE ONLY project
    ADD CONSTRAINT project_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY project
    ADD CONSTRAINT project_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY project
    ADD CONSTRAINT project_translationgroup_fk FOREIGN KEY (translationgroup) REFERENCES translationgroup(id);


ALTER TABLE ONLY publisherconfig
    ADD CONSTRAINT publisherconfig__distribution__fk FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY question
    ADD CONSTRAINT question__answer__fk FOREIGN KEY (answer) REFERENCES questionmessage(id);


ALTER TABLE ONLY question
    ADD CONSTRAINT question__answerer__fk FOREIGN KEY (answerer) REFERENCES person(id);


ALTER TABLE ONLY question
    ADD CONSTRAINT question__assignee__fk FOREIGN KEY (assignee) REFERENCES person(id);


ALTER TABLE ONLY question
    ADD CONSTRAINT question__distribution__fk FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY question
    ADD CONSTRAINT question__faq__fk FOREIGN KEY (faq) REFERENCES faq(id);


ALTER TABLE ONLY question
    ADD CONSTRAINT question__language__fkey FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY question
    ADD CONSTRAINT question__owner__fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY question
    ADD CONSTRAINT question__product__fk FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY question
    ADD CONSTRAINT question__sourcepackagename__fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY questionbug
    ADD CONSTRAINT questionbug__bug__fk FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY questionbug
    ADD CONSTRAINT questionbug__question__fk FOREIGN KEY (question) REFERENCES question(id);


ALTER TABLE ONLY questionjob
    ADD CONSTRAINT questionjob_job_fkey FOREIGN KEY (job) REFERENCES job(id);


ALTER TABLE ONLY questionjob
    ADD CONSTRAINT questionjob_question_fkey FOREIGN KEY (question) REFERENCES question(id);


ALTER TABLE ONLY questionmessage
    ADD CONSTRAINT questionmessage__message__fk FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY questionmessage
    ADD CONSTRAINT questionmessage__question__fk FOREIGN KEY (question) REFERENCES question(id);


ALTER TABLE ONLY questionreopening
    ADD CONSTRAINT questionreopening__answerer__fk FOREIGN KEY (answerer) REFERENCES person(id);


ALTER TABLE ONLY questionreopening
    ADD CONSTRAINT questionreopening__question__fk FOREIGN KEY (question) REFERENCES question(id);


ALTER TABLE ONLY questionreopening
    ADD CONSTRAINT questionreopening__reopener__fk FOREIGN KEY (reopener) REFERENCES person(id);


ALTER TABLE ONLY questionsubscription
    ADD CONSTRAINT questionsubscription__person__fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY questionsubscription
    ADD CONSTRAINT questionsubscription__question__fk FOREIGN KEY (question) REFERENCES question(id);


ALTER TABLE ONLY teammembership
    ADD CONSTRAINT reviewer_fk FOREIGN KEY (last_changed_by) REFERENCES person(id);


ALTER TABLE ONLY revision
    ADD CONSTRAINT revision_gpgkey_fk FOREIGN KEY (gpgkey) REFERENCES gpgkey(id);


ALTER TABLE ONLY revision
    ADD CONSTRAINT revision_revision_author_fk FOREIGN KEY (revision_author) REFERENCES revisionauthor(id);


ALTER TABLE ONLY revisionauthor
    ADD CONSTRAINT revisionauthor_person_fkey FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY revisioncache
    ADD CONSTRAINT revisioncache__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY revisioncache
    ADD CONSTRAINT revisioncache__product__fk FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY revisioncache
    ADD CONSTRAINT revisioncache__revision__fk FOREIGN KEY (revision) REFERENCES revision(id);


ALTER TABLE ONLY revisioncache
    ADD CONSTRAINT revisioncache__revision_author__fk FOREIGN KEY (revision_author) REFERENCES revisionauthor(id);


ALTER TABLE ONLY revisioncache
    ADD CONSTRAINT revisioncache__sourcepackagename__fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY revisionparent
    ADD CONSTRAINT revisionparent_revision_fk FOREIGN KEY (revision) REFERENCES revision(id);


ALTER TABLE ONLY revisionproperty
    ADD CONSTRAINT revisionproperty__revision__fk FOREIGN KEY (revision) REFERENCES revision(id);


ALTER TABLE ONLY sectionselection
    ADD CONSTRAINT sectionselection__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY sectionselection
    ADD CONSTRAINT sectionselection__section__fk FOREIGN KEY (section) REFERENCES section(id);


ALTER TABLE ONLY binarypackagepublishinghistory
    ADD CONSTRAINT securebinarypackagepublishinghistory__archive__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY binarypackagepublishinghistory
    ADD CONSTRAINT securebinarypackagepublishinghistory__distroarchseries__fk FOREIGN KEY (distroarchseries) REFERENCES distroarchseries(id);


ALTER TABLE ONLY binarypackagepublishinghistory
    ADD CONSTRAINT securebinarypackagepublishinghistory_binarypackagerelease_fk FOREIGN KEY (binarypackagerelease) REFERENCES binarypackagerelease(id);


ALTER TABLE ONLY binarypackagepublishinghistory
    ADD CONSTRAINT securebinarypackagepublishinghistory_component_fk FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY binarypackagepublishinghistory
    ADD CONSTRAINT securebinarypackagepublishinghistory_removedby_fk FOREIGN KEY (removed_by) REFERENCES person(id);


ALTER TABLE ONLY binarypackagepublishinghistory
    ADD CONSTRAINT securebinarypackagepublishinghistory_section_fk FOREIGN KEY (section) REFERENCES section(id);


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT securesourcepackagepublishinghistory__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT securesourcepackagepublishinghistory_component_fk FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT securesourcepackagepublishinghistory_removedby_fk FOREIGN KEY (removed_by) REFERENCES person(id);


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT securesourcepackagepublishinghistory_section_fk FOREIGN KEY (section) REFERENCES section(id);


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT securesourcepackagepublishinghistory_sourcepackagerelease_fk FOREIGN KEY (sourcepackagerelease) REFERENCES sourcepackagerelease(id);


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT securesourcepackagepublishinghistory_supersededby_fk FOREIGN KEY (supersededby) REFERENCES sourcepackagerelease(id);


ALTER TABLE ONLY seriessourcepackagebranch
    ADD CONSTRAINT seriessourcepackagebranch_branch_fkey FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY seriessourcepackagebranch
    ADD CONSTRAINT seriessourcepackagebranch_distroseries_fkey FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY seriessourcepackagebranch
    ADD CONSTRAINT seriessourcepackagebranch_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY seriessourcepackagebranch
    ADD CONSTRAINT seriessourcepackagebranch_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY signedcodeofconduct
    ADD CONSTRAINT signedcodeofconduct_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY signedcodeofconduct
    ADD CONSTRAINT signedcodeofconduct_signingkey_fk FOREIGN KEY (owner, signingkey) REFERENCES gpgkey(owner, id) ON UPDATE CASCADE;


ALTER TABLE ONLY sourcepackageformatselection
    ADD CONSTRAINT sourceformatselection__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY packagingjob
    ADD CONSTRAINT sourcepackagename_fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY packagesetsources
    ADD CONSTRAINT sourcepackagenamesources__sourcepackagename__fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT sourcepackagepublishinghistory__archive__fk FOREIGN KEY (archive) REFERENCES archive(id) ON DELETE CASCADE;


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT sourcepackagepublishinghistory__creator__fk FOREIGN KEY (creator) REFERENCES person(id);


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT sourcepackagepublishinghistory_ancestor_fkey FOREIGN KEY (ancestor) REFERENCES sourcepackagepublishinghistory(id);


ALTER TABLE ONLY sourcepackagepublishinghistory
    ADD CONSTRAINT sourcepackagepublishinghistory_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY sourcepackagerecipe
    ADD CONSTRAINT sourcepackagerecipe_daily_build_archive_fkey FOREIGN KEY (daily_build_archive) REFERENCES archive(id);


ALTER TABLE ONLY sourcepackagerecipe
    ADD CONSTRAINT sourcepackagerecipe_owner_fkey FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY sourcepackagerecipe
    ADD CONSTRAINT sourcepackagerecipe_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY sourcepackagerecipebuild
    ADD CONSTRAINT sourcepackagerecipebuild_distroseries_fkey FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY sourcepackagerecipebuild
    ADD CONSTRAINT sourcepackagerecipebuild_manifest_fkey FOREIGN KEY (manifest) REFERENCES sourcepackagerecipedata(id);


ALTER TABLE ONLY sourcepackagerecipebuild
    ADD CONSTRAINT sourcepackagerecipebuild_package_build_fkey FOREIGN KEY (package_build) REFERENCES packagebuild(id);


ALTER TABLE ONLY sourcepackagerecipebuild
    ADD CONSTRAINT sourcepackagerecipebuild_recipe_fkey FOREIGN KEY (recipe) REFERENCES sourcepackagerecipe(id);


ALTER TABLE ONLY sourcepackagerecipebuild
    ADD CONSTRAINT sourcepackagerecipebuild_requester_fkey FOREIGN KEY (requester) REFERENCES person(id);


ALTER TABLE ONLY sourcepackagerecipebuildjob
    ADD CONSTRAINT sourcepackagerecipebuildjob_job_fkey FOREIGN KEY (job) REFERENCES job(id);


ALTER TABLE ONLY sourcepackagerecipebuildjob
    ADD CONSTRAINT sourcepackagerecipebuildjob_sourcepackage_recipe_build_fkey FOREIGN KEY (sourcepackage_recipe_build) REFERENCES sourcepackagerecipebuild(id);


ALTER TABLE ONLY sourcepackagerecipedata
    ADD CONSTRAINT sourcepackagerecipedata_base_branch_fkey FOREIGN KEY (base_branch) REFERENCES branch(id);


ALTER TABLE ONLY sourcepackagerecipedata
    ADD CONSTRAINT sourcepackagerecipedata_sourcepackage_recipe_build_fkey FOREIGN KEY (sourcepackage_recipe_build) REFERENCES sourcepackagerecipebuild(id);


ALTER TABLE ONLY sourcepackagerecipedata
    ADD CONSTRAINT sourcepackagerecipedata_sourcepackage_recipe_fkey FOREIGN KEY (sourcepackage_recipe) REFERENCES sourcepackagerecipe(id);


ALTER TABLE ONLY sourcepackagerecipedatainstruction
    ADD CONSTRAINT sourcepackagerecipedatainstruction_branch_fkey FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY sourcepackagerecipedatainstruction
    ADD CONSTRAINT sourcepackagerecipedatainstruction_parent_instruction_fkey FOREIGN KEY (parent_instruction) REFERENCES sourcepackagerecipedatainstruction(id);


ALTER TABLE ONLY sourcepackagerecipedatainstruction
    ADD CONSTRAINT sourcepackagerecipedatainstruction_recipe_data_fkey FOREIGN KEY (recipe_data) REFERENCES sourcepackagerecipedata(id);


ALTER TABLE ONLY sourcepackagerecipedistroseries
    ADD CONSTRAINT sourcepackagerecipedistroseries_distroseries_fkey FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY sourcepackagerecipedistroseries
    ADD CONSTRAINT sourcepackagerecipedistroseries_sourcepackagerecipe_fkey FOREIGN KEY (sourcepackagerecipe) REFERENCES sourcepackagerecipe(id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease__creator__fk FOREIGN KEY (creator) REFERENCES person(id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease__dscsigningkey FOREIGN KEY (dscsigningkey) REFERENCES gpgkey(id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease__upload_archive__fk FOREIGN KEY (upload_archive) REFERENCES archive(id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease__upload_distroseries__fk FOREIGN KEY (upload_distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease_changelog_fkey FOREIGN KEY (changelog) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease_component_fk FOREIGN KEY (component) REFERENCES component(id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease_maintainer_fk FOREIGN KEY (maintainer) REFERENCES person(id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease_section FOREIGN KEY (section) REFERENCES section(id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease_sourcepackage_recipe_build_fkey FOREIGN KEY (sourcepackage_recipe_build) REFERENCES sourcepackagerecipebuild(id);


ALTER TABLE ONLY sourcepackagerelease
    ADD CONSTRAINT sourcepackagerelease_sourcepackagename_fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification__distroseries__distribution__fk FOREIGN KEY (distroseries, distribution) REFERENCES distroseries(id, distribution);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_approver_fk FOREIGN KEY (approver) REFERENCES person(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_assignee_fk FOREIGN KEY (assignee) REFERENCES person(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_completer_fkey FOREIGN KEY (completer) REFERENCES person(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_distribution_fk FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_distribution_milestone_fk FOREIGN KEY (distribution, milestone) REFERENCES milestone(distribution, id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_drafter_fk FOREIGN KEY (drafter) REFERENCES person(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_goal_decider_fkey FOREIGN KEY (goal_decider) REFERENCES person(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_goal_proposer_fkey FOREIGN KEY (goal_proposer) REFERENCES person(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_product_fk FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_product_milestone_fk FOREIGN KEY (product, milestone) REFERENCES milestone(product, id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_productseries_valid FOREIGN KEY (product, productseries) REFERENCES productseries(product, id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_starter_fkey FOREIGN KEY (starter) REFERENCES person(id);


ALTER TABLE ONLY specification
    ADD CONSTRAINT specification_superseded_by_fk FOREIGN KEY (superseded_by) REFERENCES specification(id);


ALTER TABLE ONLY specificationbranch
    ADD CONSTRAINT specificationbranch__branch__fk FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY specificationbranch
    ADD CONSTRAINT specificationbranch__specification__fk FOREIGN KEY (specification) REFERENCES specification(id);


ALTER TABLE ONLY specificationbranch
    ADD CONSTRAINT specificationbranch_registrant_fkey FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY specificationbug
    ADD CONSTRAINT specificationbug_bug_fk FOREIGN KEY (bug) REFERENCES bug(id);


ALTER TABLE ONLY specificationbug
    ADD CONSTRAINT specificationbug_specification_fk FOREIGN KEY (specification) REFERENCES specification(id);


ALTER TABLE ONLY specificationdependency
    ADD CONSTRAINT specificationdependency_dependency_fk FOREIGN KEY (dependency) REFERENCES specification(id);


ALTER TABLE ONLY specificationdependency
    ADD CONSTRAINT specificationdependency_specification_fk FOREIGN KEY (specification) REFERENCES specification(id);


ALTER TABLE ONLY specificationfeedback
    ADD CONSTRAINT specificationfeedback_provider_fk FOREIGN KEY (reviewer) REFERENCES person(id);


ALTER TABLE ONLY specificationfeedback
    ADD CONSTRAINT specificationfeedback_requester_fk FOREIGN KEY (requester) REFERENCES person(id);


ALTER TABLE ONLY specificationfeedback
    ADD CONSTRAINT specificationfeedback_specification_fk FOREIGN KEY (specification) REFERENCES specification(id);


ALTER TABLE ONLY specificationmessage
    ADD CONSTRAINT specificationmessage__message__fk FOREIGN KEY (message) REFERENCES message(id);


ALTER TABLE ONLY specificationmessage
    ADD CONSTRAINT specificationmessage__specification__fk FOREIGN KEY (specification) REFERENCES specification(id);


ALTER TABLE ONLY specificationsubscription
    ADD CONSTRAINT specificationsubscription_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY specificationsubscription
    ADD CONSTRAINT specificationsubscription_specification_fk FOREIGN KEY (specification) REFERENCES specification(id);


ALTER TABLE ONLY sprint
    ADD CONSTRAINT sprint__icon__fk FOREIGN KEY (icon) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY sprint
    ADD CONSTRAINT sprint__logo__fk FOREIGN KEY (logo) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY sprint
    ADD CONSTRAINT sprint__mugshot__fk FOREIGN KEY (mugshot) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY sprint
    ADD CONSTRAINT sprint_driver_fkey FOREIGN KEY (driver) REFERENCES person(id);


ALTER TABLE ONLY sprint
    ADD CONSTRAINT sprint_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY sprintattendance
    ADD CONSTRAINT sprintattendance_attendee_fk FOREIGN KEY (attendee) REFERENCES person(id);


ALTER TABLE ONLY sprintattendance
    ADD CONSTRAINT sprintattendance_sprint_fk FOREIGN KEY (sprint) REFERENCES sprint(id);


ALTER TABLE ONLY sprintspecification
    ADD CONSTRAINT sprintspec_spec_fk FOREIGN KEY (specification) REFERENCES specification(id);


ALTER TABLE ONLY sprintspecification
    ADD CONSTRAINT sprintspec_sprint_fk FOREIGN KEY (sprint) REFERENCES sprint(id);


ALTER TABLE ONLY sprintspecification
    ADD CONSTRAINT sprintspecification__nominator__fk FOREIGN KEY (registrant) REFERENCES person(id);


ALTER TABLE ONLY sprintspecification
    ADD CONSTRAINT sprintspecification_decider_fkey FOREIGN KEY (decider) REFERENCES person(id);


ALTER TABLE ONLY structuralsubscription
    ADD CONSTRAINT structuralsubscription_distribution_fkey FOREIGN KEY (distribution) REFERENCES distribution(id);


ALTER TABLE ONLY structuralsubscription
    ADD CONSTRAINT structuralsubscription_distroseries_fkey FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY structuralsubscription
    ADD CONSTRAINT structuralsubscription_milestone_fkey FOREIGN KEY (milestone) REFERENCES milestone(id);


ALTER TABLE ONLY structuralsubscription
    ADD CONSTRAINT structuralsubscription_product_fkey FOREIGN KEY (product) REFERENCES product(id);


ALTER TABLE ONLY structuralsubscription
    ADD CONSTRAINT structuralsubscription_productseries_fkey FOREIGN KEY (productseries) REFERENCES productseries(id);


ALTER TABLE ONLY structuralsubscription
    ADD CONSTRAINT structuralsubscription_project_fkey FOREIGN KEY (project) REFERENCES project(id);


ALTER TABLE ONLY structuralsubscription
    ADD CONSTRAINT structuralsubscription_sourcepackagename_fkey FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY structuralsubscription
    ADD CONSTRAINT structuralsubscription_subscribed_by_fkey FOREIGN KEY (subscribed_by) REFERENCES person(id);


ALTER TABLE ONLY structuralsubscription
    ADD CONSTRAINT structuralsubscription_subscriber_fkey FOREIGN KEY (subscriber) REFERENCES person(id);


ALTER TABLE ONLY subunitstream
    ADD CONSTRAINT subunitstream_branch_fkey FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY subunitstream
    ADD CONSTRAINT subunitstream_stream_fkey FOREIGN KEY (stream) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY subunitstream
    ADD CONSTRAINT subunitstream_uploader_fkey FOREIGN KEY (uploader) REFERENCES person(id);


ALTER TABLE ONLY suggestivepotemplate
    ADD CONSTRAINT suggestivepotemplate__potemplate__fk FOREIGN KEY (potemplate) REFERENCES potemplate(id) ON DELETE CASCADE;


ALTER TABLE ONLY teammembership
    ADD CONSTRAINT teammembership_acknowledged_by_fkey FOREIGN KEY (acknowledged_by) REFERENCES person(id);


ALTER TABLE ONLY teammembership
    ADD CONSTRAINT teammembership_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY teammembership
    ADD CONSTRAINT teammembership_proposed_by_fkey FOREIGN KEY (proposed_by) REFERENCES person(id);


ALTER TABLE ONLY teammembership
    ADD CONSTRAINT teammembership_reviewed_by_fkey FOREIGN KEY (reviewed_by) REFERENCES person(id);


ALTER TABLE ONLY teammembership
    ADD CONSTRAINT teammembership_team_fk FOREIGN KEY (team) REFERENCES person(id);


ALTER TABLE ONLY teamparticipation
    ADD CONSTRAINT teamparticipation_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY teamparticipation
    ADD CONSTRAINT teamparticipation_team_fk FOREIGN KEY (team) REFERENCES person(id);


ALTER TABLE ONLY temporaryblobstorage
    ADD CONSTRAINT temporaryblobstorage_file_alias_fkey FOREIGN KEY (file_alias) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY translationgroup
    ADD CONSTRAINT translationgroup_owner_fk FOREIGN KEY (owner) REFERENCES person(id);


ALTER TABLE ONLY translationimportqueueentry
    ADD CONSTRAINT translationimportqueueentry__content__fk FOREIGN KEY (content) REFERENCES libraryfilealias(id);


ALTER TABLE ONLY translationimportqueueentry
    ADD CONSTRAINT translationimportqueueentry__distroseries__fk FOREIGN KEY (distroseries) REFERENCES distroseries(id);


ALTER TABLE ONLY translationimportqueueentry
    ADD CONSTRAINT translationimportqueueentry__importer__fk FOREIGN KEY (importer) REFERENCES person(id);


ALTER TABLE ONLY translationimportqueueentry
    ADD CONSTRAINT translationimportqueueentry__pofile__fk FOREIGN KEY (pofile) REFERENCES pofile(id);


ALTER TABLE ONLY translationimportqueueentry
    ADD CONSTRAINT translationimportqueueentry__potemplate__fk FOREIGN KEY (potemplate) REFERENCES potemplate(id);


ALTER TABLE ONLY translationimportqueueentry
    ADD CONSTRAINT translationimportqueueentry__productseries__fk FOREIGN KEY (productseries) REFERENCES productseries(id);


ALTER TABLE ONLY translationimportqueueentry
    ADD CONSTRAINT translationimportqueueentry__sourcepackagename__fk FOREIGN KEY (sourcepackagename) REFERENCES sourcepackagename(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage__msgstr0__fk FOREIGN KEY (msgstr0) REFERENCES potranslation(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage__msgstr1__fk FOREIGN KEY (msgstr1) REFERENCES potranslation(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage__msgstr2__fk FOREIGN KEY (msgstr2) REFERENCES potranslation(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage__msgstr3__fk FOREIGN KEY (msgstr3) REFERENCES potranslation(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage__msgstr4__fk FOREIGN KEY (msgstr4) REFERENCES potranslation(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage__msgstr5__fk FOREIGN KEY (msgstr5) REFERENCES potranslation(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage__potmsgset__fk FOREIGN KEY (potmsgset) REFERENCES potmsgset(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage__reviewer__fk FOREIGN KEY (reviewer) REFERENCES person(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage__submitter__fk FOREIGN KEY (submitter) REFERENCES person(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage_language_fkey FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY translationmessage
    ADD CONSTRAINT translationmessage_potemplate_fkey FOREIGN KEY (potemplate) REFERENCES potemplate(id);


ALTER TABLE ONLY translationrelicensingagreement
    ADD CONSTRAINT translationrelicensingagreement__person__fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY translationtemplateitem
    ADD CONSTRAINT translationtemplateitem_potemplate_fkey FOREIGN KEY (potemplate) REFERENCES potemplate(id);


ALTER TABLE ONLY translationtemplateitem
    ADD CONSTRAINT translationtemplateitem_potmsgset_fkey FOREIGN KEY (potmsgset) REFERENCES potmsgset(id);


ALTER TABLE ONLY translationtemplatesbuild
    ADD CONSTRAINT translationtemplatesbuild_branch_fkey FOREIGN KEY (branch) REFERENCES branch(id);


ALTER TABLE ONLY translationtemplatesbuild
    ADD CONSTRAINT translationtemplatesbuild_build_farm_job_fkey FOREIGN KEY (build_farm_job) REFERENCES buildfarmjob(id);


ALTER TABLE ONLY translator
    ADD CONSTRAINT translator_language_fk FOREIGN KEY (language) REFERENCES language(id);


ALTER TABLE ONLY translator
    ADD CONSTRAINT translator_person_fk FOREIGN KEY (translator) REFERENCES person(id);


ALTER TABLE ONLY translator
    ADD CONSTRAINT translator_translationgroup_fk FOREIGN KEY (translationgroup) REFERENCES translationgroup(id);


ALTER TABLE ONLY usertouseremail
    ADD CONSTRAINT usertouseremail__recipient__fk FOREIGN KEY (recipient) REFERENCES person(id);


ALTER TABLE ONLY usertouseremail
    ADD CONSTRAINT usertouseremail__sender__fk FOREIGN KEY (sender) REFERENCES person(id);


ALTER TABLE ONLY vote
    ADD CONSTRAINT vote_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY vote
    ADD CONSTRAINT vote_poll_fk FOREIGN KEY (poll) REFERENCES poll(id);


ALTER TABLE ONLY vote
    ADD CONSTRAINT vote_poll_option_fk FOREIGN KEY (poll, option) REFERENCES polloption(poll, id);


ALTER TABLE ONLY votecast
    ADD CONSTRAINT votecast_person_fk FOREIGN KEY (person) REFERENCES person(id);


ALTER TABLE ONLY votecast
    ADD CONSTRAINT votecast_poll_fk FOREIGN KEY (poll) REFERENCES poll(id);


ALTER TABLE ONLY wikiname
    ADD CONSTRAINT wikiname_person_fk FOREIGN KEY (person) REFERENCES person(id);