5 Modify queue autobuild support
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 "Updating queue_build table"
50 print "Adding copy_files field to queue table"
51 c.execute("ALTER TABLE queue ADD copy_pool_files BOOL NOT NULL DEFAULT FALSE")
53 print "Adding queue_files table"
55 c.execute("""CREATE TABLE queue_files (
56 id SERIAL PRIMARY KEY,
57 queueid INT4 NOT NULL REFERENCES queue(id) ON DELETE RESTRICT,
58 insertdate TIMESTAMP NOT NULL DEFAULT now(),
59 lastused TIMESTAMP DEFAULT NULL,
60 filename TEXT NOT NULL,
61 fileid INT4 REFERENCES files(id) ON DELETE CASCADE)""")
63 c.execute("""SELECT queue_build.filename, queue_build.last_used, queue_build.queue
66 for r in c.fetchall():
72 endlink = os.readlink(filename)
73 c.execute("SELECT files.id FROM files WHERE filename LIKE '%%%s'" % endlink[endlink.rindex('/')+1:])
75 c.execute("""INSERT INTO queue_files (queueid, lastused, filename, fileid) VALUES
76 (%s, now(), %s, %s)""", (queue, filename[filename.rindex('/')+1:], f[0]))
78 print "Can't find file %s (%s)" % (filename, e)
80 print "Dropping old queue_build table"
81 c.execute("DROP TABLE queue_build")
83 print "Adding changes_pending_files table"
84 c.execute("""CREATE TABLE changes_pending_files (
85 id SERIAL PRIMARY KEY,
86 changeid INT4 NOT NULL REFERENCES known_changes(id) ON DELETE CASCADE,
87 filename TEXT NOT NULL,
88 source BOOL NOT NULL DEFAULT FALSE,
89 filesize BIGINT NOT NULL,
91 sha1sum TEXT NOT NULL,
92 sha256sum TEXT NOT NULL)""")
95 print "Adding changes_pool_files table"
96 c.execute("""CREATE TABLE changes_pool_files (
97 changeid INT4 NOT NULL REFERENCES known_changes(id) ON DELETE CASCADE,
98 fileid INT4 NOT NULL REFERENCES files(id) ON DELETE RESTRICT,
100 PRIMARY KEY (changeid, fileid))""")
102 print "Adding suite_queue_copy table"
103 c.execute("""CREATE TABLE suite_queue_copy (
104 suite INT4 NOT NULL REFERENCES suite(id),
105 queue INT4 NOT NULL REFERENCES queue(id),
107 PRIMARY KEY (suite, queue))""")
109 # Link all suites from accepted
110 c.execute("""SELECT suite.id FROM suite""")
111 for s in c.fetchall():
112 c.execute("""INSERT INTO suite_queue_copy (suite, queue) VALUES (%s, (SELECT id FROM queue WHERE queue_name = 'accepted'))""", s)
114 # Parse the config and add any buildd stuff
116 c.execute("""INSERT INTO queue (queue_name, path) VALUES ('buildd', '%s')""" % cnf["Dir::QueueBuild"].rstrip('/'))
118 for s in cnf.ValueList("Dinstall::QueueBuildSuites"):
119 c.execute("""INSERT INTO suite_queue_copy (suite, queue)
120 VALUES ( (SELECT id FROM suite WHERE suite_name = '%s'),
121 (SELECT id FROM queue WHERE queue_name = 'buildd'))""" % s.lower())
124 c.execute("UPDATE config SET value = '21' WHERE name = 'db_revision'")
127 except psycopg2.InternalError, msg:
129 raise DBUpdateError, "Unable to apply queue_build 21, rollback issued. Error message : %s" % (str(msg))