]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update24.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update24.py
1 #!/usr/bin/env python
2
3 """
4 Add some meta info to queues
5
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2009  Mark Hymers <mhy@debian.org>
8 @license: GNU General Public License version 2 or later
9 """
10
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.
15
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.
20
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
24
25 import psycopg2
26
27 def do_update(self):
28     print "Add meta info columns to queues."
29
30     try:
31         c = self.db.cursor()
32
33         c.execute("ALTER TABLE policy_queue ADD COLUMN generate_metadata BOOL DEFAULT FALSE NOT NULL")
34         c.execute("ALTER TABLE policy_queue ADD COLUMN origin TEXT DEFAULT NULL")
35         c.execute("ALTER TABLE policy_queue ADD COLUMN label TEXT DEFAULT NULL")
36         c.execute("ALTER TABLE policy_queue ADD COLUMN releasedescription TEXT DEFAULT NULL")
37         c.execute("ALTER TABLE policy_queue ADD COLUMN signingkey TEXT DEFAULT NULL")
38         c.execute("ALTER TABLE policy_queue ADD COLUMN stay_of_execution INT4 NOT NULL DEFAULT 86400 CHECK (stay_of_execution >= 0)")
39         c.execute("""ALTER TABLE policy_queue
40                        ADD CONSTRAINT policy_queue_meta_sanity_check
41                            CHECK ( (generate_metadata IS FALSE)
42                                 OR (origin IS NOT NULL AND label IS NOT NULL AND releasedescription IS NOT NULL) )""")
43
44         c.execute("ALTER TABLE build_queue ADD COLUMN generate_metadata BOOL DEFAULT FALSE NOT NULL")
45         c.execute("ALTER TABLE build_queue ADD COLUMN origin TEXT DEFAULT NULL")
46         c.execute("ALTER TABLE build_queue ADD COLUMN label TEXT DEFAULT NULL")
47         c.execute("ALTER TABLE build_queue ADD COLUMN releasedescription TEXT DEFAULT NULL")
48         c.execute("ALTER TABLE build_queue ADD COLUMN signingkey TEXT DEFAULT NULL")
49         c.execute("ALTER TABLE build_queue ADD COLUMN stay_of_execution INT4 NOT NULL DEFAULT 86400 CHECK (stay_of_execution >= 0)")
50         c.execute("""ALTER TABLE build_queue
51                        ADD CONSTRAINT build_queue_meta_sanity_check
52                            CHECK ( (generate_metadata IS FALSE)
53                                 OR (origin IS NOT NULL AND label IS NOT NULL AND releasedescription IS NOT NULL) )""")
54
55         print "Committing"
56         c.execute("UPDATE config SET value = '24' WHERE name = 'db_revision'")
57         self.db.commit()
58
59     except psycopg2.InternalError as msg:
60         self.db.rollback()
61         raise DBUpdateError, "Database error, rollback issued. Error message : %s" % (str(msg))
62