X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fdakdb%2Fupdate3.py;h=f7a4e5026e3c79908c208040f5a46d9ab273169c;hb=7ed15b809fd22f3325aed4e4a1ecac4387417437;hp=eef7d4c6a003ade245a2afc2bc7a49054f64ba40;hpb=6a4cddfbe864e563e671fe5dabf5600c4783af5c;p=dak.git diff --git a/dak/dakdb/update3.py b/dak/dakdb/update3.py old mode 100755 new mode 100644 index eef7d4c6..f7a4e502 --- a/dak/dakdb/update3.py +++ b/dak/dakdb/update3.py @@ -1,8 +1,13 @@ #!/usr/bin/env python -""" Database Update Script - Remove unused versioncmp """ -# Copyright (C) 2008 Michael Casadevall -# Copyright (C) 2009 Joerg Jaspert +""" +Remove unused versioncmp + +@contact: Debian FTP Master +@copyright: 2008 Michael Casadevall +@copyright: 2009 Joerg Jaspert +@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 @@ -31,11 +36,19 @@ def do_update(self): try: c = self.db.cursor() - c.execute("DROP FUNCTION versioncmp(text, text);") + # The reason we try and check to see if it exists is that + # psycopg2 might leave the cursor invalid if the drop fails + c.execute("SELECT proname from pg_catalog.pg_proc WHERE proname = 'versioncmp'") + rows = c.fetchall() + if rows: + c.execute("DROP FUNCTION versioncmp(text, text);") + else: + print "function already does not exist" + c.execute("UPDATE config SET value = '3' WHERE name = 'db_revision'") self.db.commit() - except psycopg2.ProgrammingError, msg: + except psycopg2.ProgrammingError as msg: self.db.rollback() - raise DBUpdateError, "Unable to appy versioncmp removal, rollback issued. Error message : %s" % (str(msg)) + raise DBUpdateError("Unable to appy versioncmp removal, rollback issued. Error message : %s" % (str(msg)))