]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update106.py
auto-decruft: Expand NVI in cmd line argument names
[dak.git] / dak / dakdb / update106.py
1 #!/usr/bin/env python
2 # coding=utf8
3
4 """
5 new views binary_component, source_component and package_list
6
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2014, Ansgar Burchardt <ansgar@debian.org>
9 @license: GNU General Public License version 2 or later
10 """
11
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26 ################################################################################
27
28 import psycopg2
29 from daklib.dak_exceptions import DBUpdateError
30 from daklib.config import Config
31
32 statements = [
33 """
34 CREATE OR REPLACE VIEW source_component AS
35 SELECT
36   s.id AS source_id,
37   sa.suite AS suite_id,
38   af.component_id AS component_id
39 FROM source s
40 JOIN src_associations sa ON s.id = sa.source
41 JOIN suite ON sa.suite = suite.id
42 JOIN files_archive_map af ON s.file = af.file_id AND suite.archive_id = af.archive_id
43 """,
44 """
45 COMMENT ON VIEW source_component IS 'Map (source_id, suite_id) to the component(s) that the source is included in. Note that this view might return more components than expected as we can only query the component for (source_id, archive_id).'
46 """,
47 "GRANT SELECT ON source_component TO PUBLIC",
48
49 """
50 CREATE OR REPLACE VIEW binary_component AS
51 SELECT
52   b.id AS binary_id,
53   ba.suite AS suite_id,
54   af.component_id AS component_id
55 FROM binaries b
56 JOIN bin_associations ba ON b.id = ba.bin
57 JOIN suite ON ba.suite = suite.id
58 JOIN files_archive_map af ON b.file = af.file_id AND suite.archive_id = af.archive_id
59 """,
60 """
61 COMMENT ON VIEW binary_component IS 'Map (binary_id, suite_id) to the component(s) that the binary is included in. Note that this view might return more components than expected as we can only query the component for (binary_id, archive_id).'
62 """,
63 "GRANT SELECT ON binary_component TO PUBLIC",
64
65 """
66 CREATE OR REPLACE VIEW package_list AS
67 SELECT
68   tmp.package,
69   tmp.version,
70   tmp.source,
71   tmp.source_version,
72   suite.suite_name AS suite,
73   archive.name AS archive,
74   component.name AS component,
75   CASE component.name
76     WHEN 'main' THEN suite.suite_name
77     ELSE CONCAT(suite.suite_name, '/', component.name)
78     END AS display_suite,
79   tmp.architecture_is_source,
80   tmp.architecture,
81   tmp.type
82 FROM
83   (SELECT
84     s.source AS package,
85     s.version AS version,
86     s.source AS source,
87     s.version AS source_version,
88     sa.suite AS suite_id,
89     TRUE AS architecture_is_source,
90     'source' AS architecture,
91     'dsc' AS type,
92     sc.component_id
93     FROM source s
94     JOIN src_associations sa ON s.id = sa.source
95     JOIN source_component sc ON s.id = sc.source_id AND sa.suite = sc.suite_id
96    UNION
97    SELECT
98     b.package AS package,
99     b.version AS version,
100     s.source AS source,
101     s.version AS source_version,
102     ba.suite AS suite_id,
103     FALSE AS architecture_is_source,
104     a.arch_string AS architecture,
105     b.type AS type,
106     bc.component_id
107     FROM binaries b
108     JOIN source s ON b.source = s.id
109     JOIN architecture a ON b.architecture = a.id
110     JOIN bin_associations ba ON b.id = ba.bin
111     JOIN binary_component bc ON b.id = bc.binary_id AND ba.suite = bc.suite_id) AS tmp
112   JOIN suite ON tmp.suite_id = suite.id
113   JOIN archive ON suite.archive_id = archive.id
114   JOIN component ON tmp.component_id = component.id
115 """,
116 "GRANT SELECT ON package_list TO PUBLIC"
117 ]
118
119 ################################################################################
120 def do_update(self):
121     print __doc__
122     try:
123         cnf = Config()
124
125         c = self.db.cursor()
126
127         for stmt in statements:
128             c.execute(stmt)
129
130         c.execute("UPDATE config SET value = '106' WHERE name = 'db_revision'")
131         self.db.commit()
132
133     except psycopg2.ProgrammingError as msg:
134         self.db.rollback()
135         raise DBUpdateError('Unable to apply sick update 106, rollback issued. Error message: {0}'.format(msg))