#!/usr/bin/env python
-# Debian Archive Kit Database Update Script
+""" Database Update Main Script
+
+@contact: Debian FTP Master <ftpmaster@debian.org>
# Copyright (C) 2008 Michael Casadevall <mcasadevall@debian.org>
+@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
################################################################################
-import psycopg2, sys, fcntl, os
+import psycopg2
+import sys
+import fcntl
+import os
import apt_pkg
import time
import errno
from daklib import database
from daklib import utils
+from daklib.dak_exceptions import DBUpdateError
################################################################################
Cnf = None
projectB = None
-required_database_schema = 3
+required_database_schema = 12
################################################################################
################################################################################
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:
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:
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:
sys.exit(0)
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)
+ print "updating database schema from " + str(database_revision) + " to " + str(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)
+ 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
################################################################################