X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fdakdb%2Fupdate4.py;h=169653fa4397caa7f4fd9e89b67b873553c419f7;hb=27e00376e81d1c37ff327ee0d39670b266418869;hp=31160766cbf37595d21e2eff4a3c00dab24ebe7f;hpb=f71ac27c75a8ab5185508491e97bc6f237772aa6;p=dak.git diff --git a/dak/dakdb/update4.py b/dak/dakdb/update4.py old mode 100644 new mode 100755 index 31160766..169653fa --- a/dak/dakdb/update4.py +++ b/dak/dakdb/update4.py @@ -1,12 +1,10 @@ #!/usr/bin/env python -# coding=utf8 - """ -Debian Archive Kit Database Update Script -Copyright © 2008 Michael Casadevall -Copyright © 2008 Roger Leigh +Get suite_architectures table use sane values -Debian Archive Kit Database Update Script 2 +@contact: Debian FTP Master +@copyright: 2009 Joerg Jaspert +@license: GNU General Public License version 2 or later """ # This program is free software; you can redistribute it and/or modify @@ -25,62 +23,47 @@ Debian Archive Kit Database Update Script 2 ################################################################################ -# really, if we want to screw ourselves, let's find a better way. -# 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 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("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: + except psycopg2.ProgrammingError as 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))