X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fupdate_db.py;h=dadaf3517951b8d469677d2557c5a078129e7d6b;hb=67c8d8a7405375102b70bfa76b3774d023d37b9f;hp=49a6b584d1fc59ea76f5b2cefde9380b4a6452ca;hpb=9a14adff2ca4e7a5346c0c3b5723d9959022291a;p=dak.git diff --git a/dak/update_db.py b/dak/update_db.py index 49a6b584..dadaf351 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -41,11 +41,12 @@ import errno from daklib import utils from daklib.config import Config from daklib.dak_exceptions import DBUpdateError +from daklib.daklog import Logger ################################################################################ Cnf = None -required_database_schema = 23 +required_database_schema = 48 ################################################################################ @@ -100,12 +101,25 @@ Updates dak's database schema to the lastest version. You should disable crontab print "No configuration table found, assuming dak database revision to be pre-zero" return -1 +################################################################################ + + def get_transaction_id(self): + ''' + Returns the current transaction id as a string. + ''' + cursor = self.db.cursor() + cursor.execute("SELECT txid_current();") + id = cursor.fetchone()[0] + cursor.close() + return id + ################################################################################ def update_db(self): # Ok, try and find the configuration table print "Determining dak database revision ..." cnf = Config() + logger = Logger(cnf.Cnf, 'update-db') try: # Build a connect string @@ -120,6 +134,7 @@ Updates dak's database schema to the lastest version. You should disable crontab pass database_revision = int(self.get_db_rev()) + logger.log(['transaction id before update: %s' % self.get_transaction_id()]) if database_revision == -1: print "dak database schema predates update-db." @@ -140,20 +155,26 @@ Updates dak's database schema to the lastest version. You should disable crontab if database_revision == required_database_schema: print "no updates required" + logger.log(["no updates required"]) sys.exit(0) for i in range (database_revision, required_database_schema): - print "updating database schema from %d to %d" % (database_revision, i+1) try: dakdb = __import__("dakdb", globals(), locals(), ['update'+str(i+1)]) update_module = getattr(dakdb, "update"+str(i+1)) update_module.do_update(self) + message = "updated database schema from %d to %d" % (database_revision, i+1) + print message + logger.log([message]) except DBUpdateError, e: # Seems the update did not work. print "Was unable to update database schema from %d to %d." % (database_revision, i+1) print "The error message received was %s" % (e) + logger.log(["DB Schema upgrade failed"]) + logger.close() utils.fubar("DB Schema upgrade failed") database_revision += 1 + logger.close() ################################################################################