]> git.decadent.org.uk Git - dak.git/blob - dak/dakdb/update99.py
Use correct db_name for MD5 hash
[dak.git] / dak / dakdb / update99.py
1 #!/usr/bin/env python
2 # coding=utf8
3
4 """
5 Add component ordering
6
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2012 Varnish Software AS
9 @author: Tollef Fog Heen <tfheen@varnish-software.com>
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 import psycopg2
30 from daklib.dak_exceptions import DBUpdateError
31 from daklib.config import Config
32
33 statements = [
34 """
35 ALTER TABLE component
36 ADD COLUMN ordering INTEGER UNIQUE
37 """,
38
39 """
40 CREATE SEQUENCE component_ordering_seq
41 INCREMENT BY 10
42 START WITH 100
43 OWNED BY component.ordering
44 """,
45 ]
46
47 ################################################################################
48 def do_update(self):
49     print __doc__
50     try:
51         cnf = Config()
52
53         c = self.db.cursor()
54
55         for stmt in statements:
56             c.execute(stmt)
57
58         for component in ('main', 'contrib', 'non-free'):
59             c.execute("UPDATE component SET ordering = nextval('component_ordering_seq') WHERE name = '{0}'".format(component))
60         c.execute("UPDATE component SET ordering = nextval('component_ordering_seq') WHERE ordering IS NULL")
61         c.execute("""ALTER TABLE component ALTER COLUMN ordering SET NOT NULL""")
62         c.execute("""ALTER TABLE component ALTER COLUMN ordering SET DEFAULT nextval('component_ordering_seq')""")
63
64         c.execute("UPDATE config SET value = '99' WHERE name = 'db_revision'")
65
66         self.db.commit()
67
68     except psycopg2.ProgrammingError as msg:
69         self.db.rollback()
70         raise DBUpdateError('Unable to apply sick update 99, rollback issued. Error message: {0}'.format(msg))