1 """
2 Change indices for {src,bin}_contents
3
4 @contact: Debian FTP Master <ftpmaster@debian.org>
5 @copyright: 2015, Ansgar Burchardt <ansgar@debian.org>
6 @license: GNU General Public License version 2 or later
7 """
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import psycopg2
26 from daklib.dak_exceptions import DBUpdateError
27 from daklib.config import Config
28
29 statements = [
30 """
31 DROP INDEX IF EXISTS ind_bin_contents_binary
32 """,
33 """
34 ALTER TABLE bin_contents
35 DROP CONSTRAINT IF EXISTS bin_contents_pkey
36 """,
37 """
38 CREATE UNIQUE INDEX bin_contents_pkey
39 ON bin_contents (binary_id, file) WITH (fillfactor = 80)
40 """,
41 """
42 ALTER TABLE bin_contents
43 ADD PRIMARY KEY USING INDEX bin_contents_pkey
44 """,
45 """
46 CLUSTER bin_contents USING bin_contents_pkey
47 """,
48 """
49 DROP INDEX IF EXISTS src_contents_source_id_idx
50 """,
51 """
52 ALTER TABLE src_contents
53 DROP CONSTRAINT IF EXISTS src_contents_pkey
54 """,
55 """
56 CREATE UNIQUE INDEX src_contents_pkey
57 ON src_contents (source_id, file) WITH (fillfactor = 80)
58 """,
59 """
60 ALTER TABLE src_contents
61 ADD PRIMARY KEY USING INDEX src_contents_pkey
62 """,
63 """
64 CLUSTER src_contents USING src_contents_pkey
65 """,
66 ]
67
68
69
70
72 print(__doc__)
73 try:
74 cnf = Config()
75
76 c = self.db.cursor()
77
78 for stmt in statements:
79 c.execute(stmt)
80
81 c.execute("UPDATE config SET value = '109' WHERE name = 'db_revision'")
82 self.db.commit()
83
84 except psycopg2.ProgrammingError as msg:
85 self.db.rollback()
86 raise DBUpdateError('Unable to apply sick update 109, rollback issued. Error message: {0}'.format(msg))
87