1""" 

2Change 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# This program is free software; you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation; either version 2 of the License, or 

12# (at your option) any later version. 

13 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18 

19# You should have received a copy of the GNU General Public License 

20# along with this program; if not, write to the Free Software 

21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

22 

23################################################################################ 

24 

25import psycopg2 

26from daklib.dak_exceptions import DBUpdateError 

27from daklib.config import Config 

28 

29statements = [ 

30""" 

31DROP INDEX IF EXISTS ind_bin_contents_binary 

32""", 

33""" 

34ALTER TABLE bin_contents 

35 DROP CONSTRAINT IF EXISTS bin_contents_pkey 

36""", 

37""" 

38CREATE UNIQUE INDEX bin_contents_pkey 

39 ON bin_contents (binary_id, file) WITH (fillfactor = 80) 

40""", 

41""" 

42ALTER TABLE bin_contents 

43 ADD PRIMARY KEY USING INDEX bin_contents_pkey 

44""", 

45""" 

46CLUSTER bin_contents USING bin_contents_pkey 

47""", 

48""" 

49DROP INDEX IF EXISTS src_contents_source_id_idx 

50""", 

51""" 

52ALTER TABLE src_contents 

53 DROP CONSTRAINT IF EXISTS src_contents_pkey 

54""", 

55""" 

56CREATE UNIQUE INDEX src_contents_pkey 

57 ON src_contents (source_id, file) WITH (fillfactor = 80) 

58""", 

59""" 

60ALTER TABLE src_contents 

61 ADD PRIMARY KEY USING INDEX src_contents_pkey 

62""", 

63""" 

64CLUSTER src_contents USING src_contents_pkey 

65""", 

66] 

67 

68################################################################################ 

69 

70 

71def do_update(self): 

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))