5 Move to using the C version of debversion
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2009 Mark Hymers <mhy@debian.org>
9 @license: GNU General Public License version 2 or later
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.
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.
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
26 ################################################################################
29 ################################################################################
37 from daklib.dak_exceptions import DBUpdateError
38 from daklib.config import Config
40 ################################################################################
43 print "Converting database to use new C based debversion type"
48 print "Temporarily converting columns to TEXT"
49 c.execute("ALTER TABLE binaries ALTER COLUMN version TYPE TEXT")
50 c.execute("ALTER TABLE source ALTER COLUMN version TYPE TEXT")
51 c.execute("ALTER TABLE upload_blocks ALTER COLUMN version TYPE TEXT")
52 c.execute("ALTER TABLE pending_content_associations ALTER COLUMN version TYPE TEXT")
54 print "Dropping old debversion type"
55 c.execute("DROP OPERATOR >(debversion, debversion)")
56 c.execute("DROP OPERATOR <(debversion, debversion)")
57 c.execute("DROP OPERATOR <=(debversion, debversion)")
58 c.execute("DROP OPERATOR >=(debversion, debversion)")
59 c.execute("DROP OPERATOR =(debversion, debversion)")
60 c.execute("DROP OPERATOR <>(debversion, debversion)")
61 c.execute("DROP FUNCTION debversion_eq(debversion,debversion)")
62 c.execute("DROP FUNCTION debversion_ge(debversion,debversion)")
63 c.execute("DROP FUNCTION debversion_gt(debversion,debversion)")
64 c.execute("DROP FUNCTION debversion_le(debversion,debversion)")
65 c.execute("DROP FUNCTION debversion_lt(debversion,debversion)")
66 c.execute("DROP FUNCTION debversion_ne(debversion,debversion)")
67 c.execute("DROP FUNCTION debversion_compare(debversion,debversion)")
68 c.execute("DROP FUNCTION debversion_revision(debversion)")
69 c.execute("DROP FUNCTION debversion_version(debversion)")
70 c.execute("DROP FUNCTION debversion_epoch(debversion)")
71 c.execute("DROP FUNCTION debversion_split(debversion)")
72 c.execute("DROP TYPE debversion")
75 print "Importing new debversion type"
76 f = open('/usr/share/postgresql/8.4/contrib/debversion.sql', 'r')
79 for j in f.readlines():
80 j = j.replace('\t', '').replace('\n', '').split('--')[0]
81 if not j.startswith('--'):
95 print "Converting columns to new debversion type"
96 c.execute("ALTER TABLE binaries ALTER COLUMN version TYPE debversion")
97 c.execute("ALTER TABLE source ALTER COLUMN version TYPE debversion")
98 c.execute("ALTER TABLE upload_blocks ALTER COLUMN version TYPE debversion")
99 c.execute("ALTER TABLE pending_content_associations ALTER COLUMN version TYPE debversion")
102 c.execute("UPDATE config SET value = '19' WHERE name = 'db_revision'")
105 except psycopg2.InternalError, msg:
107 raise DBUpdateError, "Unable to apply debversion update 19, rollback issued. Error message : %s" % (str(msg))