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