[dak/bpo] 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 <joerg@debian.org>
---
dak/dakdb/update1.py | 8 ++++----
dak/dakdb/update2.py | 8 ++++----
dak/dakdb/update3.py | 8 ++++----
dak/update_db.py | 12 +++++++++---
daklib/dak_exceptions.py | 3 ++-
5 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/dak/dakdb/update1.py b/dak/dakdb/update1.py
index 7778b1b..ff2b62e 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 71b43fa..b1ba672 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 df89fb9..3a628de 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 f9b6e47..5d5fef4 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 b210a6f..d18bee1 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):
--
1.5.6.5
Reply to: