]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update6.py
Merge commit 'mhyftpmaster/master'
[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
37 ################################################################################
38
39 def do_update(self):
40     print "Adding content fields to database"
41
42     try:
43         c = self.db.cursor()
44         c.execute("""CREATE TABLE content_file_paths (
45                      id serial primary key not null,
46                      path text unique not null
47                    )""")
48
49         c.execute("""CREATE TABLE content_file_names (
50                     id serial primary key not null,
51                     file text unique not null
52                    )""")
53
54         c.execute("""CREATE TABLE content_associations (
55                     id serial not null,
56                     binary_pkg int4 not null references binaries(id) on delete cascade,
57                     filepath int4 not null references content_file_paths(id) on delete cascade,
58                     filename int4 not null references content_file_names(id) on delete cascade
59                   );""")
60
61         c.execute("""CREATE TABLE pending_content_associations (
62                      id serial not null,
63                      package text not null,
64                      version debversion not null,
65                      filepath int4 not null references content_file_paths(id) on delete cascade,
66                      filename int4 not null references content_file_names(id) on delete cascade
67                    );""")
68
69         c.execute("""CREATE FUNCTION comma_concat(text, text) RETURNS text
70                    AS $_$select case
71                    WHEN $2 is null or $2 = '' THEN $1
72                    WHEN $1 is null or $1 = '' THEN $2
73                    ELSE $1 || ',' || $2
74                    END$_$
75                    LANGUAGE sql""")
76
77         c.execute("""CREATE AGGREGATE comma_separated_list (
78                    BASETYPE = text,
79                    SFUNC = comma_concat,
80                    STYPE = text,
81                    INITCOND = ''
82                    );""")
83
84         c.execute( "CREATE INDEX content_assocaitions_binary ON content_associations(binary_pkg)" )
85
86         c.execute("UPDATE config SET value = '6' WHERE name = 'db_revision'")
87         self.db.commit()
88
89     except psycopg2.ProgrammingError, msg:
90         self.db.rollback()
91         raise DBUpdateError, "Unable to appy debversion updates, rollback issued. Error message : %s" % (str(msg))