| | 1 | from trac.db import Table, Column, Index, DatabaseManager |
| | 2 | |
| | 3 | def do_upgrade(env, ver, cursor): |
| | 4 | """Replace the primary key constraint on the `node_change` table by an |
| | 5 | index, as the key is not unique in some circumstances (#3778). |
| | 6 | """ |
| | 7 | cursor.execute("CREATE TEMPORARY TABLE node_change_old AS " |
| | 8 | "SELECT * FROM node_change") |
| | 9 | cursor.execute("DROP TABLE node_change") |
| | 10 | |
| | 11 | table = Table('node_change')[ |
| | 12 | Column('rev'), |
| | 13 | Column('path'), |
| | 14 | Column('node_type', size=1), |
| | 15 | Column('change_type', size=1), |
| | 16 | Column('base_path'), |
| | 17 | Column('base_rev'), |
| | 18 | Index(['rev']), |
| | 19 | Index(['rev', 'path', 'change_type'])] |
| | 20 | |
| | 21 | db_connector, _ = DatabaseManager(env)._get_connector() |
| | 22 | for stmt in db_connector.to_sql(table): |
| | 23 | cursor.execute(stmt) |
| | 24 | |
| | 25 | cursor.execute("INSERT INTO node_change " |
| | 26 | "(rev,path,node_type,change_type,base_path,base_rev) " |
| | 27 | "SELECT rev,path,node_type,change_type,base_path,base_rev " |
| | 28 | "FROM node_change_old") |
| | 29 | cursor.execute("DROP TABLE node_change_old") |