4 Add views for new dominate command.
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
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.
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.
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
28 print "Add views for generate_filelist to database."
33 print "Drop old views."
34 c.execute("DROP VIEW IF EXISTS binaries_suite_arch CASCADE")
35 c.execute("DROP VIEW IF EXISTS newest_all_associations CASCADE")
36 c.execute("DROP VIEW IF EXISTS obsolete_any_by_all_associations CASCADE")
37 c.execute("DROP VIEW IF EXISTS newest_any_associations CASCADE")
38 c.execute("DROP VIEW IF EXISTS obsolete_any_associations CASCADE")
39 c.execute("DROP VIEW IF EXISTS source_suite CASCADE")
40 c.execute("DROP VIEW IF EXISTS newest_source CASCADE")
41 c.execute("DROP VIEW IF EXISTS newest_src_association CASCADE")
42 c.execute("DROP VIEW IF EXISTS any_associations_source CASCADE")
43 c.execute("DROP VIEW IF EXISTS src_associations_src CASCADE")
44 c.execute("DROP VIEW IF EXISTS almost_obsolete_src_associations CASCADE")
45 c.execute("DROP VIEW IF EXISTS obsolete_src_associations CASCADE")
46 c.execute("DROP VIEW IF EXISTS bin_associations_binaries CASCADE")
47 c.execute("DROP VIEW IF EXISTS src_associations_bin CASCADE")
48 c.execute("DROP VIEW IF EXISTS almost_obsolete_all_associations CASCADE")
49 c.execute("DROP VIEW IF EXISTS obsolete_all_associations CASCADE")
51 print "Create new views."
53 CREATE VIEW binaries_suite_arch AS
54 SELECT bin_associations.id, binaries.id AS bin, binaries.package,
55 binaries.version, binaries.source, bin_associations.suite,
56 suite.suite_name, binaries.architecture, architecture.arch_string
57 FROM binaries JOIN bin_associations ON binaries.id = bin_associations.bin
58 JOIN suite ON suite.id = bin_associations.suite
59 JOIN architecture ON binaries.architecture = architecture.id;
62 CREATE VIEW newest_all_associations AS
63 SELECT package, max(version) AS version, suite, architecture
64 FROM binaries_suite_arch
65 WHERE architecture = 2 GROUP BY package, suite, architecture;
68 CREATE VIEW obsolete_any_by_all_associations AS
69 SELECT binaries_suite_arch.id, binaries_suite_arch.package,
70 binaries_suite_arch.version, binaries_suite_arch.suite,
71 binaries_suite_arch.architecture
72 FROM binaries_suite_arch
73 JOIN newest_all_associations
74 ON (binaries_suite_arch.package = newest_all_associations.package AND
75 binaries_suite_arch.version < newest_all_associations.version AND
76 binaries_suite_arch.suite = newest_all_associations.suite AND
77 binaries_suite_arch.architecture > 2);
80 CREATE VIEW newest_any_associations AS
81 SELECT package, max(version) AS version, suite, architecture
82 FROM binaries_suite_arch
83 WHERE architecture > 2 GROUP BY package, suite, architecture;
86 CREATE VIEW obsolete_any_associations AS
87 SELECT id, binaries_suite_arch.architecture, binaries_suite_arch.version,
88 binaries_suite_arch.package, binaries_suite_arch.suite
89 FROM binaries_suite_arch
90 JOIN newest_any_associations
91 ON binaries_suite_arch.architecture = newest_any_associations.architecture AND
92 binaries_suite_arch.package = newest_any_associations.package AND
93 binaries_suite_arch.suite = newest_any_associations.suite AND
94 binaries_suite_arch.version != newest_any_associations.version;
97 CREATE VIEW source_suite AS
98 SELECT src_associations.id, source.id AS src , source.source, source.version,
99 src_associations.suite, suite.suite_name
101 JOIN src_associations ON source.id = src_associations.source
102 JOIN suite ON suite.id = src_associations.suite;
105 CREATE VIEW newest_source AS
106 SELECT source, max(version) AS version, suite
108 GROUP BY source, suite;
111 CREATE VIEW newest_src_association AS
112 SELECT id, src, source, version, suite
114 JOIN newest_source USING (source, version, suite);
117 CREATE VIEW any_associations_source AS
118 SELECT bin_associations.id, bin_associations.suite, binaries.id AS bin,
119 binaries.package, binaries.version AS binver, binaries.architecture,
120 source.id AS src, source.source, source.version AS srcver
121 FROM bin_associations
122 JOIN binaries ON bin_associations.bin = binaries.id AND architecture != 2
123 JOIN source ON binaries.source = source.id;
126 CREATE VIEW src_associations_src AS
127 SELECT src_associations.id, src_associations.suite, source.id AS src,
128 source.source, source.version
129 FROM src_associations
130 JOIN source ON src_associations.source = source.id;
133 CREATE VIEW almost_obsolete_src_associations AS
134 SELECT src_associations_src.id, src_associations_src.src,
135 src_associations_src.source, src_associations_src.version, suite
136 FROM src_associations_src
137 LEFT JOIN any_associations_source USING (src, suite)
141 CREATE VIEW obsolete_src_associations AS
142 SELECT almost.id, almost.src, almost.source, almost.version, almost.suite
143 FROM almost_obsolete_src_associations as almost
144 JOIN newest_src_association AS newest
145 ON almost.source = newest.source AND
146 almost.version < newest.version AND
147 almost.suite = newest.suite;
150 CREATE VIEW bin_associations_binaries AS
151 SELECT bin_associations.id, bin_associations.bin, binaries.package,
152 binaries.version, bin_associations.suite, binaries.architecture
153 FROM bin_associations
154 JOIN binaries ON bin_associations.bin = binaries.id;
157 CREATE VIEW src_associations_bin AS
158 SELECT src_associations.id, src_associations.source, src_associations.suite,
159 binaries.id AS bin, binaries.architecture
160 FROM src_associations
161 JOIN source ON src_associations.source = source.id
162 JOIN binaries ON source.id = binaries.source;
165 CREATE VIEW almost_obsolete_all_associations AS
166 SELECT bin_associations_binaries.id AS id, bin, bin_associations_binaries.package,
167 bin_associations_binaries.version, suite
168 FROM bin_associations_binaries
169 LEFT JOIN src_associations_bin USING (bin, suite, architecture)
170 WHERE source IS NULL AND architecture = 2;
173 CREATE VIEW obsolete_all_associations AS
174 SELECT almost.id, almost.bin, almost.package, almost.version, almost.suite
175 FROM almost_obsolete_all_associations AS almost
176 JOIN newest_all_associations AS newest
177 ON almost.package = newest.package AND
178 almost.version < newest.version AND
179 almost.suite = newest.suite;
183 c.execute("UPDATE config SET value = '25' WHERE name = 'db_revision'")
186 except psycopg2.InternalError, msg:
188 raise DBUpdateError, "Database error, rollback issued. Error message : %s" % (str(msg))