Package trac :: Package upgrades :: Module db38

Source Code for Module trac.upgrades.db38

 1  # -*- coding: utf-8 -*- 
 2  # 
 3  # Copyright (C) 2015-2023 Edgewall Software 
 4  # All rights reserved. 
 5  # 
 6  # This software is licensed as described in the file COPYING, which 
 7  # you should have received as part of this distribution. The terms 
 8  # are also available at https://trac.edgewall.org/wiki/TracLicense. 
 9  # 
10  # This software consists of voluntary contributions made by many 
11  # individuals. For the exact contribution history, see the revision 
12  # history and logs, available at https://trac.edgewall.org/log/. 
13   
14  from trac.db.api import DatabaseManager 
15  from trac.db.schema import Column, Index, Table 
16   
17   
18 -def do_upgrade(env, ver, cursor):
19 """Add an auto-increment primary key to `node_change` table and indices 20 (repos, rev, path) and (repos, path, rev) (#3676). 21 """ 22 db_connector, _ = DatabaseManager(env).get_connector() 23 table = Table('node_change', key='id')[ 24 Column('id', auto_increment=True), 25 Column('repos', type='int'), 26 Column('rev', key_size=40), 27 Column('path', key_size=255), 28 Column('node_type', size=1), 29 Column('change_type', size=1), 30 Column('base_path'), 31 Column('base_rev'), 32 Index(['repos', 'rev', 'path']), 33 Index(['repos', 'path', 'rev'])] 34 35 with env.db_transaction: 36 cursor.execute("""CREATE TEMPORARY TABLE node_change_old AS 37 SELECT * FROM node_change""") 38 cursor.execute("DROP TABLE node_change") 39 40 for stmt in db_connector.to_sql(table): 41 cursor.execute(stmt) 42 43 cursor.execute("""\ 44 INSERT INTO node_change 45 (repos,rev,path,node_type,change_type,base_path,base_rev) 46 SELECT repos,rev,path,node_type,change_type,base_path,base_rev 47 FROM node_change_old""") 48 cursor.execute("DROP TABLE node_change_old")
49