~launchpad-pqm/launchpad/devel

7675.731.1 by Edwin Grubbs
Changed DistributionSourcePackage.section foreign key to is_meta boolean to solve issues that led to rolling back revision 9449 in revision 9451.
1
-- Copyright 2010 Canonical Ltd.  This software is licensed under the
2
-- GNU Affero General Public License version 3 (see the file LICENSE).
3
4
SET client_min_messages=ERROR;
5
6
INSERT INTO LaunchpadDatabaseRevision VALUES (2207, 56, 0);
7
8
/*
9
Existing Schema:
10
11
CREATE TABLE distributionsourcepackage (
12
    id integer NOT NULL,
13
    distribution integer NOT NULL,
14
    sourcepackagename integer NOT NULL,
15
    bug_reporting_guidelines text,
16
    max_bug_heat integer
17
);
18
*/
19
20
ALTER TABLE DistributionSourcePackage ADD COLUMN total_bug_heat INTEGER;
21
ALTER TABLE DistributionSourcePackage ADD COLUMN bug_count INTEGER;
22
ALTER TABLE DistributionSourcePackage ADD COLUMN po_message_count INTEGER;
23
ALTER TABLE DistributionSourcePackage
7675.731.2 by Edwin Grubbs
Changed DistributionSourcePackage.is_meta to is_upstream_link_allowed.
24
    ADD COLUMN is_upstream_link_allowed BOOLEAN NOT NULL DEFAULT TRUE;
7675.730.3 by Edwin Grubbs
Populate bug cache values in DistributionSourcePackage.
25
26
/* Add DistributionSourcePackage row for each
27
 * SourcePackagePublishingHistory entry whose archive is primary and
28
 * whose distroseries is current.
29
 */
30
INSERT INTO DistributionSourcePackage (
31
    distribution,
32
    sourcepackagename
33
    )
34
    SELECT
35
        ds.distribution,
36
        sourcepackagename
37
    FROM SourcePackagePublishingHistory spph
38
        JOIN Archive ON spph.archive = Archive.id
39
        JOIN SourcePackageRelease spr ON spph.sourcepackagerelease = spr.id
40
        JOIN DistroSeries ds ON spph.distroseries = ds.id
41
    WHERE ds.releasestatus = 4 -- CURRENT
42
        AND Archive.purpose = 1 -- PRIMARY
43
    EXCEPT
44
    SELECT
45
        distribution,
46
        sourcepackagename
7675.730.8 by Edwin Grubbs
Addressed db review comments.
47
    FROM DistributionSourcePackage
48
ORDER BY distribution, sourcepackagename;
49
7675.730.3 by Edwin Grubbs
Populate bug cache values in DistributionSourcePackage.
50
51
52
/* Update cached bug values in DistributionSourcePackage. */
53
UPDATE DistributionSourcePackage
54
SET max_bug_heat = subquery.max_bug_heat,
55
    total_bug_heat = subquery.total_bug_heat,
56
    bug_count = subquery.bug_count
57
FROM (
58
    SELECT
7675.730.5 by Edwin Grubbs
Optimized +needs-packaging query.
59
        COALESCE(MAX(Bug.heat), 0) as max_bug_heat,
60
        COALESCE(SUM(Bug.heat), 0) as total_bug_heat,
61
        COALESCE(COUNT(Bug.id), 0) as bug_count,
7675.730.3 by Edwin Grubbs
Populate bug cache values in DistributionSourcePackage.
62
        distribution as distro,
63
        sourcepackagename as spn
7675.730.5 by Edwin Grubbs
Optimized +needs-packaging query.
64
    FROM
65
        DistributionSourcePackage
66
        LEFT JOIN BugTask USING(distribution, sourcepackagename)
67
        LEFT JOIN Bug ON BugTask.bug = Bug.id
7675.730.3 by Edwin Grubbs
Populate bug cache values in DistributionSourcePackage.
68
    GROUP BY distribution, sourcepackagename
69
    ) AS subquery
70
WHERE distribution = distro
71
    AND sourcepackagename = spn;
7675.730.8 by Edwin Grubbs
Addressed db review comments.
72
73
74
CLUSTER DistributionSourcePackage
75
   USING distributionpackage__sourcepackagename__distribution__key;