]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update27.py
cruft-report: reimplement 'obsolete source'
[dak.git] / dak / dakdb / update27.py
1 #!/usr/bin/env python
2
3 """
4 Add views for new obsolete source detection.
5
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2009  Torsten Werner <twerner@debian.org>
8 @license: GNU General Public License version 2 or later
9 """
10
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
25 import psycopg2
26
27 def do_update(self):
28     print "Add/modify views for obsolete source detection."
29
30     try:
31         c = self.db.cursor()
32
33         print "Replace old views."
34         # joins src_associations and source
35         c.execute("""
36 CREATE OR REPLACE VIEW source_suite AS
37     SELECT src_associations.id, source.id AS src, source.source, source.version,
38            src_associations.suite, suite.suite_name, source.install_date
39         FROM source
40         JOIN src_associations ON source.id = src_associations.source
41         JOIN suite ON suite.id = src_associations.suite;
42             """)
43         # joins bin_associations and binaries
44         c.execute("""
45 CREATE OR REPLACE VIEW bin_associations_binaries AS
46     SELECT bin_associations.id, bin_associations.bin, binaries.package,
47            binaries.version, bin_associations.suite, binaries.architecture,
48            binaries.source
49         FROM bin_associations
50         JOIN binaries ON bin_associations.bin = binaries.id;
51             """)
52
53         print "Drop old views."
54         c.execute("DROP VIEW IF EXISTS source_suite_unique CASCADE")
55         c.execute("DROP VIEW IF EXISTS obsolete_source CASCADE")
56         c.execute("DROP VIEW IF EXISTS source_bin CASCADE")
57         c.execute("DROP VIEW IF EXISTS newest_source_bab CASCADE")
58
59         print "Create new views."
60         # returns source package names from suite without duplicates;
61         # rationale: cruft-report and rm cannot handle duplicates (yet)
62         c.execute("""
63 CREATE VIEW source_suite_unique
64     AS SELECT source, suite
65         FROM source_suite GROUP BY source, suite HAVING count(*) = 1;
66             """)
67         # returns obsolete sources without binaries in the same suite;
68         # outputs install_date to detect source only (or binary throw away)
69         # uploads; duplicates are skipped
70         c.execute("""
71 CREATE VIEW obsolete_source
72     AS SELECT ss.src, ss.source, ss.version, ss.suite,
73         to_char(ss.install_date, 'YYYY-MM-DD') AS install_date
74         FROM source_suite ss
75         JOIN source_suite_unique ssu
76             ON ss.source = ssu.source AND ss.suite = ssu.suite
77         LEFT JOIN bin_associations_binaries bab
78             ON ss.src = bab.source AND ss.suite = bab.suite
79             WHERE bab.id IS NULL;
80             """)
81         # returns source package names and its binaries from any suite
82         c.execute("""
83 CREATE VIEW source_bin
84     AS SELECT b.package, MAX(b.version) AS version, sas.source
85         FROM binaries b
86         JOIN src_associations_src sas
87             ON b.source = sas.src
88         GROUP BY b.package, sas.source
89             """)
90         # returns binaries from suite and their source with max(version)
91         # grouped by source name, binary name, and suite
92         c.execute("""
93 CREATE VIEW newest_source_bab
94     AS SELECT sas.source, MAX(sas.version) AS srcver, bab.package, bab.suite
95         FROM src_associations_src sas
96         JOIN bin_associations_binaries bab ON sas.src = bab.source
97             GROUP BY sas.source, bab.package, bab.suite;
98             """)
99
100         print "Grant permissions to views."
101         c.execute("GRANT SELECT ON binfiles_suite_component_arch TO PUBLIC;");
102         c.execute("GRANT SELECT ON srcfiles_suite_component TO PUBLIC;");
103         c.execute("GRANT SELECT ON binaries_suite_arch TO PUBLIC;");
104         c.execute("GRANT SELECT ON newest_all_associations TO PUBLIC;");
105         c.execute("GRANT SELECT ON obsolete_any_by_all_associations TO PUBLIC;");
106         c.execute("GRANT SELECT ON newest_any_associations TO PUBLIC;");
107         c.execute("GRANT SELECT ON obsolete_any_associations TO PUBLIC;");
108         c.execute("GRANT SELECT ON source_suite TO PUBLIC;");
109         c.execute("GRANT SELECT ON newest_source TO PUBLIC;");
110         c.execute("GRANT SELECT ON newest_src_association TO PUBLIC;");
111         c.execute("GRANT SELECT ON any_associations_source TO PUBLIC;");
112         c.execute("GRANT SELECT ON src_associations_src TO PUBLIC;");
113         c.execute("GRANT SELECT ON almost_obsolete_src_associations TO PUBLIC;");
114         c.execute("GRANT SELECT ON obsolete_src_associations TO PUBLIC;");
115         c.execute("GRANT SELECT ON bin_associations_binaries TO PUBLIC;");
116         c.execute("GRANT SELECT ON src_associations_bin TO PUBLIC;");
117         c.execute("GRANT SELECT ON almost_obsolete_all_associations TO PUBLIC;");
118         c.execute("GRANT SELECT ON obsolete_all_associations TO PUBLIC;");
119         c.execute("GRANT SELECT ON source_suite_unique TO PUBLIC;");
120         c.execute("GRANT SELECT ON obsolete_source TO PUBLIC;");
121         c.execute("GRANT SELECT ON source_bin TO PUBLIC;");
122         c.execute("GRANT SELECT ON newest_source_bab TO PUBLIC;");
123
124         print "Committing"
125         c.execute("UPDATE config SET value = '27' WHERE name = 'db_revision'")
126         self.db.commit()
127
128     except psycopg2.InternalError, msg:
129         self.db.rollback()
130         raise DBUpdateError, "Database error, rollback issued. Error message : %s" % (str(msg))
131