]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update1.py
Contents generation should be working now
[dak.git] / dak / dakdb / update1.py
1 #!/usr/bin/env python
2
3 """ Database Update Script - Saner DM db schema """
4 # Copyright (C) 2008  Michael Casadevall <mcasadevall@debian.org>
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 ################################################################################
21
22 # <tomv_w> really, if we want to screw ourselves, let's find a better way.
23 # <Ganneff> rm -rf /srv/ftp.debian.org
24
25 ################################################################################
26
27 import psycopg2, time
28
29 ################################################################################
30
31 def do_update(self):
32     print "Adding DM fields to database"
33
34     try:
35         c = self.db.cursor()
36         c.execute("ALTER TABLE source ADD COLUMN dm_upload_allowed BOOLEAN DEFAULT 'no' NOT NULL;")
37         c.execute("ALTER TABLE keyrings ADD COLUMN debian_maintainer BOOLEAN DEFAULT 'false' NOT NULL;")
38
39         print "Migrating DM data to source table. This might take some time ..."
40
41         c.execute("UPDATE source SET dm_upload_allowed = 't' WHERE id IN (SELECT source FROM src_uploaders);")
42         c.execute("UPDATE config SET value = '1' WHERE name = 'db_revision'")
43
44         print "Migrating DM uids to normal uids"
45         c.execute("SELECT uid FROM uid WHERE uid  LIKE 'dm:%'")
46         rows = c.fetchall()
47         for r in rows:
48             uid = r[0]
49             c.execute("UPDATE uid SET uid = '%s' WHERE uid = '%s'" % (uid[3:], uid))
50
51         self.db.commit()
52
53         print "IMPORTANT: Set the debian_maintainer flag in the config file for keyrings that are DMs!"
54         print "           Failure to do so will result in DM's having full upload abilities!"
55         print "REMINDER: Remember to run the updated byhand-dm crontab to update Debian Maintainer information"
56         print ""
57         print "Pausing for five seconds ..."
58         time.sleep (5)
59
60     except psycopg2.ProgrammingError, msg:
61         self.db.rollback()
62         print "FATAL: Unable to apply DM table update 1!"
63         print "Error Message: " + str(msg)
64         print "Database changes have been rolled back."