From: Ansgar Burchardt Date: Mon, 14 May 2012 11:24:07 +0000 (+0200) Subject: Reference archive table from suite and add path to archive root X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2393746724f614977052633542c5442f07906516;p=dak Reference archive table from suite and add path to archive root Signed-off-by: Ansgar Burchardt --- diff --git a/dak/dakdb/update73.py b/dak/dakdb/update73.py new file mode 100644 index 00000000..1f309e45 --- /dev/null +++ b/dak/dakdb/update73.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +Reference archive table from suite and add path to archive root + +@contact: Debian FTP Master +@copyright: 2012 Ansgar Burchardt +@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 +from daklib.dak_exceptions import DBUpdateError +from daklib.config import Config + +################################################################################ +def do_update(self): + print __doc__ + try: + cnf = Config() + + c = self.db.cursor() + + archive_root = cnf["Dir::Root"] + c.execute("ALTER TABLE archive ADD COLUMN path TEXT NOT NULL DEFAULT %s", (archive_root,)) + c.execute("ALTER TABLE archive ALTER COLUMN path DROP DEFAULT") + + c.execute("ALTER TABLE archive ADD COLUMN mode CHAR(4) NOT NULL DEFAULT '0644' CHECK (mode SIMILAR TO '[0-7]{4}')") + c.execute("ALTER TABLE archive ADD COLUMN tainted BOOLEAN NOT NULL DEFAULT 'f'") + c.execute("ALTER TABLE archive ADD COLUMN use_morgue BOOLEAN NOT NULL DEFAULT 't'") + + c.execute("SELECT id FROM archive") + (archive_id,) = c.fetchone() + + if c.fetchone() is not None: + raise DBUpdateError("Cannot automatically upgrade form installation with multiple archives.") + + c.execute("ALTER TABLE suite ADD COLUMN archive_id INT REFERENCES archive(id) NOT NULL DEFAULT %s", (archive_id,)) + c.execute("ALTER TABLE suite ALTER COLUMN archive_id DROP DEFAULT") + + c.execute("UPDATE config SET value = '73' WHERE name = 'db_revision'") + self.db.commit() + + except psycopg2.ProgrammingError as msg: + self.db.rollback() + raise DBUpdateError('Unable to apply sick update 73, rollback issued. Error message : %s' % (str(msg))) diff --git a/dak/update_db.py b/dak/update_db.py index f70fc1c8..8b9fa32b 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -46,7 +46,7 @@ from daklib.daklog import Logger ################################################################################ Cnf = None -required_database_schema = 72 +required_database_schema = 73 ################################################################################ diff --git a/daklib/dbconn.py b/daklib/dbconn.py index a31e9167..c1c3d9ef 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -3596,7 +3596,8 @@ class DBConn(object): copy_queues = relation(BuildQueue, secondary=self.tbl_suite_build_queue_copy), srcformats = relation(SrcFormat, secondary=self.tbl_suite_src_formats, - backref=backref('suites', lazy='dynamic'))), + backref=backref('suites', lazy='dynamic')), + archive = relation(Archive, backref='suites')), extension = validator) mapper(Uid, self.tbl_uid,