From: Joerg Jaspert Date: Mon, 16 Feb 2009 21:30:24 +0000 (+0100) Subject: update db X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=c48b357e4838eac6de79b0bd6ee5f8862d049dba;p=dak.git update db (hopefully) fix the bug that dak update-db happily ignores errors from the update scripts, going on with all the other following updates. Which isn't all that helpful. Signed-off-by: Joerg Jaspert --- diff --git a/dak/dakdb/update1.py b/dak/dakdb/update1.py index 7778b1be..ff2b62ee 100755 --- a/dak/dakdb/update1.py +++ b/dak/dakdb/update1.py @@ -24,7 +24,9 @@ ################################################################################ -import psycopg2, time +import psycopg2 +import time +from daklib.dak_exceptions import DBUpdateError ################################################################################ @@ -59,6 +61,4 @@ def do_update(self): except psycopg2.ProgrammingError, 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) diff --git a/dak/dakdb/update2.py b/dak/dakdb/update2.py index 71b43fa7..b1ba6729 100755 --- a/dak/dakdb/update2.py +++ b/dak/dakdb/update2.py @@ -21,7 +21,9 @@ ################################################################################ -import psycopg2, time +import psycopg2 +import time +from daklib.dak_exceptions import DBUpdateError ################################################################################ @@ -391,6 +393,4 @@ $$ except psycopg2.ProgrammingError, msg: self.db.rollback() - print "FATAL: Unable to apply debversion table update 2!" - print "Error Message: " + str(msg) - print "Database changes have been rolled back." + raise DBUpdateError, "Unable to appy debversion updates, rollback issued. Error message : %s" % (str(msg) diff --git a/dak/dakdb/update3.py b/dak/dakdb/update3.py index df89fb9d..3a628de0 100755 --- a/dak/dakdb/update3.py +++ b/dak/dakdb/update3.py @@ -20,7 +20,9 @@ ################################################################################ -import psycopg2, time +import psycopg2 +import time +from daklib.dak_exceptions import DBUpdateError ################################################################################ @@ -36,6 +38,4 @@ def do_update(self): except psycopg2.ProgrammingError, 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) diff --git a/dak/update_db.py b/dak/update_db.py index f9b6e478..5d5fef47 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -137,9 +137,15 @@ Updates dak's database schema to the lastest version. You should disable crontab for i in range (database_revision, required_database_schema): print "updating databse schema from " + str(database_revision) + " to " + str(i+1) - dakdb = __import__("dakdb", globals(), locals(), ['update'+str(i+1)]) - update_module = getattr(dakdb, "update"+str(i+1)) - update_module.do_update(self) + try: + dakdb = __import__("dakdb", globals(), locals(), ['update'+str(i+1)]) + update_module = getattr(dakdb, "update"+str(i+1)) + update_module.do_update(self) + except DBUpdateError, e: + # Seems the update did not work. + print "Was unable to update database schema from %s to %s." % (str(database_revision), str(i+1)) + print "The error message received was %s" % (e) + utils.fubar("DB Schema upgrade failed") database_revision += 1 ################################################################################ diff --git a/daklib/dak_exceptions.py b/daklib/dak_exceptions.py index b210a6f4..d18bee1e 100755 --- a/daklib/dak_exceptions.py +++ b/daklib/dak_exceptions.py @@ -57,7 +57,8 @@ dakerrors = { "SendmailFailedError": """Exception raised when Sendmail invocation failed.""", "NoFreeFilenameError": """Exception raised when no alternate filename was found.""", "TransitionsError": """Exception raised when transitions file can't be parsed.""", - "NoSourceFieldError": """Exception raised - we cant find the source - wtf?""" + "NoSourceFieldError": """Exception raised - we cant find the source - wtf?""", + "DBUpdateError": """Exception raised - could not update the database""" } #: All dak exceptions def construct_dak_exception(name, description):