7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2009 Mark Hymers <mhy@debian.org>
9 @license: GNU General Public License version 2 or later
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.
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.
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
26 ################################################################################
29 ################################################################################
37 from daklib.dak_exceptions import DBUpdateError
38 from daklib.config import Config
40 ################################################################################
43 print "Splitting up queues and fixing general design mistakes"
50 print "Adding build_queue table"
51 c.execute("""CREATE TABLE build_queue (
52 id SERIAL PRIMARY KEY,
53 queue_name TEXT NOT NULL UNIQUE,
55 copy_files BOOL DEFAULT FALSE NOT NULL)""")
57 print "Adding policy_queue table"
58 c.execute("""CREATE TABLE policy_queue (
59 id SERIAL PRIMARY KEY,
60 queue_name TEXT NOT NULL UNIQUE,
62 perms CHAR(4) NOT NULL DEFAULT '0660' CHECK (perms SIMILAR TO '^[0-7][0-7][0-7][0-7]$'),
63 change_perms CHAR(4) NOT NULL DEFAULT '0660' CHECK (change_perms SIMILAR TO '^[0-7][0-7][0-7][0-7]$')
66 print "Copying queues"
68 c.execute("""SELECT queue.id, queue.queue_name, queue.path, queue.copy_pool_files FROM queue""")
70 for q in c.fetchall():
72 if q[1] in ['accepted', 'buildd']:
73 # Move to build_queue_table
74 c.execute("""INSERT INTO build_queue (queue_name, path, copy_files)
75 VALUES ('%s', '%s', '%s')""" % (q[1], q[2], q[3]))
78 # Move to policy_queue_table
79 c.execute("""INSERT INTO policy_queue (queue_name, path)
80 VALUES ('%s', '%s')""" % (q[1], q[2]))
83 print "Fixing up build_queue_files"
84 c.execute("""ALTER TABLE queue_files DROP CONSTRAINT queue_files_queueid_fkey""")
85 c.execute("""ALTER TABLE queue_files RENAME TO build_queue_files""")
86 c.execute("""ALTER TABLE build_queue_files RENAME COLUMN queueid TO build_queue_id""")
88 c.execute("""UPDATE build_queue_files
89 SET build_queue_id = (SELECT build_queue.id FROM build_queue
90 WHERE build_queue.queue_name =
91 (SELECT queue.queue_name FROM queue
92 WHERE queue.id = build_queue_files.build_queue_id))""")
94 c.execute("""ALTER TABLE build_queue_files
95 ADD CONSTRAINT build_queue_files_build_queue_id_fkey
96 FOREIGN KEY (build_queue_id)
97 REFERENCES build_queue(id)
101 c.execute("""ALTER TABLE suite DROP CONSTRAINT suite_policy_queue_id_fkey""")
103 c.execute("""UPDATE suite
104 SET policy_queue_id = (SELECT policy_queue.id FROM policy_queue
105 WHERE policy_queue.queue_name =
106 (SELECT queue.queue_name FROM queue
107 WHERE queue.id = suite.policy_queue_id))""")
109 c.execute("""ALTER TABLE suite
110 ADD CONSTRAINT suite_policy_queue_fkey
111 FOREIGN KEY (policy_queue_id)
112 REFERENCES policy_queue (id)
113 ON DELETE RESTRICT""")
115 c.execute("""ALTER TABLE known_changes DROP CONSTRAINT known_changes_approved_for_fkey""")
116 c.execute("""ALTER TABLE known_changes DROP CONSTRAINT known_changes_in_queue_fkey""")
118 c.execute("""UPDATE known_changes
119 SET in_queue = (SELECT policy_queue.id FROM policy_queue
120 WHERE policy_queue.queue_name =
121 (SELECT queue.queue_name FROM queue
122 WHERE queue.id = known_changes.in_queue))""")
124 c.execute("""ALTER TABLE known_changes
125 ADD CONSTRAINT known_changes_in_queue_fkey
126 FOREIGN KEY (in_queue)
127 REFERENCES policy_queue (id)
128 ON DELETE RESTRICT""")
132 c.execute("""UPDATE known_changes
133 SET approved_for = (SELECT policy_queue.id FROM policy_queue
134 WHERE policy_queue.queue_name =
135 (SELECT queue.queue_name FROM queue
136 WHERE queue.id = known_changes.approved_for))""")
138 c.execute("""ALTER TABLE known_changes
139 ADD CONSTRAINT known_changes_approved_for_fkey
140 FOREIGN KEY (in_queue)
141 REFERENCES policy_queue (id)
142 ON DELETE RESTRICT""")
144 c.execute("""ALTER TABLE suite_queue_copy RENAME TO suite_build_queue_copy""")
146 c.execute("""ALTER TABLE suite_build_queue_copy DROP CONSTRAINT suite_queue_copy_queue_fkey""")
148 c.execute("""ALTER TABLE suite_build_queue_copy RENAME COLUMN queue TO build_queue_id""")
150 c.execute("""UPDATE suite_build_queue_copy
151 SET build_queue_id = (SELECT build_queue.id FROM build_queue
152 WHERE build_queue.queue_name =
153 (SELECT queue.queue_name FROM queue
154 WHERE queue.id = suite_build_queue_copy.build_queue_id))""")
156 c.execute("""ALTER TABLE suite_build_queue_copy
157 ADD CONSTRAINT suite_build_queue_copy_build_queue_id_fkey
158 FOREIGN KEY (build_queue_id)
159 REFERENCES build_queue (id)
160 ON DELETE RESTRICT""")
162 c.execute("""DROP TABLE changes_pending_files""")
164 c.execute("""CREATE TABLE changes_pending_files (
165 id SERIAL PRIMARY KEY,
166 filename TEXT NOT NULL UNIQUE,
167 size BIGINT NOT NULL,
168 md5sum TEXT NOT NULL,
169 sha1sum TEXT NOT NULL,
170 sha256sum TEXT NOT NULL )""")
172 c.execute("""CREATE TABLE changes_pending_files_map (
173 file_id INT4 NOT NULL REFERENCES changes_pending_files (id),
174 change_id INT4 NOT NULL REFERENCES known_changes (id),
176 PRIMARY KEY (file_id, change_id))""")
178 c.execute("""CREATE TABLE changes_pending_source (
179 id SERIAL PRIMARY KEY,
180 change_id INT4 NOT NULL REFERENCES known_changes (id),
181 source TEXT NOT NULL,
182 version DEBVERSION NOT NULL,
183 maintainer_id INT4 NOT NULL REFERENCES maintainer (id),
184 changedby_id INT4 NOT NULL REFERENCES maintainer (id),
185 sig_fpr INT4 NOT NULL REFERENCES fingerprint (id),
186 dm_upload_allowed BOOL NOT NULL DEFAULT FALSE )""")
188 c.execute("""CREATE TABLE changes_pending_source_files (
189 pending_source_id INT4 REFERENCES changes_pending_source (id) NOT NULL,
190 pending_file_id INT4 REFERENCES changes_pending_files (id) NOT NULL,
192 PRIMARY KEY (pending_source_id, pending_file_id) )""")
194 c.execute("""CREATE TABLE changes_pending_binaries (
195 id SERIAL PRIMARY KEY,
196 change_id INT4 NOT NULL REFERENCES known_changes (id),
197 package TEXT NOT NULL,
198 version DEBVERSION NOT NULL,
199 architecture_id INT4 REFERENCES architecture (id) NOT NULL,
200 source_id INT4 REFERENCES source (id),
201 pending_source_id INT4 REFERENCES changes_pending_source (id),
202 pending_file_id INT4 REFERENCES changes_pending_files (id),
204 UNIQUE (package, version, architecture_id),
205 CHECK (source_id IS NOT NULL or pending_source_id IS NOT NULL ) )""")
207 print "Getting rid of old queue table"
208 c.execute("""DROP TABLE queue""")
210 print "Sorting out permission columns"
211 c.execute("""UPDATE policy_queue SET perms = '0664' WHERE queue_name IN ('proposedupdates', 'oldproposedupdates')""")
213 print "Moving known_changes table"
214 c.execute("""ALTER TABLE known_changes RENAME TO changes""")
216 print "Sorting out permissions"
218 for t in ['build_queue', 'policy_queue', 'build_queue_files',
219 'changes_pending_binaries', 'changes_pending_source_files',
220 'changes_pending_source', 'changes_pending_files',
221 'changes_pool_files', 'suite_build_queue_copy']:
222 c.execute("GRANT SELECT ON %s TO public" % t)
223 c.execute("GRANT ALL ON %s TO ftpmaster" % t)
225 for s in ['queue_files_id_seq', 'build_queue_id_seq',
226 'changes_pending_source_id_seq',
227 'changes_pending_binaries_id_seq',
228 'changes_pending_files_id_seq',
229 'changes_pending_source_id_seq',
230 'known_changes_id_seq',
231 'policy_queue_id_seq']:
232 c.execute("GRANT USAGE ON %s TO ftpmaster" % s)
235 c.execute("UPDATE config SET value = '22' WHERE name = 'db_revision'")
238 except psycopg2.InternalError, msg:
240 raise DBUpdateError, "Unable to apply queue_build 21, rollback issued. Error message : %s" % (str(msg))