]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update6.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / dakdb / update6.py
1 #!/usr/bin/env python
2 # coding=utf8
3
4 """
5 Adding content fields
6
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2008  Michael Casadevall <mcasadevall@debian.org>
9 @copyright: 2008  Roger Leigh <rleigh@debian.org>
10 @license: GNU General Public License version 2 or later
11 """
12
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
27 ################################################################################
28
29 # <tomv_w> really, if we want to screw ourselves, let's find a better way.
30 # <Ganneff> rm -rf /srv/ftp.debian.org
31
32 ################################################################################
33
34 import psycopg2
35 import time
36 from daklib.dak_exceptions import DBUpdateError
37
38 ################################################################################
39
40 def do_update(self):
41     print "Adding content fields to database"
42
43     try:
44         c = self.db.cursor()
45         c.execute("""CREATE TABLE content_file_paths (
46                      id serial primary key not null,
47                      path text unique not null
48                    )""")
49
50         c.execute("""CREATE TABLE content_file_names (
51                     id serial primary key not null,
52                     file text unique not null
53                    )""")
54
55         c.execute("""CREATE TABLE content_associations (
56                     id serial not null,
57                     binary_pkg int4 not null references binaries(id) on delete cascade,
58                     filepath int4 not null references content_file_paths(id) on delete cascade,
59                     filename int4 not null references content_file_names(id) on delete cascade
60                   );""")
61
62         c.execute("""CREATE TABLE pending_content_associations (
63                      id serial not null,
64                      package text not null,
65                      version debversion not null,
66                      filepath int4 not null references content_file_paths(id) on delete cascade,
67                      filename int4 not null references content_file_names(id) on delete cascade
68                    );""")
69
70         c.execute("""CREATE FUNCTION comma_concat(text, text) RETURNS text
71                    AS $_$select case
72                    WHEN $2 is null or $2 = '' THEN $1
73                    WHEN $1 is null or $1 = '' THEN $2
74                    ELSE $1 || ',' || $2
75                    END$_$
76                    LANGUAGE sql""")
77
78         c.execute("""CREATE AGGREGATE comma_separated_list (
79                    BASETYPE = text,
80                    SFUNC = comma_concat,
81                    STYPE = text,
82                    INITCOND = ''
83                    );""")
84
85         c.execute( "CREATE INDEX content_assocaitions_binary ON content_associations(binary_pkg)" )
86
87         c.execute("UPDATE config SET value = '6' WHERE name = 'db_revision'")
88         self.db.commit()
89
90     except psycopg2.ProgrammingError as msg:
91         self.db.rollback()
92         raise DBUpdateError, "Unable to appy debversion updates, rollback issued. Error message : %s" % (str(msg))