1"""
2Add codename to package_list view
4@contact: Debian FTP Master <ftpmaster@debian.org>
5@copyright: 2015, 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"""DROP VIEW IF EXISTS package_list""",
31"""
32CREATE OR REPLACE VIEW package_list AS
33SELECT
34 tmp.package,
35 tmp.version,
36 tmp.source,
37 tmp.source_version,
38 suite.suite_name AS suite,
39 suite.codename AS codename,
40 archive.name AS archive,
41 component.name AS component,
42 CASE component.name
43 WHEN 'main' THEN suite.suite_name
44 ELSE CONCAT(suite.suite_name, '/', component.name)
45 END AS display_suite,
46 tmp.architecture_is_source,
47 tmp.architecture,
48 tmp.type
49FROM
50 (SELECT
51 s.source AS package,
52 s.version AS version,
53 s.source AS source,
54 s.version AS source_version,
55 sa.suite AS suite_id,
56 TRUE AS architecture_is_source,
57 'source' AS architecture,
58 'dsc' AS type,
59 sc.component_id
60 FROM source s
61 JOIN src_associations sa ON s.id = sa.source
62 JOIN source_component sc ON s.id = sc.source_id AND sa.suite = sc.suite_id
63 UNION
64 SELECT
65 b.package AS package,
66 b.version AS version,
67 s.source AS source,
68 s.version AS source_version,
69 ba.suite AS suite_id,
70 FALSE AS architecture_is_source,
71 a.arch_string AS architecture,
72 b.type AS type,
73 bc.component_id
74 FROM binaries b
75 JOIN source s ON b.source = s.id
76 JOIN architecture a ON b.architecture = a.id
77 JOIN bin_associations ba ON b.id = ba.bin
78 JOIN binary_component bc ON b.id = bc.binary_id AND ba.suite = bc.suite_id) AS tmp
79 JOIN suite ON tmp.suite_id = suite.id
80 JOIN archive ON suite.archive_id = archive.id
81 JOIN component ON tmp.component_id = component.id
82""",
83]
85################################################################################
88def do_update(self):
89 print(__doc__)
90 try:
91 cnf = Config()
93 c = self.db.cursor()
95 for stmt in statements:
96 c.execute(stmt)
98 c.execute("UPDATE config SET value = '108' WHERE name = 'db_revision'")
99 self.db.commit()
101 except psycopg2.ProgrammingError as msg:
102 self.db.rollback()
103 raise DBUpdateError('Unable to apply sick update 108, rollback issued. Error message: {0}'.format(msg))