1 """
2 new views binary_component, source_component and package_list
3
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 """
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import psycopg2
26
27 from daklib.dak_exceptions import DBUpdateError
28
29 statements = [
30 """
31 CREATE OR REPLACE VIEW source_component AS
32 SELECT
33 s.id AS source_id,
34 sa.suite AS suite_id,
35 af.component_id AS component_id
36 FROM source s
37 JOIN src_associations sa ON s.id = sa.source
38 JOIN suite ON sa.suite = suite.id
39 JOIN files_archive_map af ON s.file = af.file_id AND suite.archive_id = af.archive_id
40 """,
41 """
42 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).'
43 """,
44 "GRANT SELECT ON source_component TO PUBLIC",
45 """
46 CREATE OR REPLACE VIEW binary_component AS
47 SELECT
48 b.id AS binary_id,
49 ba.suite AS suite_id,
50 af.component_id AS component_id
51 FROM binaries b
52 JOIN bin_associations ba ON b.id = ba.bin
53 JOIN suite ON ba.suite = suite.id
54 JOIN files_archive_map af ON b.file = af.file_id AND suite.archive_id = af.archive_id
55 """,
56 """
57 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).'
58 """,
59 "GRANT SELECT ON binary_component TO PUBLIC",
60 """
61 CREATE OR REPLACE VIEW package_list AS
62 SELECT
63 tmp.package,
64 tmp.version,
65 tmp.source,
66 tmp.source_version,
67 suite.suite_name AS suite,
68 archive.name AS archive,
69 component.name AS component,
70 CASE component.name
71 WHEN 'main' THEN suite.suite_name
72 ELSE CONCAT(suite.suite_name, '/', component.name)
73 END AS display_suite,
74 tmp.architecture_is_source,
75 tmp.architecture,
76 tmp.type
77 FROM
78 (SELECT
79 s.source AS package,
80 s.version AS version,
81 s.source AS source,
82 s.version AS source_version,
83 sa.suite AS suite_id,
84 TRUE AS architecture_is_source,
85 'source' AS architecture,
86 'dsc' AS type,
87 sc.component_id
88 FROM source s
89 JOIN src_associations sa ON s.id = sa.source
90 JOIN source_component sc ON s.id = sc.source_id AND sa.suite = sc.suite_id
91 UNION
92 SELECT
93 b.package AS package,
94 b.version AS version,
95 s.source AS source,
96 s.version AS source_version,
97 ba.suite AS suite_id,
98 FALSE AS architecture_is_source,
99 a.arch_string AS architecture,
100 b.type AS type,
101 bc.component_id
102 FROM binaries b
103 JOIN source s ON b.source = s.id
104 JOIN architecture a ON b.architecture = a.id
105 JOIN bin_associations ba ON b.id = ba.bin
106 JOIN binary_component bc ON b.id = bc.binary_id AND ba.suite = bc.suite_id) AS tmp
107 JOIN suite ON tmp.suite_id = suite.id
108 JOIN archive ON suite.archive_id = archive.id
109 JOIN component ON tmp.component_id = component.id
110 """,
111 "GRANT SELECT ON package_list TO PUBLIC",
112 ]
113
114
115
116
118 print(__doc__)
119 try:
120 c = self.db.cursor()
121
122 for stmt in statements:
123 c.execute(stmt)
124
125 c.execute("UPDATE config SET value = '106' WHERE name = 'db_revision'")
126 self.db.commit()
127
128 except psycopg2.ProgrammingError as msg:
129 self.db.rollback()
130 raise DBUpdateError(
131 "Unable to apply sick update 106, rollback issued. Error message: {0}".format(
132 msg
133 )
134 )
135