]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update17.py
merge from master with sqla
[dak.git] / dak / dakdb / update17.py
1 #!/usr/bin/env python
2 # coding=utf8
3
4 """
5 Adding a trainee field to the process-new notes
6
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2009  Mike O'Connor <stew@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
29 ################################################################################
30
31 import psycopg2
32 import time
33 from daklib.dak_exceptions import DBUpdateError
34
35 ################################################################################
36
37 def suites():
38     """
39     return a list of suites to operate on
40     """
41     if Config().has_key( "%s::%s" %(options_prefix,"Suite")):
42         suites = utils.split_args(Config()[ "%s::%s" %(options_prefix,"Suite")])
43     else:
44         suites = [ 'unstable', 'testing' ]
45 #            suites = Config().SubTree("Suite").List()
46
47     return suites
48
49 def arches(cursor, suite):
50     """
51     return a list of archs to operate on
52     """
53     arch_list = []
54     cursor.execute("EXECUTE arches_q(%d)" % (suite))
55     while True:
56         r = cursor.fetchone()
57         if not r:
58             break
59
60         if r[1] != "source" and r[1] != "all":
61             arch_list.append((r[0], r[1]))
62
63     return arch_list
64
65 def do_update(self):
66     """
67     Adding contents table as first step to maybe, finally getting rid
68     of apt-ftparchive
69     """
70
71     print __doc__
72
73     try:
74         c = self.db.cursor()
75         c.execute("""CREATE TABLE deb_contents (
76         file text,
77         section text,
78         package text,
79         binary_id integer,
80         arch integer,
81         suite integer,
82         component integer)""" )
83         
84         c.execute("""CREATE TABLE udeb_contents (
85         file text,
86         section text,
87         package text,
88         binary_id integer,
89         suite integer,
90         component integer )""" )
91         
92         c.execute("""ALTER TABLE ONLY deb_contents
93         ADD CONSTRAINT deb_contents_arch_fkey
94         FOREIGN KEY (arch) REFERENCES architecture(id)
95         ON DELETE CASCADE;""")
96
97         c.execute("""ALTER TABLE ONLY udeb_contents
98         ADD CONSTRAINT udeb_contents_arch_fkey
99         FOREIGN KEY (arch) REFERENCES architecture(id)
100         ON DELETE CASCADE;""")
101
102         c.execute("""ALTER TABLE ONLY deb_contents
103         ADD CONSTRAINT deb_contents_suite_fkey
104         FOREIGN KEY (suite) REFERENCES suite(id)
105         ON DELETE CASCADE;""")
106
107         c.execute("""ALTER TABLE ONLY udeb_contents
108         ADD CONSTRAINT udeb_contents_suite_fkey
109         FOREIGN KEY (suite) REFERENCES suite(id)
110         ON DELETE CASCADE;""")
111
112         c.execute("""ALTER TABLE ONLY deb_contents
113         ADD CONSTRAINT deb_contents_binary_fkey
114         FOREIGN KEY (binary_id) REFERENCES binaries(id)
115         ON DELETE CASCADE;""")
116
117         c.execute("""ALTER TABLE ONLY udeb_contents
118         ADD CONSTRAINT udeb_contents_binary_fkey
119         FOREIGN KEY (binary_id) REFERENCES binaries(id)
120         ON DELETE CASCADE;""")
121
122         c.execute("""CREATE INDEX ind_deb_contents_binary ON deb_contents(binary_id);""" )
123
124         arches_q = """PREPARE arches_q(int) as
125         SELECT s.architecture, a.arch_string
126         FROM suite_architectures s
127         JOIN architecture a ON (s.architecture=a.id)
128         WHERE suite = $1"""
129         
130         suites = self.suites()
131
132         for suite in [i.lower() for i in suites]:
133             suite_id = DBConn().get_suite_id(suite)
134             arch_list = arches(c, suite_id)
135             arch_list = arches(c, suite_id)
136
137             for (arch_id,arch_str) in arch_list:
138                 c.execute( "CREATE INDEX ind_deb_contents_%s_%s ON deb_contents (arch,suite) WHERE (arch=2 OR arch=%d) AND suite=$d"%(arch_str,suite,arch_id,suite_id) )
139
140             for section, sname in [("debian-installer","main"),
141                                   ("non-free/debian-installer", "nonfree")]:
142                 c.execute( "CREATE INDEX ind_udeb_contents_%s_%s ON udeb_contents (section,suite) WHERE section=%s AND suite=$d"%(sname,suite,section,suite_id) )
143                 
144
145    Column   |  Type   | Modifiers
146    ------------+---------+-----------
147     package    | text    | not null
148      suite      | integer | not null
149       component  | integer | not null
150        priority   | integer |
151         section    | integer | not null
152          type       | integer | not null
153           maintainer | text    |
154           
155         c.execute("""CREATE TABLE deb_contents (
156         file text,
157         section text,
158         package text,
159         binary_id integer,
160         arch integer,
161         suite integer,
162         component integer)""" )
163         
164
165 CREATE FUNCTION update_contents_for_override() RETURNS trigger AS $update_contents_for_override$
166 BEGIN
167     UPDATE deb_contents  SET section=NEW.section, component=NEW.component
168     WHERE deb_contents.package=OLD.package
169                             
170
171 DELETE FROM 
172 NEW.last_date := current_timestamp;
173 NEW.last_user := current_user;
174 RETURN NEW;
175 END;
176 $update_contents_for_override$ LANGUAGE plpgsql;
177
178
179         self.db.commit()
180
181     except psycopg2.ProgrammingError, msg:
182         self.db.rollback()
183         raise DBUpdateError, "Unable to apply process-new update 14, rollback issued. Error message : %s" % (str(msg))
184 """
185          INSERT INTO deb_contents SELECT (p.path||'/'||n.file) AS file,
186                   s.section AS section,
187                   b.package AS package,
188                   b.id AS binary_id,
189                   b.architecture AS arch,
190                   o.suite AS suited,
191                   o.component AS componentd,
192                   o.type AS otype_id
193           FROM content_associations c 
194           JOIN content_file_paths p ON (c.filepath=p.id)
195           JOIN content_file_names n ON (c.filename=n.id)
196           JOIN binaries b ON (b.id=c.binary_pkg)
197           JOIN architecture a ON (b.architecture = a.id)
198           JOIN override o ON (o.package=b.package)
199           JOIN bin_associations ba on ba.suite=o.suite and ba.bin=b.id
200           JOIN section s ON (s.id=o.section)
201           where b.type='deb';
202
203          INSERT INTO udeb_contents SELECT (p.path||'/'||n.file) AS file,
204                   s.section AS section,
205                   b.package AS package,
206                   b.id AS binary_id,
207                   b.architecture AS arch,
208                   o.suite AS suited,
209                   o.component AS componentd,
210                   o.type AS otype_id
211           FROM content_associations c 
212           JOIN content_file_paths p ON (c.filepath=p.id)
213           JOIN content_file_names n ON (c.filename=n.id)
214           JOIN binaries b ON (b.id=c.binary_pkg)
215           JOIN architecture a ON (b.architecture = a.id)
216           JOIN override o ON (o.package=b.package)
217           JOIN section s ON (s.id=o.section)
218           where b.type='udeb'
219 """
220
221 """
222 CREATE INDEX ind_archid ON contents(arch);
223 CREATE INDEX ind_archid_amd64 ON contents(arch) WHERE arch=16;
224 CREATE INDEX ind_suite ON contents(suite);
225 CREATE INDEX ind_suite_unstable ON contents(suite) WHERE suite=5;
226 CREATE INDEX ind_overridetype ON contents(otype);
227 CREATE INDEX ind_overridetype_deb ON contents(otype) WHERE otype=7;
228 CREATE INDEX ind_packagetype ON contents(packagetype);
229 CREATE INDEX ind_packagetype_deb ON contents(packagetype) WHERE packagetype='deb';
230 CREATE INDEX ind_package ON contents(package);
231
232  CREATE INDEX ind_suite_otype ON contents(suite, otype) WHERE suite=5 AND otype=7;
233  CREATE INDEX ind_suite_otype_arch ON contents(suite, otype, arch) WHERE suite=5 AND otype=7 AND arch=16;
234  CREATE INDEX ind_suite_otype_package ON contents(suite, otype, packagetype) WHERE suite=5 AND otype=7 AND packagetype='deb';
235  CREATE INDEX ind_suite_otype_package_notdeb ON contents(suite, otype, packagetype) WHERE suite=5 AND otype=7 AND packagetype!='deb';
236                                                                                                                                                                                           """
237
238 CREATE INDEX ind_deb_contents_binary ON deb_contents(binary_id);
239
240 CREATE INDEX ind_deb_contents_arch_alpha_unstable ON deb_contents(arch) where (arch=2 or arch=3) AND suite=5 AND otype=7;
241 CREATE INDEX ind_deb_contents_arch_hurd_i386_unstable ON deb_contents(arch) where (arch=2 or arch=4) AND suite=5 AND otype=7;
242 CREATE INDEX ind_deb_contents_arch_hppa_unstable ON deb_contents(arch) where (arch=2 or arch=5) AND suite=5 AND otype=7;
243 CREATE INDEX ind_deb_contents_arch_arm_unstable ON deb_contents(arch) where (arch=2 or arch=6) AND suite=5 AND otype=7;
244 CREATE INDEX ind_deb_contents_arch_i386_unstable ON deb_contents(arch) where (arch=2 or arch=7) AND suite=5 AND otype=7;
245 CREATE INDEX ind_deb_contents_arch_m68k_unstable ON deb_contents(arch) where (arch=2 or arch=8) AND suite=5 AND otype=7;
246 CREATE INDEX ind_deb_contents_arch_mips_unstable ON deb_contents(arch) where (arch=2 or arch=9) AND suite=5 AND otype=7;
247 CREATE INDEX ind_deb_contents_arch_mipsel_unstable ON deb_contents(arch) where (arch=2 or arch=10) AND suite=5 AND otype=7;
248 CREATE INDEX ind_deb_contents_arch_powerpc_unstable ON deb_contents(arch) where (arch=2 or arch=11) AND suite=5 AND otype=7;
249 CREATE INDEX ind_deb_contents_arch_sh_unstable ON deb_contents(arch) where (arch=2 or arch=12) AND suite=5 AND otype=7;
250 CREATE INDEX ind_deb_contents_arch_sparc_unstable ON deb_contents(arch) where (arch=2 or arch=13) AND suite=5 AND otype=7;
251 CREATE INDEX ind_deb_contents_arch_s390_unstable ON deb_contents(arch) where (arch=2 or arch=14) AND suite=5 AND otype=7;
252 CREATE INDEX ind_deb_contents_arch_ia64_unstable ON deb_contents(arch) where (arch=2 or arch=15) AND suite=5 AND otype=7;
253 CREATE INDEX ind_deb_contents_arch_amd64_unstable ON deb_contents(arch) where (arch=2 or arch=16) AND suite=5 AND otype=7;
254 CREATE INDEX ind_deb_contents_arch_armel_unstable ON deb_contents(arch) where (arch=2 or arch=17) AND suite=5 AND otype=7;
255 CREATE INDEX ind_deb_contents_arch_kfreebsd_i386_unstable ON deb_contents(arch) where (arch=2 or arch=25) AND suite=5 AND otype=7;
256 CREATE INDEX ind_deb_contents_arch_kfreebsd_amd64_unstable ON deb_contents(arch) where (arch=2 or arch=26) AND suite=5 AND otype=7;
257
258 CREATE INDEX ind_deb_contents_arch_alpha_stable ON deb_contents(arch) where (arch=2 or arch=3) AND suite=2 AND otype=7;
259 CREATE INDEX ind_deb_contents_arch_hurd_i386_stable ON deb_contents(arch) where (arch=2 or arch=4) AND suite=2 AND otype=7;
260 CREATE INDEX ind_deb_contents_arch_hppa_stable ON deb_contents(arch) where (arch=2 or arch=5) AND suite=2 AND otype=7;
261 CREATE INDEX ind_deb_contents_arch_arm_stable ON deb_contents(arch) where (arch=2 or arch=6) AND suite=2 AND otype=7;
262 CREATE INDEX ind_deb_contents_arch_i386_stable ON deb_contents(arch) where (arch=2 or arch=7) AND suite=2 AND otype=7;
263 CREATE INDEX ind_deb_contents_arch_m68k_stable ON deb_contents(arch) where (arch=2 or arch=8) AND suite=2 AND otype=7;
264 CREATE INDEX ind_deb_contents_arch_mips_stable ON deb_contents(arch) where (arch=2 or arch=9) AND suite=2 AND otype=7;
265 CREATE INDEX ind_deb_contents_arch_mipsel_stable ON deb_contents(arch) where (arch=2 or arch=10) AND suite=2 AND otype=7;
266 CREATE INDEX ind_deb_contents_arch_powerpc_stable ON deb_contents(arch) where (arch=2 or arch=11) AND suite=2 AND otype=7;
267 CREATE INDEX ind_deb_contents_arch_sh_stable ON deb_contents(arch) where (arch=2 or arch=12) AND suite=2 AND otype=7;
268 CREATE INDEX ind_deb_contents_arch_sparc_stable ON deb_contents(arch) where (arch=2 or arch=13) AND suite=2 AND otype=7;
269 CREATE INDEX ind_deb_contents_arch_s390_stable ON deb_contents(arch) where (arch=2 or arch=14) AND suite=2 AND otype=7;
270 CREATE INDEX ind_deb_contents_arch_ia64_stable ON deb_contents(arch) where (arch=2 or arch=15) AND suite=2 AND otype=7;
271 CREATE INDEX ind_deb_contents_arch_amd64_stable ON deb_contents(arch) where (arch=2 or arch=16) AND suite=2 AND otype=7;
272 CREATE INDEX ind_deb_contents_arch_armel_stable ON deb_contents(arch) where (arch=2 or arch=17) AND suite=2 AND otype=7;
273 CREATE INDEX ind_deb_contents_arch_kfreebsd_i386_stable ON deb_contents(arch) where (arch=2 or arch=25) AND suite=2 AND otype=7;
274 CREATE INDEX ind_deb_contents_arch_kfreebsd_amd64_stable ON deb_contents(arch) where (arch=2 or arch=26) AND suite=2 AND otype=7;
275
276 CREATE INDEX ind_deb_contents_arch_alpha_testing ON deb_contents(arch) where (arch=2 or arch=3) AND suite=4 AND otype=7;
277 CREATE INDEX ind_deb_contents_arch_hurd_i386_testing ON deb_contents(arch) where (arch=2 or arch=4) AND suite=4 AND otype=7;
278 CREATE INDEX ind_deb_contents_arch_hppa_testing ON deb_contents(arch) where (arch=2 or arch=5) AND suite=4 AND otype=7;
279 CREATE INDEX ind_deb_contents_arch_arm_testing ON deb_contents(arch) where (arch=2 or arch=6) AND suite=4 AND otype=7;
280 CREATE INDEX ind_deb_contents_arch_i386_testing ON deb_contents(arch) where (arch=2 or arch=7) AND suite=4 AND otype=7;
281 CREATE INDEX ind_deb_contents_arch_m68k_testing ON deb_contents(arch) where (arch=2 or arch=8) AND suite=4 AND otype=7;
282 CREATE INDEX ind_deb_contents_arch_mips_testing ON deb_contents(arch) where (arch=2 or arch=9) AND suite=4 AND otype=7;
283 CREATE INDEX ind_deb_contents_arch_mipsel_testing ON deb_contents(arch) where (arch=2 or arch=10) AND suite=4 AND otype=7;
284 CREATE INDEX ind_deb_contents_arch_powerpc_testing ON deb_contents(arch) where (arch=2 or arch=11) AND suite=4 AND otype=7;
285 CREATE INDEX ind_deb_contents_arch_sh_testing ON deb_contents(arch) where (arch=2 or arch=12) AND suite=4 AND otype=7;
286 CREATE INDEX ind_deb_contents_arch_sparc_testing ON deb_contents(arch) where (arch=2 or arch=13) AND suite=4 AND otype=7;
287 CREATE INDEX ind_deb_contents_arch_s390_testing ON deb_contents(arch) where (arch=2 or arch=14) AND suite=4 AND otype=7;
288 CREATE INDEX ind_deb_contents_arch_ia64_testing ON deb_contents(arch) where (arch=2 or arch=15) AND suite=4 AND otype=7;
289 CREATE INDEX ind_deb_contents_arch_amd64_testing ON deb_contents(arch) where (arch=2 or arch=16) AND suite=4 AND otype=7;
290 CREATE INDEX ind_deb_contents_arch_armel_testing ON deb_contents(arch) where (arch=2 or arch=17) AND suite=4 AND otype=7;
291 CREATE INDEX ind_deb_contents_arch_kfreebsd_i386_testing ON deb_contents(arch) where (arch=2 or arch=25) AND suite=4 AND otype=7;
292 CREATE INDEX ind_deb_contents_arch_kfreebsd_amd64_testing ON deb_contents(arch) where (arch=2 or arch=26) AND suite=4 AND otype=7;
293
294 CREATE INDEX ind_deb_contents_arch_alpha_oldstable ON deb_contents(arch) where (arch=2 or arch=3) AND suite=14 AND otype=7;
295 CREATE INDEX ind_deb_contents_arch_hurd_i386_oldstable ON deb_contents(arch) where (arch=2 or arch=4) AND suite=14 AND otype=7;
296 CREATE INDEX ind_deb_contents_arch_hppa_oldstable ON deb_contents(arch) where (arch=2 or arch=5) AND suite=14 AND otype=7;
297 CREATE INDEX ind_deb_contents_arch_arm_oldstable ON deb_contents(arch) where (arch=2 or arch=6) AND suite=14 AND otype=7;
298 CREATE INDEX ind_deb_contents_arch_i386_oldstable ON deb_contents(arch) where (arch=2 or arch=7) AND suite=14 AND otype=7;
299 CREATE INDEX ind_deb_contents_arch_m68k_oldstable ON deb_contents(arch) where (arch=2 or arch=8) AND suite=14 AND otype=7;
300 CREATE INDEX ind_deb_contents_arch_mips_oldstable ON deb_contents(arch) where (arch=2 or arch=9) AND suite=14 AND otype=7;
301 CREATE INDEX ind_deb_contents_arch_mipsel_oldstable ON deb_contents(arch) where (arch=2 or arch=10) AND suite=14 AND otype=7;
302 CREATE INDEX ind_deb_contents_arch_powerpc_oldstable ON deb_contents(arch) where (arch=2 or arch=11) AND suite=14 AND otype=7;
303 CREATE INDEX ind_deb_contents_arch_sh_oldstable ON deb_contents(arch) where (arch=2 or arch=12) AND suite=14 AND otype=7;
304 CREATE INDEX ind_deb_contents_arch_sparc_oldstable ON deb_contents(arch) where (arch=2 or arch=13) AND suite=14 AND otype=7;
305 CREATE INDEX ind_deb_contents_arch_s390_oldstable ON deb_contents(arch) where (arch=2 or arch=14) AND suite=14 AND otype=7;
306 CREATE INDEX ind_deb_contents_arch_ia64_oldstable ON deb_contents(arch) where (arch=2 or arch=15) AND suite=14 AND otype=7;
307 CREATE INDEX ind_deb_contents_arch_amd64_oldstable ON deb_contents(arch) where (arch=2 or arch=16) AND suite=14 AND otype=7;
308 CREATE INDEX ind_deb_contents_arch_armel_oldstable ON deb_contents(arch) where (arch=2 or arch=17) AND suite=14 AND otype=7;
309 CREATE INDEX ind_deb_contents_arch_kfreebsd_i386_oldstable ON deb_contents(arch) where (arch=2 or arch=25) AND suite=14 AND otype=7;
310 CREATE INDEX ind_deb_contents_arch_kfreebsd_amd64_oldstable ON deb_contents(arch) where (arch=2 or arch=26) AND suite=14 AND otype=7;