X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fdakdb%2Fupdate1.py;h=ede12e56c949315ccd3790d7d212cae455569be5;hb=27e00376e81d1c37ff327ee0d39670b266418869;hp=a7ceb20a164b22eca0164648623d5c871a082739;hpb=a10398019d83fb13fbe230c944ed51470a35df34;p=dak.git diff --git a/dak/dakdb/update1.py b/dak/dakdb/update1.py old mode 100644 new mode 100755 index a7ceb20a..ede12e56 --- a/dak/dakdb/update1.py +++ b/dak/dakdb/update1.py @@ -1,7 +1,12 @@ #!/usr/bin/env python -# Debian Archive Kit Database Update Script -# Copyright (C) 2008 Michael Casadevall +""" +Saner DM db schema + +@contact: Debian FTP Master +@copyright: 2008 Michael Casadevall +@license: GNU General Public License version 2 or later +""" # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,6 +30,8 @@ ################################################################################ import psycopg2 +import time +from daklib.dak_exceptions import DBUpdateError ################################################################################ @@ -32,20 +39,31 @@ def do_update(self): print "Adding DM fields to database" try: - c = self.db.cursor() - c.execute("ALTER TABLE source ADD COLUMN dm_upload_allowed BOOLEAN DEFAULT 'no' NOT NULL;") - c.execute("ALTER TABLE uid ADD COLUMN debian_maintainer BOOLEAN DEFAULT 'false' NOT NULL;") + c = self.db.cursor() + c.execute("ALTER TABLE source ADD COLUMN dm_upload_allowed BOOLEAN DEFAULT 'no' NOT NULL;") + c.execute("ALTER TABLE keyrings ADD COLUMN debian_maintainer BOOLEAN DEFAULT 'false' NOT NULL;") + + print "Migrating DM data to source table. This might take some time ..." + + c.execute("UPDATE source SET dm_upload_allowed = 't' WHERE id IN (SELECT source FROM src_uploaders);") + c.execute("UPDATE config SET value = '1' WHERE name = 'db_revision'") - print "Migrating DM data to source table. This might take some time ..." + print "Migrating DM uids to normal uids" + c.execute("SELECT uid FROM uid WHERE uid LIKE 'dm:%'") + rows = c.fetchall() + for r in rows: + uid = r[0] + c.execute("UPDATE uid SET uid = '%s' WHERE uid = '%s'" % (uid[3:], uid)) - c.execute("UPDATE source SET dm_upload_allowed = 't' WHERE id = (SELECT source FROM src_uploaders);") - c.execute("UPDATE config SET value = '1' WHERE name = 'db_revision'") - self.db.commit() + self.db.commit() - print "REMINDER: Remember to run the updated byhand-dm crontab to update Debian Maintainer information" + print "IMPORTANT: Set the debian_maintainer flag in the config file for keyrings that are DMs!" + print " Failure to do so will result in DM's having full upload abilities!" + print "REMINDER: Remember to run the updated byhand-dm crontab to update Debian Maintainer information" + print "" + print "Pausing for five seconds ..." + time.sleep (5) - except psycopg2.ProgrammingError, msg: + except psycopg2.ProgrammingError as msg: self.db.rollback() - print "FATAL: Unable to apply DM table update 1!" - print "Error Message: " + str(msg) - print "Database changes have been rolled back." + raise DBUpdateError, "Unable to appy DM table updates, rollback issued. Error message : %s" % (str(msg))