1 """
2 Add component ordering
3
4 @contact: Debian FTP Master <ftpmaster@debian.org>
5 @copyright: 2012 Varnish Software AS
6 @author: Tollef Fog Heen <tfheen@varnish-software.com>
7 @license: GNU General Public License version 2 or later
8 """
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import psycopg2
27 from daklib.dak_exceptions import DBUpdateError
28 from daklib.config import Config
29
30 statements = [
31 """
32 ALTER TABLE component
33 ADD COLUMN ordering INTEGER UNIQUE
34 """,
35
36 """
37 CREATE SEQUENCE component_ordering_seq
38 INCREMENT BY 10
39 START WITH 100
40 OWNED BY component.ordering
41 """,
42 ]
43
44
45
46
48 print(__doc__)
49 try:
50 cnf = Config()
51
52 c = self.db.cursor()
53
54 for stmt in statements:
55 c.execute(stmt)
56
57 for component in ('main', 'contrib', 'non-free-firmware', 'non-free'):
58 c.execute("UPDATE component SET ordering = nextval('component_ordering_seq') WHERE name = '{0}'".format(component))
59 c.execute("UPDATE component SET ordering = nextval('component_ordering_seq') WHERE ordering IS NULL")
60 c.execute("""ALTER TABLE component ALTER COLUMN ordering SET NOT NULL""")
61 c.execute("""ALTER TABLE component ALTER COLUMN ordering SET DEFAULT nextval('component_ordering_seq')""")
62
63 c.execute("UPDATE config SET value = '99' WHERE name = 'db_revision'")
64
65 self.db.commit()
66
67 except psycopg2.ProgrammingError as msg:
68 self.db.rollback()
69 raise DBUpdateError('Unable to apply sick update 99, rollback issued. Error message: {0}'.format(msg))
70