X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fupdate_db.py;h=f7d13750d9be48738ee8cb7c78d6ac4c77a28b3a;hb=9f371390bb90395b2f2f0b65c91c21047896774a;hp=7d89e6bfeb8871bd7eb1423b21f52506085dd126;hpb=6d236cc36e6de541586a94fc4e2276bd0e8d1453;p=dak.git diff --git a/dak/update_db.py b/dak/update_db.py index 7d89e6bf..f7d13750 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Debian Archive Kit Database Update Script +""" Database Update Main Script """ # Copyright (C) 2008 Michael Casadevall # This program is free software; you can redistribute it and/or modify @@ -29,6 +29,7 @@ import psycopg2, sys, fcntl, os import apt_pkg import time +import errno from daklib import database from daklib import utils @@ -36,7 +37,7 @@ from daklib import utils Cnf = None projectB = None -required_database_schema = 2 +required_database_schema = 4 ################################################################################ @@ -52,7 +53,7 @@ Updates dak's database schema to the lastest version. You should disable crontab ################################################################################ def update_db_to_zero(self): - # This function will attempt to update a pre-zero database schema to zero + """ This function will attempt to update a pre-zero database schema to zero """ # First, do the sure thing, and create the configuration table try: @@ -63,7 +64,7 @@ Updates dak's database schema to the lastest version. You should disable crontab name TEXT UNIQUE NOT NULL, value TEXT );""") - c.execute("INSERT INTO config VALUES ( nextval('config_id_seq'), 'db_revision', '0')"); + c.execute("INSERT INTO config VALUES ( nextval('config_id_seq'), 'db_revision', '0')") self.db.commit() except psycopg2.ProgrammingError: @@ -84,7 +85,7 @@ Updates dak's database schema to the lastest version. You should disable crontab try: c = self.db.cursor() - q = c.execute("SELECT value FROM config WHERE name = 'db_revision';"); + q = c.execute("SELECT value FROM config WHERE name = 'db_revision';") return c.fetchone()[0] except psycopg2.ProgrammingError: @@ -136,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 ################################################################################