Package trac ::
Package upgrades ::
Module db24
1 from trac .db import Table , Column , Index , DatabaseManager
2
4 # Change repository key from reponame to a surrogate id
5 cursor .execute ("SELECT id FROM repository "
6 "UNION SELECT repos AS id FROM revision "
7 "UNION SELECT repos AS id FROM node_change "
8 "ORDER BY id")
9 id_name_list = [(i + 1, name ) for i , (name ,) in enumerate(cursor )]
10
11 cursor .execute ("CREATE TEMPORARY TABLE repo_old "
12 "AS SELECT * FROM repository")
13 cursor .execute ("DROP TABLE repository")
14 cursor .execute ("CREATE TEMPORARY TABLE rev_old "
15 "AS SELECT * FROM revision")
16 cursor .execute ("DROP TABLE revision")
17 cursor .execute ("CREATE TEMPORARY TABLE nc_old "
18 "AS SELECT * FROM node_change")
19 cursor .execute ("DROP TABLE node_change")
20
21 tables = [Table ('repository', key=('id', 'name'))[
22 Column ('id', type ='int'),
23 Column ('name'),
24 Column ('value')],
25 Table ('revision', key=('repos', 'rev'))[
26 Column ('repos', type ='int'),
27 Column ('rev', key_size=20),
28 Column ('time', type ='int'),
29 Column ('author'),
30 Column ('message'),
31 Index (['repos', 'time'])],
32 Table ('node_change', key=('repos', 'rev', 'path', 'change_type'))[
33 Column ('repos', type ='int'),
34 Column ('rev', key_size=20),
35 Column ('path', key_size=255),
36 Column ('node_type', size=1),
37 Column ('change_type', size=1, key_size=2),
38 Column ('base_path'),
39 Column ('base_rev'),
40 Index (['repos', 'rev'])]]
41
42 db_connector, _ = DatabaseManager (env )._get_connector()
43 for table in tables:
44 for stmt in db_connector.to_sql (table):
45 cursor .execute (stmt)
46
47 cursor .executemany ("INSERT INTO repository (id,name,value) "
48 "VALUES (%s,'name',%s)", id_name_list)
49 cursor .executemany ("INSERT INTO repository (id,name,value) "
50 "SELECT %s,name,value FROM repo_old WHERE id=%s",
51 id_name_list)
52 cursor .execute ("DROP TABLE repo_old")
53 cursor .executemany ("INSERT INTO revision (repos,rev,time,author,message) "
54 "SELECT %s,rev,time,author,message FROM rev_old "
55 "WHERE repos=%s", id_name_list)
56 cursor .execute ("DROP TABLE rev_old")
57 cursor .executemany ("INSERT INTO node_change (repos,rev,path,node_type,"
58 " change_type,base_path,base_rev) "
59 "SELECT %s,rev,path,node_type,change_type,base_path,"
60 " base_rev FROM nc_old WHERE repos=%s", id_name_list)
61 cursor .execute ("DROP TABLE nc_old")
62