]> git.decadent.org.uk Git - dak.git/blobdiff - dak/dakdb/update10.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update10.py
old mode 100644 (file)
new mode 100755 (executable)
index cf1caa1..52a5d0b
@@ -2,11 +2,11 @@
 # coding=utf8
 
 """
-Debian Archive Kit Database Update Script
-Copyright © 2008 Michael Casadevall <mcasadevall@debian.org>
-Copyright © 2009 Mike O'Connor <stew@debian.org>
+Add constraints to src_uploaders
 
-Debian Archive Kit Database Update Script 8
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2009  Mark Hymers <mhy@debian.org>
+@license: GNU General Public License version 2 or later
 """
 
 # This program is free software; you can redistribute it and/or modify
@@ -25,6 +25,7 @@ Debian Archive Kit Database Update Script 8
 
 ################################################################################
 
+# <mhy> oh no, Ganneff has just corrected my english
 
 ################################################################################
 
@@ -36,21 +37,20 @@ from daklib.utils import get_conf
 ################################################################################
 
 def do_update(self):
-    print "add package_type enum"
+    print "Add constraints to src_uploaders"
     Cnf = get_conf()
 
     try:
         c = self.db.cursor()
-
-        c.execute("CREATE TYPE package_type AS ENUM('deb','udeb','tdeb', 'dsc')")
-        c.execute("ALTER TABLE binaries RENAME COLUMN type to type_text" );
-        c.execute("ALTER TABLE binaries ADD COLUMN type package_type" );
-        c.execute("UPDATE binaries set type=type_text::package_type" );
-        c.execute("ALTER TABLE binaries DROP COLUMN type_text" );
-        c.execute("CREATE INDEX binary_type_ids on binaries(type)")
-
+        # 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:
+    except psycopg2.ProgrammingError as msg:
         self.db.rollback()
-        raise DBUpdateError, "Unable to apply binary type enum update, rollback issued. Error message : %s" % (str(msg))
+        raise DBUpdateError, "Unable to apply suite config updates, rollback issued. Error message : %s" % (str(msg))