[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Reference archive table from suite and add path to archive root



Signed-off-by: Ansgar Burchardt <ansgar@debian.org>
---
 dak/dakdb/update73.py |   62 +++++++++++++++++++++++++++++++++++++++++++++++++
 dak/update_db.py      |    2 +-
 daklib/dbconn.py      |    3 +-
 3 files changed, 65 insertions(+), 2 deletions(-)
 create mode 100644 dak/dakdb/update73.py

diff --git a/dak/dakdb/update73.py b/dak/dakdb/update73.py
new file mode 100644
index 0000000..1f309e4
--- /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 <ftpmaster@debian.org>
+@copyright: 2012 Ansgar Burchardt <ansgar@debian.org>
+@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 f70fc1c..8b9fa32 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 a31e916..c1c3d9e 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,
-- 
1.7.2.5



Reply to: