From 351ad12c1e12fb080a0299c1cf13cfa5c91b8593 Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Sat, 11 Apr 2009 19:36:03 +0100 Subject: [PATCH] add update to fix up src_uploaders Signed-off-by: Mark Hymers --- dak/dakdb/update10.py | 58 +++++++++++++++++++++++++++++++++++++++++++ dak/update_db.py | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100755 dak/dakdb/update10.py diff --git a/dak/dakdb/update10.py b/dak/dakdb/update10.py new file mode 100755 index 00000000..680257ed --- /dev/null +++ b/dak/dakdb/update10.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +Pending contents disinguished by arch + +@contact: Debian FTP Master +@copyright: 2009 Mark Hymers +@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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +################################################################################ + +# * Ganneff ponders how to best write the text to -devel. (need to tell em in +# case they find more bugs). "We fixed the fucking idiotic broken implementation +# to be less so" is probably not the nicest, even if perfect valid, way to say so + +################################################################################ + +import psycopg2 +import time +from daklib.dak_exceptions import DBUpdateError +from daklib.utils import get_conf + +################################################################################ + +def do_update(self): + print "Add constraints to src_uploaders" + Cnf = get_conf() + + try: + c = self.db.cursor() + # Deal with out-of-date src_uploaders entries + c.execute("DELETE FROM src_uploaders WHERE source NOT IN (SELECT id FROM source)") + c.execute("DELETE FROM src_uploaders WHERE maintainer NOT IN (SELECT id FROM maintainer)") + # Add constraints + c.execute("ALTER TABLE src_uploaders ADD CONSTRAINT src_uploaders_maintainer FOREIGN KEY (maintainer) REFERENCES maintainer(id) ON DELETE CASCADE") + c.execute("ALTER TABLE src_uploaders ADD CONSTRAINT src_uploaders_source FOREIGN KEY (source) REFERENCES source(id) ON DELETE CASCADE") + c.execute("UPDATE config SET value = '10' WHERE name = 'db_revision'") + self.db.commit() + + except psycopg2.ProgrammingError, msg: + self.db.rollback() + raise DBUpdateError, "Unable to apply suite config updates, rollback issued. Error message : %s" % (str(msg)) diff --git a/dak/update_db.py b/dak/update_db.py index 55dda5da..4d08721f 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -45,7 +45,7 @@ from daklib.dak_exceptions import DBUpdateError Cnf = None projectB = None -required_database_schema = 9 +required_database_schema = 10 ################################################################################ -- 2.39.2