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,
61 path TEXT NOT NULL)""")
63 print "Copying queues"
65 c.execute("""SELECT queue.id, queue.queue_name, queue.path, queue.copy_pool_files FROM queue""")
67 for q in c.fetchall():
69 if q[1] in ['accepted', 'buildd']:
70 # Move to build_queue_table
71 c.execute("""INSERT INTO build_queue (queue_name, path, copy_files)
72 VALUES ('%s', '%s', '%s')""" % (q[1], q[2], q[3]))
75 # Move to policy_queue_table
76 c.execute("""INSERT INTO policy_queue (queue_name, path)
77 VALUES ('%s', '%s')""" % (q[1], q[2]))
80 print "Fixing up build_queue_files"
81 c.execute("""ALTER TABLE queue_files DROP CONSTRAINT queue_files_queueid_fkey""")
82 c.execute("""ALTER TABLE queue_files RENAME TO build_queue_files""")
83 c.execute("""ALTER TABLE build_queue_files RENAME COLUMN queueid TO build_queue_id""")
85 c.execute("""UPDATE build_queue_files
86 SET build_queue_id = (SELECT build_queue.id FROM build_queue
87 WHERE build_queue.queue_name =
88 (SELECT queue.queue_name FROM queue
89 WHERE queue.id = build_queue_files.build_queue_id))""")
91 c.execute("""ALTER TABLE build_queue_files
92 ADD CONSTRAINT build_queue_files_build_queue_id_fkey
93 FOREIGN KEY (build_queue_id)
94 REFERENCES build_queue(id)
98 c.execute("""ALTER TABLE suite DROP CONSTRAINT suite_policy_queue_id_fkey""")
100 c.execute("""UPDATE suite
101 SET policy_queue_id = (SELECT policy_queue.id FROM policy_queue
102 WHERE policy_queue.queue_name =
103 (SELECT queue.queue_name FROM queue
104 WHERE queue.id = suite.policy_queue_id))""")
106 c.execute("""ALTER TABLE suite
107 ADD CONSTRAINT suite_policy_queue_fkey
108 FOREIGN KEY (policy_queue_id)
109 REFERENCES policy_queue (id)
110 ON DELETE RESTRICT""")
112 c.execute("""ALTER TABLE known_changes DROP CONSTRAINT known_changes_approved_for_fkey""")
113 c.execute("""ALTER TABLE known_changes DROP CONSTRAINT known_changes_in_queue_fkey""")
115 c.execute("""UPDATE known_changes
116 SET in_queue = (SELECT policy_queue.id FROM policy_queue
117 WHERE policy_queue.queue_name =
118 (SELECT queue.queue_name FROM queue
119 WHERE queue.id = known_changes.in_queue))""")
121 c.execute("""ALTER TABLE known_changes
122 ADD CONSTRAINT known_changes_in_queue_fkey
123 FOREIGN KEY (in_queue)
124 REFERENCES policy_queue (id)
125 ON DELETE RESTRICT""")
129 c.execute("""UPDATE known_changes
130 SET approved_for = (SELECT policy_queue.id FROM policy_queue
131 WHERE policy_queue.queue_name =
132 (SELECT queue.queue_name FROM queue
133 WHERE queue.id = known_changes.approved_for))""")
135 c.execute("""ALTER TABLE known_changes
136 ADD CONSTRAINT known_changes_approved_for_fkey
137 FOREIGN KEY (in_queue)
138 REFERENCES policy_queue (id)
139 ON DELETE RESTRICT""")
141 c.execute("""ALTER TABLE suite_queue_copy RENAME TO suite_build_queue_copy""")
143 c.execute("""ALTER TABLE suite_build_queue_copy DROP CONSTRAINT suite_queue_copy_queue_fkey""")
145 c.execute("""ALTER TABLE suite_build_queue_copy RENAME COLUMN queue TO build_queue_id""")
147 c.execute("""UPDATE suite_build_queue_copy
148 SET build_queue_id = (SELECT build_queue.id FROM build_queue
149 WHERE build_queue.queue_name =
150 (SELECT queue.queue_name FROM queue
151 WHERE queue.id = suite_build_queue_copy.build_queue_id))""")
153 c.execute("""ALTER TABLE suite_build_queue_copy
154 ADD CONSTRAINT suite_build_queue_copy_build_queue_id_fkey
155 FOREIGN KEY (build_queue_id)
156 REFERENCES build_queue (id)
157 ON DELETE RESTRICT""")
159 c.execute("""DROP TABLE changes_pending_files""")
161 c.execute("""CREATE TABLE changes_pending_files (
162 id SERIAL PRIMARY KEY,
163 filename TEXT NOT NULL UNIQUE,
164 size BIGINT NOT NULL,
165 md5sum TEXT NOT NULL,
166 sha1sum TEXT NOT NULL,
167 sha256sum TEXT NOT NULL )""")
169 c.execute("""CREATE TABLE changes_pending_files_map (
170 file_id INT4 NOT NULL REFERENCES changes_pending_files (id),
171 change_id INT4 NOT NULL REFERENCES known_changes (id),
173 PRIMARY KEY (file_id, change_id))""")
175 c.execute("""CREATE TABLE changes_pending_source (
176 id SERIAL PRIMARY KEY,
177 change_id INT4 NOT NULL REFERENCES known_changes (id),
178 source TEXT NOT NULL,
179 version DEBVERSION NOT NULL,
180 maintainer_id INT4 NOT NULL REFERENCES maintainer (id),
181 changedby_id INT4 NOT NULL REFERENCES maintainer (id),
182 sig_fpr INT4 NOT NULL REFERENCES fingerprint (id),
183 dm_upload_allowed BOOL NOT NULL DEFAULT FALSE )""")
185 c.execute("""CREATE TABLE changes_pending_source_files (
186 pending_source_id INT4 REFERENCES changes_pending_source (id) NOT NULL,
187 pending_file_id INT4 REFERENCES changes_pending_files (id) NOT NULL,
189 PRIMARY KEY (pending_source_id, pending_file_id) )""")
191 c.execute("""CREATE TABLE changes_pending_binaries (
192 id SERIAL PRIMARY KEY,
193 change_id INT4 NOT NULL REFERENCES known_changes (id),
194 package TEXT NOT NULL,
195 version DEBVERSION NOT NULL,
196 architecture_id INT4 REFERENCES architecture (id) NOT NULL,
197 source_id INT4 REFERENCES source (id),
198 pending_source_id INT4 REFERENCES changes_pending_source (id),
199 pending_file_id INT4 REFERENCES changes_pending_files (id),
201 UNIQUE (package, version, architecture_id),
202 CHECK (source_id IS NOT NULL or pending_source_id IS NOT NULL ) )""")
204 print "Getting rid of old queue table"
205 c.execute("""DROP TABLE queue""")
207 print "Moving known_changes table"
208 c.execute("""ALTER TABLE known_changes RENAME TO changes""")
210 print "Sorting out permissions"
212 for t in ['build_queue', 'policy_queue', 'build_queue_files',
213 'changes_pending_binaries', 'changes_pending_source_files',
214 'changes_pending_source', 'changes_pending_files',
215 'changes_pool_files', 'suite_build_queue_copy']:
216 c.execute("GRANT SELECT ON %s TO public" % t)
217 c.execute("GRANT ALL ON %s TO ftpmaster" % t)
219 for s in ['queue_files_id_seq', 'build_queue_id_seq',
220 'changes_pending_source_id_seq',
221 'changes_pending_binaries_id_seq',
222 'changes_pending_files_id_seq',
223 'changes_pending_source_id_seq',
224 'known_changes_id_seq',
225 'policy_queue_id_seq']:
226 c.execute("GRANT USAGE ON %s TO ftpmaster" % s)
229 c.execute("UPDATE config SET value = '22' WHERE name = 'db_revision'")
232 except psycopg2.InternalError, msg:
234 raise DBUpdateError, "Unable to apply queue_build 21, rollback issued. Error message : %s" % (str(msg))