From: Raphaƫl Hertzog Date: Mon, 26 Oct 2009 23:08:07 +0000 (+0100) Subject: Add list of allowed source formats in the database X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f0ae995f049129c3073a93551e3dbf47b62aea4;p=dak Add list of allowed source formats in the database * Add dak/dakdb/update15.py to update the database. * Update required_database_schema to 15 in dak/update_db.py. --- diff --git a/dak/dakdb/update15.py b/dak/dakdb/update15.py new file mode 100644 index 00000000..6cf86cc0 --- /dev/null +++ b/dak/dakdb/update15.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +Adding table for allowed source formats + +@contact: Debian FTP Master +@copyright: 2009 Raphael Hertzog +@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 + +################################################################################ + + +################################################################################ + +import psycopg2 +import time +from daklib.dak_exceptions import DBUpdateError + +################################################################################ + +def do_update(self): + print "Adding tables listing allowed source formats" + + try: + c = self.db.cursor() + c.execute(""" + CREATE TABLE src_format ( + id SERIAL PRIMARY KEY, + format_name TEXT NOT NULL, + unique (format_name) + ) + """) + c.execute("INSERT INTO src_format (format_name) VALUES('1.0')") + c.execute("INSERT INTO src_format (format_name) VALUES('3.0 (quilt)')") + c.execute("INSERT INTO src_format (format_name) VALUES('3.0 (native)')") + + c.execute(""" + CREATE TABLE suite_src_formats ( + suite INT4 NOT NULL, + src_format INT4 NOT NULL, + unique (suite, src_format) + ) + """) + + print "Authorize all formats on all suites by default" + c.execute("SELECT id FROM suite") + suites = c.fetchall() + c.execute("SELECT id FROM src_format") + formats = c.fetchall() + for s in suites: + for f in formats: + c.execute("INSERT INTO suite_src_formats (suite, src_format) VALUES('%s', '%s')" % (s[0], f[0])) + + c.execute("UPDATE config SET value = '15' WHERE name = 'db_revision'") + self.db.commit() + + except psycopg2.ProgrammingError, msg: + self.db.rollback() + raise DBUpdateError, "Unable to apply source format update 15, rollback issued. Error message : %s" % (str(msg)) diff --git a/dak/update_db.py b/dak/update_db.py index 4999af3a..ecf5cd2a 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -44,7 +44,7 @@ from daklib.dak_exceptions import DBUpdateError ################################################################################ Cnf = None -required_database_schema = 14 +required_database_schema = 15 ################################################################################