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