X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fdakdb%2Fupdate3.py;h=1eab89f66e45e2147403268b0984d8e60bce5670;hb=27e00376e81d1c37ff327ee0d39670b266418869;hp=df89fb9d6300710e85ec890d51a830b25f8b3a76;hpb=74c5a1256401a709d74c496b972cc0bd38decaa8;p=dak.git diff --git a/dak/dakdb/update3.py b/dak/dakdb/update3.py index df89fb9d..1eab89f6 100755 --- 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 @@ -20,7 +25,9 @@ ################################################################################ -import psycopg2, time +import psycopg2 +import time +from daklib.dak_exceptions import DBUpdateError ################################################################################ @@ -29,13 +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() - print "FATAL: Unable to apply db update 3!" - print "Error Message: " + str(msg) - print "Database changes have been rolled back." + raise DBUpdateError, "Unable to appy versioncmp removal, rollback issued. Error message : %s" % (str(msg))