Ticket #3676: remove_node_change_pk-r5133.diff
| File remove_node_change_pk-r5133.diff, 2.9 KB (added by cboos, 20 months ago) |
|---|
-
trac/db_default.py
17 17 from trac.db import Table, Column, Index 18 18 19 19 # Database version identifier. Used for automatic upgrades. 20 db_version = 2 020 db_version = 21 21 21 22 22 def __mkreports(reports): 23 23 """Utility function used to create report data in same syntax as the … … 88 88 Column('author'), 89 89 Column('message'), 90 90 Index(['time'])], 91 Table('node_change' , key=('rev', 'path', 'change_type'))[91 Table('node_change')[ # MySQL can't have a key on path (see #3676) 92 92 Column('rev'), 93 93 Column('path'), 94 94 Column('node_type', size=1), -
trac/db/mysql_backend.py
80 80 name = '`%s`' % c 81 81 table_col = filter((lambda x: x.name == c), table.columns) 82 82 if len(table_col) == 1 and table_col[0].type.lower() == 'text': 83 if name == '`rev`': 84 name += '(20)' 85 elif name == '`path`': 86 name += '(255)' 87 elif name == '`change_type`': 88 name += '(2)' 89 else: 90 name += '(%s)' % limit 83 name += '(%s)' % limit 91 84 # For non-text columns, we simply throw away the extra bytes. 92 85 # That could certainly be optimized better, but for now let's KISS. 93 86 cols.append(name) -
trac/upgrades/db21.py
1 from trac.db import Table, Column, Index, DatabaseManager 2 3 def do_upgrade(env, ver, cursor): 4 """Remove the primary key constraint on the `node_change` table, 5 as it's not used anyway and MySQL doesn't support it properly (#3676). 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 20 db_connector, _ = DatabaseManager(env)._get_connector() 21 for stmt in db_connector.to_sql(table): 22 cursor.execute(stmt) 23 24 cursor.execute("INSERT INTO node_change " 25 "(rev,path,node_type,change_type,base_path,base_rev) " 26 "SELECT rev,path,node_type,change_type,base_path,base_rev " 27 "FROM node_change_old") 28 cursor.execute("DROP TABLE node_change_old")
