]> git.decadent.org.uk Git - dak.git/blobdiff - dak/dakdb/update4.py
Merge branch 'master' into content_generation, make changes based on Joerg's review
[dak.git] / dak / dakdb / update4.py
index f707a31150df211fd588816ed9002de165b77776..1a9d9c3a4c6168deec277aa70d9ecede41b4c349 100644 (file)
@@ -1,12 +1,10 @@
 #!/usr/bin/env python
-# coding=utf8
-
 """
-Debian Archive Kit Database Update Script
-Copyright © 2008  Michael Casadevall <mcasadevall@debian.org>
-Copyright © 2008  Roger Leigh <rleigh@debian.org>
+Database Update Script - Get suite_architectures table use sane values
 
-Debian Archive Kit Database Update Script 2
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2009  Joerg Jaspert <joerg@debian.org>
+@license: GNU General Public License version 2 or later
 """
 
 # This program is free software; you can redistribute it and/or modify
@@ -25,72 +23,47 @@ Debian Archive Kit Database Update Script 2
 
 ################################################################################
 
-# <tomv_w> really, if we want to screw ourselves, let's find a better way.
-# <Ganneff> rm -rf /srv/ftp.debian.org
+import psycopg2
+from daklib.dak_exceptions import DBUpdateError
+from daklib.utils import get_conf
 
 ################################################################################
 
-import psycopg2, time
-
-################################################################################
+suites = {}  #: Cache of existing suites
+archs = {}   #: Cache of existing architectures
 
 def do_update(self):
-    print "Adding content fields to database"
+    """ Execute the DB update """
 
+    print "Lets make suite_architecture table use sane values"
+    Cnf = get_conf()
+
+    query = "INSERT into suite_architectures (suite, architecture) VALUES (%s, %s)"  #: Update query
     try:
         c = self.db.cursor()
-        c.execute("""CREATE TABLE content_file_paths (
-                     id serial primary key not null,
-                     path text unique not null
-                   )""")
-
-        c.execute("""CREATE TABLE content_file_names (
-                    id serial primary key not null,
-                    file text unique not null
-                   )""")
-
-        c.execute("""CREATE TABLE content_associations (
-                    id serial not null,
-                    binary_pkg int4 not null references binaries(id) on delete cascade,
-                    filepath int4 not null references content_file_paths(id) on delete cascade,
-                    filename int4 not null references content_file_names(id) on delete cascade
-                  );""")
-
-        c.execute("""CREATE TABLE temp_content_associations (
-                     id serial not null,
-                     package text not null,
-                     version debversion not null,
-                     filepath int4 not null references content_file_paths(id) on delete cascade,
-                     filename int4 not null references content_file_names(id) on delete cascade
-                   );""")
-
-        c.execute("""CREATE FUNCTION comma_concat(text, text) RETURNS text
-                   AS $_$select case
-                   WHEN $2 is null or $2 = '' THEN $1
-                   WHEN $1 is null or $1 = '' THEN $2
-                   ELSE $1 || ',' || $2
-                   END$_$
-                   LANGUAGE sql""")
-
-        c.execute("""CREATE AGGREGATE comma_separated_list (
-                   BASETYPE = text,
-                   SFUNC = comma_concat,
-                   STYPE = text,
-                   INITCOND = ''
-                   );""")
-
-        c.execute( "CREATE INDEX content_assocaitions_binary ON content_associations(binary_pkg)" )
-
-        c.execute("UPDATE config SET value = '2' WHERE name = 'db_revision'")
-        self.db.commit()
+        c.execute("DELETE FROM suite_architectures;")
 
-        print "REMINDER: Remember to fully regenerate the Contents files before running import-contents"
-        print ""
-        print "Pausing for five seconds ..."
-        time.sleep (5)
+        c.execute("SELECT id, arch_string FROM architecture;")
+        a=c.fetchall()
+        for arch in a:
+            archs[arch[1]]=arch[0]
+
+        c.execute("SELECT id,suite_name FROM suite")
+        s=c.fetchall()
+        for suite in s:
+            suites[suite[1]]=suite[0]
+
+        for suite in Cnf.SubTree("Suite").List():
+            print "Processing suite %s" % (suite)
+            architectures = Cnf.SubTree("Suite::" + suite).ValueList("Architectures")
+            suite = suite.lower()
+            for arch in architectures:
+                c.execute(query, [suites[suite], archs[arch]])
+
+        c.execute("UPDATE config SET value = '4' WHERE name = 'db_revision'")
+
+        self.db.commit()
 
     except psycopg2.ProgrammingError, msg:
         self.db.rollback()
-        print "FATAL: Unable to apply debversion table update 2!"
-        print "Error Message: " + str(msg)
-        print "Database changes have been rolled back."
+        raise DBUpdateError, "Unable to apply sanity to suite_architecture table, rollback issued. Error message : %s" % (str(msg))